?? attemppanel.java
字號(hào):
/**
* <p>Title: 卓博營(yíng)運(yùn)支撐系統(tǒng)</p>
*
* <p>Description: 為本企業(yè)內(nèi)部運(yùn)作提供支撐,為企業(yè)資源的E化管理提供解決方案</p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: 卓博信息科技有限公司</p>
*
* @author Henry
* @version 1.0
*/
package com.jobcn.ui;
import java.util.ArrayList;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import com.jobcn.control.AttempTableModel;
import com.jobcn.control.Constant;
public class AttempPanel extends JPanel {
/**
* Create the panel
*/
public AttempPanel(final TaskDialog taskDialog) {
super(new BorderLayout());
this.taskDialog = taskDialog;
JPanel panel = new JPanel();
final JButton newAttemp = new JButton();
newAttemp.setBounds(20, 20, 60, 25);
newAttemp.setText("新建");
panel.add(newAttemp);
final JButton editAttemp = new JButton();
editAttemp.setBounds(80, 20, 60, 25);
editAttemp.setText("編輯");
panel.add(editAttemp);
final JButton delAttemp = new JButton();
delAttemp.setBounds(140, 20, 60, 25);
delAttemp.setText("刪除");
panel.add(delAttemp);
add(panel, BorderLayout.NORTH);
model = new AttempTableModel(columnNames, 0);
table = new JTable(model);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumnModel colModel = table.getColumnModel();
int columnCount = table.getColumnCount();
TableColumn[] columns = new TableColumn[columnCount];
for (int i = 0; i < columnCount; i++) {
columns[i] = colModel.getColumn(i);
columns[i].setPreferredWidth(colWidths[i]);
}
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane, BorderLayout.CENTER);
newAttempDialog = new AttempNewPanel(this);
newAttemp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
newAttempDialog.updateUIAndData(null);
newAttempDialog.setEditable(false);
newAttempDialog.setVisible(true);
}
});
editAttemp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editAttemp();
}
});
delAttemp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int idx = table.getSelectedRow();
if (idx < 0){
JOptionPane.showMessageDialog(taskDialog, "請(qǐng)選擇一個(gè)調(diào)度!");
return;
}
int n = JOptionPane.showConfirmDialog(
taskDialog, "您確定要?jiǎng)h除該調(diào)度嗎?", "刪除調(diào)度", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
for (int i = idx + 1; i < table.getRowCount(); i++) {
attempData.get(i)[0] = String.valueOf(i);
table.setValueAt(new Integer(i), i, 0);
}
attempData.remove(idx);
model.removeRow(idx);
}
}
});
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
editAttemp();
}
}
});
}
public void editAttemp() {
int rowNo = table.getSelectedRow();
if (rowNo < 0) {
JOptionPane.showMessageDialog(taskDialog, "請(qǐng)選擇您想要編輯的調(diào)度!");
return;
}
String[] oneAttemp = attempData.get(rowNo);
newAttempDialog.updateUIAndData(oneAttemp);
newAttempDialog.setEditable(true);
newAttempDialog.setVisible(true);
}
private ArrayList<String[]> attempData = new ArrayList<String[]>();
private JTable table;
private AttempTableModel model;
private int ID;
private TaskDialog taskDialog;
private String[] columnNames = Constant.attempData;
private int[] colWidths = { 25, 150, 100, 100, 110, 110};
private AttempNewPanel newAttempDialog;
public JDialog getNewAttempDialog() {
return newAttempDialog;
}
public ArrayList<String[]> getAttempData() {
return attempData;
}
public void setAttempData(ArrayList<String[]> attempData) {
this.attempData = attempData;
}
public AttempTableModel getModel() {
return model;
}
public void setModel(AttempTableModel model) {
this.model = model;
}
public JTable getTable() {
return table;
}
public void setTable(JTable table) {
this.table = table;
}
public int getID() {
return ID;
}
public void setID(int id) {
ID = id;
}
public TaskDialog getTaskDialog() {
return taskDialog;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -