?? viewlist.java
字號:
/**
*##############################################################################
*
* [ 項目名 ] :
* [ 公司名 ] : SunshineSOFT
* [ 模塊名 ] : ViewList控件
* [ 文件名 ] : ViewList.java
* [ 相關文件 ] :
* [ 文件實現(xiàn)功能] : 生成和我的電腦差不多的面板
* [ 作者 ] : 顧俊
* [ 版本 ] : 1.0
* ----------------------------------------------------------------------------
* [ 備注 ] :
* ----------------------------------------------------------------------------
* [ 修改記錄 ] :
*
* [ 日 期 ] [版本] [修改人] [修改內(nèi)容]
* 2006/04/19 1.0 顧俊 創(chuàng)建
* ##--------------------------------------------------------------------------
* 版權所有(c) 2006-2007, SunshineSOFT Corporation
* --------------------------------------------------------------------------##
*
* [ 函數(shù)說明 ] :
*
* [## public ViewList(int buttons) {} ]:
* 功能: 構造函數(shù),并制作主面板
*
* [## public void remeButtons() {} ]:
* 功能: 補按鍵空位
*
* [## public JButton getButton(String roomNum) {} ]:
* 功能: 獲得面板中的指定按鍵
*
* [## public void setButtonImage(String buttonName, String state) {} ]:
* 功能: 設置按鍵圖片
*
* [## public void addButton(String name) {} ]:
* 制作功能按鍵,并加入相應的模板中,返回JButton方便主程序加監(jiān)聽
*
* [ 遺留問題 ] :
*
*##############################################################################
*/
package com.sunshine.sunsdk.swing;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class ViewList extends JPanel {
//放置按鍵的數(shù)組
private Hashtable buttons = new Hashtable();
//放置按鍵的面板
private JPanel panelMain;
//ViewList 里面橫向按鍵的個數(shù),和行數(shù)
private int column = 6;
private int row = 5;
//面板內(nèi)按鍵總數(shù)
private int buttonTotal = 30;
//按鍵記數(shù)器
private int buttonCount = 0;
/**=======================================================================**
* [## public ViewList(int buttons) {} ]: 構造函數(shù),并制作主面板
* 參數(shù) :int buttons 表示ViewList中的按鍵數(shù)量
* 返回值 :無
* 修飾符 :public
* 功能 :構造函數(shù),并制作主面板
**=======================================================================**
*/
public ViewList(int buttons) {
super(new BorderLayout());
JScrollPane spMain; //定義滾動面板
//根據(jù)按鍵數(shù)據(jù)計算面板的行數(shù)和列數(shù)
int vRow = buttons / column;
if(vRow > row) { //如果有足夠的按鍵數(shù)量,則設置面板行數(shù),
if(buttons % column > 0) { //否則使用默認行數(shù) row = 5
row = vRow + 1;
}else {
row = vRow;
}//Endif
buttonTotal = buttons; //獲得按鍵總數(shù)
}//Endif
//建立按鍵面板
panelMain = new JPanel(new GridLayout(row, 1, 5, 15));
//設置默認背景色
panelMain.setBackground(new Color(248, 242, 230));
spMain = new JScrollPane(panelMain);
//加入主面板
this.add("Center", spMain);
}
/**=======================================================================**
* [## public void remeButtons() {} ]: 補按鍵空位
* 參數(shù) :無
* 返回值 :無
* 修飾符 :public
* 功能 :補按鍵空位,如果按鍵數(shù)量不足 column * row 則加空JLabel補位,
* 不然總局會亂 注意,此方法一定要在加完所有按鍵后使用
**=======================================================================**
*/
public void remeButtons() {
if(buttonCount < buttonTotal) {
for (int i = 0; i < buttonTotal - buttonCount; i++) {
JLabel lb = new JLabel(" ");
panelMain.add(lb); //補空位
}//Endfor
}//Endif
}
/**=======================================================================**
* [## public JButton getButton(String roomNum) {} ]:
* 參數(shù) :String roomNum 對象表示按鍵名字,也就是房間號
* 返回值 :JButton
* 修飾符 :public
* 功能 :獲得面板中的指定按鍵
**=======================================================================**
*/
public JButton getButton(String roomNum) {
return (JButton)buttons.get(roomNum);
}
/**=======================================================================**
* [## public void setButtonImage(String buttonName, String state) {} ]:
* 參數(shù) :String buttonName 對象表示按鍵在哈希表中的鍵名
* String State 對象表示房間狀態(tài)
* 返回值 :無
* 修飾符 :public
* 功能 :設置按鍵圖片
**=======================================================================**
*/
public void setButtonImage(String buttonName, String state) {
String picName = "";
if(state.equals("可供"))
picName = "pic/room/prov.gif";
else if(state.equals("占用"))
picName = "pic/room/pree.gif";
else if(state.equals("預訂"))
picName = "pic/room/rese.gif";
else if(state.equals("鐘點"))
picName = "pic/room/clock.gif";
else if(state.equals("臟房"))
picName = "pic/room/clean.gif";
else if(state.equals("停用"))
picName = "pic/room/stop.gif";
((JButton)buttons.get(buttonName)).setIcon(new ImageIcon(picName));
}
/**=======================================================================**
* [## public void addButton(String name) {} ]:
* 參數(shù) :String name 表示功能按鍵的名字
* 返回值 :JButton
* 修飾符 :public
* 功能 :制作功能按鍵,并加入相應的模板中,返回JButton方便主程序加監(jiān)聽
**=======================================================================**
*/
public JButton addButton(String name) {
JButton button = new JButton(name);
button.setBorderPainted(false); //設置按鍵無邊框
button.setContentAreaFilled(false); //設置按鍵背景色透明
button.setHorizontalTextPosition(SwingConstants.CENTER);//設置Ico與文字居中
button.setVerticalTextPosition(SwingConstants.BOTTOM);//設置Ico相對文字的位置
panelMain.add(button); //將按鍵加入按鍵面板
buttons.put(name, button); //將按鍵存入哈希表
buttonCount++; //按鍵記數(shù)器+1
return button;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -