?? jpanel1.java
字號:
public void delete() {
if (jCheckBox5.isSelected()) {
課程[4].課序號 = 0;
n--;
update();
}
if (jCheckBox4.isSelected()) {
課程[3].課序號 = 課程[4].課序號;
課程[3].上課地點 = 課程[4].上課地點;
課程[3].上課時間 = 課程[4].上課時間;
課程[3].學分 = 課程[4].學分;
課程[4].課序號=0;
n--;
update();
}
if (jCheckBox3.isSelected()) {
課程[2].課序號 = 課程[3].課序號;
課程[3].課序號 = 課程[4].課序號;
課程[2].上課地點 = 課程[3].上課地點;
課程[3].上課地點 = 課程[4].上課地點;
課程[2].上課時間 = 課程[3].上課時間;
課程[3].上課時間 = 課程[4].上課時間;
課程[2].學分 = 課程[3].學分;
課程[3].學分 = 課程[4].學分;
課程[4].課序號=0;
n--;
update();
}
if (jCheckBox2.isSelected()) {
課程[1].課序號 = 課程[2].課序號;
課程[2].課序號 = 課程[3].課序號;
課程[3].課序號 = 課程[4].課序號;
課程[1].上課地點 = 課程[2].上課地點;
課程[2].上課地點 = 課程[3].上課地點;
課程[3].上課地點 = 課程[4].上課地點;
課程[1].上課時間 = 課程[2].上課時間;
課程[2].上課時間 = 課程[3].上課時間;
課程[3].上課時間 = 課程[4].上課時間;
課程[1].學分 = 課程[2].學分;
課程[2].學分 = 課程[3].學分;
課程[3].學分 = 課程[4].學分;
課程[4].課序號=0;
n--;
update();
}
if (jCheckBox1.isSelected()) {
課程[0].課序號 = 課程[1].課序號;
課程[1].課序號 = 課程[2].課序號;
課程[2].課序號 = 課程[3].課序號;
課程[3].課序號 = 課程[4].課序號;
課程[0].上課地點 = 課程[1].上課地點;
課程[1].上課地點 = 課程[2].上課地點;
課程[2].上課地點 = 課程[3].上課地點;
課程[3].上課地點 = 課程[4].上課地點;
課程[0].上課時間 = 課程[1].上課時間;
課程[1].上課時間 = 課程[2].上課時間;
課程[2].上課時間 = 課程[3].上課時間;
課程[3].上課時間 = 課程[4].上課時間;
課程[0].學分 = 課程[1].學分;
課程[1].學分 = 課程[2].學分;
課程[2].學分 = 課程[3].學分;
課程[3].學分 = 課程[4].學分;
課程[4].課序號=0;
n--;
update();
}
initTabel();
initCheckBox(n);
}
public boolean tof(int a) {
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1; j++) {
if (課程[j].課序號 > 課程[j + 1].課序號) {
int n = 課程[j].課序號;
課程[j].課序號 = 課程[j + 1].課序號;
課程[j + 1].課序號 = n;
String m=課程[j].上課地點;
課程[j].上課地點=課程[j+1].上課地點;
課程[j+1].上課地點=m;
m=課程[j].上課時間;
課程[j].上課時間=課程[j+1].上課時間;
課程[j+1].上課時間=m;
m=課程[j].學分;
課程[j].學分=課程[j+1].學分;
課程[j+1].學分=m;
}
}
}
return (a != 課程[0].課序號 && a != 課程[1].課序號 && a != 課程[2].課序號 &&
a != 課程[3].課序號 && a != 課程[4].課序號);
}
public void initTabel() {
jtm = new DefaultTableModel();
jtm.setRowCount(n);
jtm.addColumn("課序號");
jtm.addColumn("上課時間");
jtm.addColumn("上課地點");
jtm.addColumn("學分");
jb.setEnabled(false);
for (int i = 0; i < n; i++) {
jtm.setValueAt(new Integer(課程[i].課序號), i, 0);
jtm.setValueAt(課程[i].上課時間, i, 1);
jtm.setValueAt(課程[i].上課地點, i, 2);
jtm.setValueAt(課程[i].學分, i, 3);
}
jb.setModel(jtm);
}
private void jbInit() throws Exception {
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception e) {
e.printStackTrace();
}
this.setLayout(null);
jScrollPane1.setEnabled(false);
jScrollPane1.setBounds(new Rectangle(195, 181, 412, 117));
jTextField1.setEnabled(false);
jTextField1.setBounds(new Rectangle(310, 440, 123, 32));
jTextField1.addActionListener(this);
jLabel1.setEnabled(false);
jLabel1.setFont(new java.awt.Font("宋體", Font.PLAIN, 15));
jLabel1.setForeground(Color.magenta);
jLabel1.setText("課 序 號");
jLabel1.setBounds(new Rectangle(195, 440, 107, 33));
jButton1.setBounds(new Rectangle(475, 441, 133, 32));
jButton1.setEnabled(false);
jButton1.setFont(new java.awt.Font("宋體", Font.PLAIN, 15));
jButton1.setForeground(Color.magenta);
jButton1.setText("提 交");
jTextField2.setBounds(new Rectangle(283, 92, 181, 29));
jTextField2.addActionListener(this);
jLabel2.setFont(new java.awt.Font("宋體", Font.PLAIN, 15));
jLabel2.setForeground(Color.magenta);
jLabel2.setText("學 號");
jLabel2.setBounds(new Rectangle(195, 92, 70, 29));
jButton2.setBounds(new Rectangle(526, 92, 81, 29));
jButton2.setFont(new java.awt.Font("宋體", Font.PLAIN, 15));
jButton2.setForeground(Color.magenta);
jButton2.setBorder(BorderFactory.createRaisedBevelBorder());
jButton2.setDoubleBuffered(true);
jButton2.setSelected(true);
jButton2.setText("確 定");
jButton2.setFocusCycleRoot(true);
jLabel3.setFont(new java.awt.Font("新宋體", Font.BOLD, 16));
jLabel3.setForeground(Color.red);
jLabel3.setBounds(new Rectangle(268, 31, 276, 28));
jLabel4.setBackground(Color.lightGray);
jLabel4.setFont(new java.awt.Font("宋體", Font.BOLD, 16));
jLabel4.setForeground(Color.red);
jLabel4.setText("你 最 多 選 五 門 課 程");
jLabel4.setBounds(new Rectangle(276, 393, 218, 31));
jCheckBox1.setEnabled(false);
jCheckBox1.setSelectedIcon(null);
jCheckBox1.setText("jCheckBox1");
jCheckBox1.setBounds(new Rectangle(166, 204, 19, 13));
jCheckBox3.setEnabled(false);
jCheckBox3.setText("jCheckBox2");
jCheckBox3.setBounds(new Rectangle(166, 230, 18, 18));
jCheckBox4.setEnabled(false);
jCheckBox4.setText("jCheckBox2");
jCheckBox4.setBounds(new Rectangle(166, 245, 18, 18));
jCheckBox5.setEnabled(false);
jCheckBox5.setText("jCheckBox2");
jCheckBox5.setBounds(new Rectangle(166, 263, 18, 16));
jCheckBox2.setEnabled(false);
jCheckBox2.setText("jCheckBox2");
jCheckBox2.setBounds(new Rectangle(166, 217, 18, 18));
jButton3.setBounds(new Rectangle(195, 342, 135, 31));
jButton3.setEnabled(false);
jButton3.setFont(new java.awt.Font("宋體", Font.PLAIN, 16));
jButton3.setForeground(Color.magenta);
jButton3.setText("刪 除 ");
this.add(jLabel1);
this.add(jButton1);
this.add(jTextField1);
this.add(jScrollPane1);
this.add(jButton2);
this.add(jTextField2);
this.add(jLabel2);
this.add(jLabel3);
this.add(jLabel4);
this.add(jCheckBox3);
this.add(jCheckBox5);
this.add(jCheckBox1);
this.add(jCheckBox2);
this.add(jCheckBox4);
this.add(jButton3);
jScrollPane1.getViewport().add(jb, null);
jButton1.addActionListener(this);
jButton2.addActionListener(this);
jButton3.addActionListener(this);
jButton1.setFocusPainted(true);
jButton1.setFocusCycleRoot(true);
for (int i = 0; i < 5; i++) {
課程[i] = new 課程();
}
}
JScrollPane jScrollPane1 = new JScrollPane();
JTextField1 jTextField1 = new JTextField1();
JLabel jLabel1 = new JLabel();
JButton jButton1 = new JButton();
JTextField1 jTextField2 = new JTextField1();
JLabel jLabel2 = new JLabel();
JButton jButton2 = new JButton();
JTable jb = new JTable();
DefaultTableModel jtm;
課程[] 課程 = new 課程[5];
int n = 0;
int num;
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
int a = 0;
JCheckBox jCheckBox1 = new JCheckBox();
JCheckBox jCheckBox3 = new JCheckBox();
JCheckBox jCheckBox4 = new JCheckBox();
JCheckBox jCheckBox5 = new JCheckBox();
JCheckBox jCheckBox2 = new JCheckBox();
JButton jButton3 = new JButton();
TitledBorder titledBorder1 = new TitledBorder("");
private class 課程 {
int 課序號;
String 學分, 上課地點, 上課時間;
public 課程() {
課序號 = a++;
學分 = "0";
上課地點 = "";
上課時間 = "";
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -