?? slithermenu.java
字號:
**=======================================================================**
*/
public void initButtonPanelDimension() {
for (int i = 0; i < panelconut; i++) {
((JPanel)template.get(i)).setBounds(sm_X, sm_Y, slitherMenuBar_Width,
slitherMenuBar_Height - titleHeight * (panelconut - 1));
}//Endfor
}
/**=======================================================================**
* [## public void setInitMenu() {} ]:
* 參數 :無
* 返回值 :無
* 修飾符 :public
* 功能 :設置初始化后展開第一項菜單(在主窗口的setVisible()方法之后使用)
**=======================================================================**
*/
public void setInitMenu() {
if(panelconut > 0) {
JPanel mainMenu = (JPanel)template.get(0); //展開第一項菜單
int titlesHeight = (panelconut - 1) * titleHeight; //獲得其它模板標題的高度總和
int height = slitherMenuBar_Height - titlesHeight;
mainMenu.setBounds(sm_X, sm_Y, slitherMenuBar_Width, height);
//處理其它菜單標題
for (int i = 1; i < panelconut; i++) {
((JPanel)template.get(i)).setBounds(sm_X, sm_Y + height + (i - 1) * titleHeight,
slitherMenuBar_Width, titleHeight);
}//Endfor
}else {
String msg = "沒有按鍵模板可組織。";
JOptionPane.showMessageDialog(null, msg, "錯誤",JOptionPane.ERROR_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public void setMenuDimension(int w,int h) {} ]:
* 參數 :int w 表示菜單寬度,int h 表示菜單高度
* 返回值 :無
* 修飾符 :public
* 功能 :設置菜單寬度和高度(在初始化菜單后加入組件之前使用)
**=======================================================================**
*/
public void setMenuDimension(int w,int h) {
if(panelconut == 0) {
slitherMenuBar_Width = w;
slitherMenuBar_Height = h;
}else {
String msg = "setMenuDimension()方法請在加入組件之前使用。";
JOptionPane.showMessageDialog(null, msg, "警告",JOptionPane.WARNING_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public void setMenuLocation(int x, int y) {} ]:
* 參數 :int x 表示菜單的橫向坐標,int y 表示菜單的縱向坐標
* 返回值 :無
* 修飾符 :public
* 功能 :設置菜單的坐標(在初始化菜單后加入組件之前使用)
**=======================================================================**
*/
public void setMenuLocation(int x, int y) {
if(panelconut == 0) {
sm_X = x;
sm_Y = y;
}else {
String msg = "setMenuLocation()方法請在加入組件之前使用。";
JOptionPane.showMessageDialog(null, msg, "警告",JOptionPane.WARNING_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public void setTitleHeight(int h) {} ]:
* 參數 :int h 表示按鍵模板的標題鍵的高度
* 返回值 :無
* 修飾符 :public
* 功能 :設置模板標題按鍵高度(當標題按鍵有背景圖標時才使用本方法)
**=======================================================================**
*/
public void setTitleHeight(int h) {
titleHeight = h;
}
/**=======================================================================**
* [## public void setButtonPanelBackground(Color bg) {} ]:
* 參數 :Color 對象表示按鍵模板的背景顏色
* 返回值 :無
* 修飾符 :public
* 功能 :設置按鍵模板背景顏色(在初始化菜單后加入組件之后使用)
**=======================================================================**
*/
public void setButtonPanelBackground(Color bg) {
if(panelconut > 0) {
for (int i = 0; i < panelconut; i++) {
((JPanel)buttonPanels.get(i)).setBackground(bg);
}//Endfor
}else {
String msg = "setButtonPanelBackground()方法請在加入組件之后使用。";
JOptionPane.showMessageDialog(null, msg, "警告",JOptionPane.WARNING_MESSAGE);
}//Endif
}
/**=======================================================================**
* [## public String getSelectButtonName() {} ]:
* 參數 :無
* 返回值 :String 對象表示觸發事件的功能按鍵的名字
* 修飾符 :public
* 功能 :獲得選中的按鍵名
**=======================================================================**
*/
public String getSelectButtonName() {
return selectButtonName;
}
/**=======================================================================**
* [## private void slither(int index) {} ]:
* 參數 :無
* 返回值 :無
* 修飾符 :private
* 功能 :處理菜單滑動效果
**=======================================================================**
*/
private void slither(int index) {
//獲得其它標題的高度總和
int sp_h = slitherMenuBar_Height - titleHeight * (panelconut - 1);
if(index == selectPanelNumber) { //如果是當前面板,則不處理
return;
}else if(index > selectPanelNumber) { //菜單上移動作
int sp_y = titleHeight * (selectPanelNumber + 1);
for (int i = sp_h; i >= titleHeight; i --) {
//當前展開面板縮起
((JPanel)template.get(selectPanelNumber)).setSize(slitherMenuBar_Width, i);
//處理當前展開面板與將要展開面板之間的標題
for (int j = selectPanelNumber + 1; j < index; j++) {
int other_Y = ((JPanel)template.get(j)).getY() - 1;
((JPanel)template.get(j)).setLocation(sm_X, other_Y);
}//Endfor
//新面板展開
int index_Y = ((JPanel)template.get(index)).getY() - 1;
int index_H = ((JPanel)template.get(index)).getHeight() + 1;
((JPanel)template.get(index)).setBounds(sm_X, index_Y, slitherMenuBar_Width, index_H);
}//Endfor
}else if(index < selectPanelNumber) { //下移動作
int sp_y = titleHeight * (selectPanelNumber - 2);
for (int i = sp_h; i >= titleHeight; i --) {
//當前展開面板縮起
int spy = ((JPanel)template.get(selectPanelNumber)).getY() + 1;
((JPanel)template.get(selectPanelNumber)).setBounds(sm_X, spy, slitherMenuBar_Width, i);
//處理當前展開面板與將要展開面板之間的標題
for (int j = selectPanelNumber - 1; j > index; j--) {
int other_Y = ((JPanel)template.get(j)).getY() + 1;
((JPanel)template.get(j)).setLocation(sm_X, other_Y);
}//Endfor
//新面板展開
int index_H = ((JPanel)template.get(index)).getHeight() + 1;
((JPanel)template.get(index)).setSize(slitherMenuBar_Width, index_H);
}//Endfor
}//Endif
this.validate(); //確定當前面板變化
}
/**=======================================================================**
* ActionListener 監聽
**=======================================================================**
*/
public void actionPerformed ( ActionEvent ae ) {
//獲得觸發事件的按鍵Name
selectButtonName = ((JButton)ae.getSource()).getName();
if(selectButtonName != null) { //不為空則選擇的就是標題按鍵
//獲得被選中模板的序號
selectPanelNumberNew = Integer.parseInt(selectButtonName);
//處理菜單滑動效果
slither(selectPanelNumberNew);
selectPanelNumber = selectPanelNumberNew;
}
else {
//獲得功能按鍵的名字
selectButtonName = ((JButton)ae.getSource()).getText();
}//Endif
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -