?? adddialog.java
字號(hào):
package com.fang.client.ui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Calendar;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import com.fang.client.config.FTaskConfig;
import com.fang.commom.util.DateChooserJButton;
import com.fang.commom.util.StringParser;
import com.fang.common.core.FTask;
public class AddDialog extends JDialog implements ActionListener{
private static final long serialVersionUID = 1L;
private JComboBox comboBox;
private JTextField textField_4;
// private JTextField textField_3;
private DateChooserJButton textField_3;
private JTextField textField_2;
private JTextField textField_1;
private JTextField textField;
private FTaskConfig config=null;
public JTable table=null;
public static void main(String args[]) {
try {
AddDialog dialog = new AddDialog();
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog
*/
public AddDialog() {
super();
getContentPane().setLayout(null);
setBounds(100, 100, 501, 375);
final JLabel label = new JLabel();
label.setText("任務(wù)編號(hào)");
label.setBounds(102, 43, 66, 18);
getContentPane().add(label);
textField = new JTextField();
textField.setEditable(false);
textField.setBounds(200, 41, 124, 22);
getContentPane().add(textField);
final JLabel label_1 = new JLabel();
label_1.setText("任務(wù)名稱(chēng)");
label_1.setBounds(102, 83, 66, 18);
getContentPane().add(label_1);
textField_1 = new JTextField();
textField_1.setBounds(200, 81, 124, 22);
getContentPane().add(textField_1);
final JLabel label_2 = new JLabel();
label_2.setText("任務(wù)參數(shù)");
label_2.setBounds(102, 119, 66, 18);
getContentPane().add(label_2);
textField_2 = new JTextField();
textField_2.setBounds(200, 117, 282, 22);
getContentPane().add(textField_2);
final JLabel label_3 = new JLabel();
label_3.setText("任務(wù)開(kāi)始時(shí)間");
label_3.setBounds(78, 157, 90, 18);
getContentPane().add(label_3);
// textField_3 = new JTextField();
// textField_3.setBounds(200, 155, 124, 22);
// getContentPane().add(textField_3);
textField_3 = new DateChooserJButton();
textField_3.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
}
});
textField_3.setBounds(200, 155, 201, 22);
getContentPane().add(textField_3);
final JLabel label_4 = new JLabel();
label_4.setText("任務(wù)間隔時(shí)間");
label_4.setBounds(78, 193, 78, 18);
getContentPane().add(label_4);
textField_4 = new JTextField();
textField_4.setAction(null);
textField_4.setBounds(200, 191, 124, 22);
getContentPane().add(textField_4);
final JLabel label_5 = new JLabel();
label_5.setText("任務(wù)類(lèi)型");
label_5.setBounds(102, 227, 66, 18);
getContentPane().add(label_5);
final JButton button = new JButton();
button.setText("提交任務(wù)");
button.setBounds(62, 275, 106, 28);
button.setActionCommand(Constants.SURE);
button.addActionListener(this);
getContentPane().add(button);
final JButton button_1 = new JButton();
button_1.setText("取消");
button_1.setBounds(200, 275, 106, 28);
button_1.setActionCommand(Constants.CANCEL);
button_1.addActionListener(this);
getContentPane().add(button_1);
comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] { "linux執(zhí)行命令","url訪(fǎng)問(wèn)命令"}));
comboBox.setBounds(200, 223, 124, 27);
getContentPane().add(comboBox);
final JLabel label_6 = new JLabel();
label_6.setText("(單位:分鐘)");
label_6.setBounds(335, 193, 84, 18);
getContentPane().add(label_6);
//
}
public void actionPerformed(ActionEvent ee) {
String cmd = ee.getActionCommand();
if(Constants.SURE.equals(cmd)){
//TODO 添加任務(wù)
FTask atask=new FTask();
atask.setId(NumberGenerater.getNumber());
atask.setTaskname(textField_1.getText().trim());
atask.setCmdParam(StringParser.parseByBlank(textField_2.getText().trim()));
atask.setStarttime(StringParser.parseToDate(textField_3.getText().trim()).getTime());
atask.setInternal(Integer.parseInt(textField_4.getText().trim())*60);//*60把分轉(zhuǎn)化成秒
atask.setCmdType(comboBox.getSelectedIndex());
System.out.println("++++++++++++++++++++++++++++++++++++++++++");
System.out.println(comboBox.getSelectedIndex());
atask.setStatus(Constants.NOT_START);
if(config==null){
config=new FTaskConfig();
}
//TODO 新增任務(wù)到任務(wù)列表,以及保存到文件中
int t=config.addTask(atask);
System.out.println("tttttttttttttttttttttttttttttttttttttt");
System.out.println(t);
if(t==1){
//TODO把新增任務(wù)顯示出來(lái)
TableModelMirror tableModel=TableModelMirror.newInstance();
//tableModel.fireTableDataChanged();
tableModel.fireTableRowsInserted(0, 0);
}else {
//TODO 提示用戶(hù)操作失敗
JOptionPane.showMessageDialog(null,
"操作失敗,請(qǐng)稍候再試!!", "alert", JOptionPane.ERROR_MESSAGE);
};
System.out.println(config.getTaskCount());
}else{
this.dispose();
}
}
static class NumberGenerater {
public static int basic=-1;
static {
if(basic==-1){
Calendar c = Calendar.getInstance();
basic=c.get(Calendar.YEAR)*100000+c.get(Calendar.MONTH)*10000+c.get(Calendar.DAY_OF_MONTH)*1000
+c.get(Calendar.HOUR_OF_DAY)*100+c.get(Calendar.MINUTE)*10+c.get(Calendar.SECOND)
-2008*100000-50000;
}
}
static int getNumber(){
return basic++;
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -