?? configline.java~1~
字號:
/**
* [ConfigLine.java]
*
* 控制條類
*
* 創建日期:(2003-10-25)
* @author:ONE_Fox
* @author:ONE_Fox@163.com
*/
package datechooser;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import java.text.SimpleDateFormat;
class ConfigLine extends JPanel {
//數據配置--------------------//
private TablePanel tablePanel = null;
private Calendar showMonth = null; //當前顯示的月份
private int startYear = 0; //【最小】顯示年份
private int lastYear = 0; //【最大】顯示年份
private int nowYear = 0; //當前年份
private int nowMonth = 0; //當前月份
/**
* 計時器,RoundBox快速翻動
*/
Timer timer = new Timer(true);
//界面組件------------------//
private RoundBox yearBox = null;
private RoundBox monthBox = null;
private JLabel txtYear = new JLabel("年");
private JLabel txtMonth = new JLabel("月");
//------構造方法/函數-----------------------------------------------//
/**
* 構造方法
*
* @param tablePanel TablePanel
* @param showMonth java.util.Calendar
* @param startYear int
* @param lastYear int
*/
ConfigLine(TablePanel tablePanel, Calendar showMonth,
int startYear, int lastYear) {
this.tablePanel = tablePanel;
this.showMonth = showMonth;
this.startYear = startYear;
this.lastYear = lastYear;
nowYear = Integer.valueOf(new SimpleDateFormat("yyyy")
.format(showMonth.getTime())).intValue();
nowMonth = Integer.valueOf(new SimpleDateFormat("M")
.format(showMonth.getTime())).intValue();
yearBox = new RoundBox(nowYear, startYear, lastYear);
monthBox = new RoundBox(nowMonth, 1, 12);
makeFace(); //界面制作
addListener(); //添加事件監聽
}
//------方法/函數---------------------------------------------------//
/**
* 方法:界面制作
*/
private void makeFace() {
Font txtFont = new Font("宋體", Font.PLAIN, 12);
//自身配置-----------------------//
this.setBorder(null);
this.setBackground(Pallet.configLineColor);
this.setLayout(new FlowLayout(1, 7, 1));
this.setPreferredSize(new Dimension(50, 19));
//標簽配置---------------//
txtYear.setForeground(Pallet.cfgTextColor);
txtYear.setPreferredSize(new Dimension(14, 14));
txtYear.setFont(txtFont);
txtMonth.setForeground(Pallet.cfgTextColor);
txtMonth.setPreferredSize(new Dimension(14, 14));
txtMonth.setFont(txtFont);
monthBox.setShowWidth(17);
//總體布局-----------------------//
add(yearBox);
add(txtYear);
add(monthBox);
add(txtMonth);
}
/**
* 方法:添加事件監聽
*/
private void addListener() {
//yearBox 事件配置-------------------------//
yearBox.bt_UP.addMouseListener(new MouseAdapter() {
//yearBox.bt_UP 按下
public void mousePressed(MouseEvent e) {
btPressed(yearBox, 1);
}
//yearBox.bt_UP 彈起
public void mouseReleased(MouseEvent e) {
btReleased(yearBox, 1);
nowYear = yearBox.showNow;
tablePanel.setMonth(nowYear, nowMonth);
}
});
yearBox.bt_DOWN.addMouseListener(new MouseAdapter() {
//yearBox.bt_DOWN 按下
public void mousePressed(MouseEvent e) {
btPressed(yearBox, 2);
}
//yearBox.bt_DOWN 彈起
public void mouseReleased(MouseEvent e) {
btReleased(yearBox, 2);
nowYear = yearBox.showNow;
tablePanel.setMonth(nowYear, nowMonth);
}
});
//monthBox 事件配置------------------------//
monthBox.bt_UP.addMouseListener(new MouseAdapter() {
//monthBox.bt_UP 按下
public void mousePressed(MouseEvent e) {
btPressed(monthBox, 1);
}
//monthBox.bt_UP 彈起
public void mouseReleased(MouseEvent e) {
btReleased(monthBox, 1);
nowMonth = monthBox.showNow;
tablePanel.setMonth(nowYear, nowMonth);
}
});
monthBox.bt_DOWN.addMouseListener(new MouseAdapter() {
//monthBox.bt_DOWN 按下
public void mousePressed(MouseEvent e) {
btPressed(monthBox, 2);
}
//monthBox.bt_DOWN 彈起
public void mouseReleased(MouseEvent e) {
btReleased(monthBox, 2);
nowMonth = monthBox.showNow;
tablePanel.setMonth(nowYear, nowMonth);
}
});
}
/**
* RoundBox 統一按鈕按下事務
*
* @param box RoundBox
* @param theBT int
*/
private void btPressed(RoundBox box, int theBT) {
final RoundBox theBox = box;
if(theBT == 1) { //"+"按鈕
timer = new Timer(true);
timer.schedule(new TimerTask() {
public void run() {
if(theBox.showNow < theBox.showMax) {
theBox.showing.setText("" + (theBox.showNow+1));
theBox.showNow++;
}
}
}, 500, 100);
}
else if(theBT == 2) { //"-"按鈕
timer = new Timer(true);
timer.schedule(new TimerTask() {
public void run() {
if(theBox.showNow > theBox.showMin) {
theBox.showing.setText("" + (theBox.showNow-1));
theBox.showNow--;
}
}
}, 500, 100);
}
}
/**
* RoundBox 統一按鈕彈起事務
*
* @param box RoundBox
* @param theBT int
*/
private void btReleased(RoundBox box, int theBT) {
final RoundBox theBox = box;
timer.cancel();
if(theBT == 1) { //"+"按鈕
if(theBox.showNow < theBox.showMax) {
theBox.showing.setText("" + (theBox.showNow+1));
theBox.showNow++;
}
}
else if(theBT == 2) { //"-"按鈕
if(theBox.showNow > theBox.showMin) {
theBox.showing.setText("" + (theBox.showNow-1));
theBox.showNow--;
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -