?? pmainmenu.java
字號:
JTextField jtf = (JTextField)vtxt.elementAt(i);
jtf.setForeground(Color.yellow);
}
}
if(node.toString().equals("藍色")){
for (int i = 0; i < vtxt.size(); i++) {
JTextField jtf = (JTextField)vtxt.elementAt(i);
jtf.setForeground(Color.BLUE);
}
}
if(node.toString().equals("默認顏色")){
new PMainMenu();
this.dispose();
}
if(node.toString().equals("淺灰")){
for (int i = 0; i < vpnl.size(); i++) {
JPanel jab = (JPanel)vpnl.elementAt(i);
jab.setBackground(Color.lightGray);
}
}
if(node.toString().equals("深灰")){
for (int i = 0; i < vpnl.size(); i++) {
JPanel jab = (JPanel)vpnl.elementAt(i);
jab.setBackground(Color.GRAY);
}
}
if(node.toString().equals("白")){
for (int i = 0; i < vpnl.size(); i++) {
JPanel jab = (JPanel)vpnl.elementAt(i);
jab.setBackground(Color.WHITE);
}
}
}
}
}
public void run(){ //線程設(shè)置
while(true){
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss aaa");
jTextField3.setText(SGetDate.getDate().concat(sdf.format(new Date())));
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
public void jbInit1() throws SQLException {
Vector ve = sp.que();
SPerTitle spe = new SPerTitle();
Vector vec = spe.titleName();
jTable2 = new JTable(ve,vec);
jTable2.addMouseListener(new PMainMenu_jTable2_mouseAdapter(this));
jScrollPane2.getViewport().add(jTable2);
root.add(roota);
roota.add(roota1);
roota.add(roota2);
}
DefaultMutableTreeNode root = new DefaultMutableTreeNode("菜單選項");
DefaultMutableTreeNode roota = new DefaultMutableTreeNode("人員信息");
DefaultMutableTreeNode roota1 = new DefaultMutableTreeNode("人員管理 1");
DefaultMutableTreeNode roota2 = new DefaultMutableTreeNode("人員管理 2");
JTree jTree1 = new JTree(root);
TitledBorder titledBorder1 = new TitledBorder("");
JMenuItem jMenuItem14 = new JMenuItem();
JMenuItem jMenuItem21 = new JMenuItem();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
GridLayout gridLayout2 = new GridLayout();
JMenuItem jMenuItem22 = new JMenuItem();
JScrollPane jScrollPane3 = new JScrollPane();
JTree jTree2 = new JTree();
JTextField txtnote = new JTextField();
Border border1 = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.yellow);
public void jPanel3_mouseClicked(MouseEvent e) {
int num = (int)Math.round(Math.random()*9);
ImageIcon image=new ImageIcon("/Jewelry/desktop/20050118xy001_("+num+").jpg");
}
public void jButton4_mouseClicked(MouseEvent e) {
}
public void jButton6_actionPerformed(ActionEvent e) {
SMainMenu sm = new SMainMenu();
Thread thr = new Thread(sm);
thr.start();
this.dispose();
}
public void jButton5_actionPerformed(ActionEvent e) {
SMainMenu sm = new SMainMenu(); //
sm.baseButton(e); //
Thread thr = new Thread(sm);
thr.start();
this.dispose();
}
public void jButton4_actionPerformed(ActionEvent e) {
CSMainMenu cs = new CSMainMenu();
Thread thr = new Thread(cs);
thr.start();
this.dispose();
}
public void getTime(){
Date date = new Date();
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
txtDate.setText(fmt.format(date));
}
public void jButton8_actionPerformed(ActionEvent e) throws SQLException {
SPerControl sp = new SPerControl();
if(this.jComboBox2.getSelectedItem().equals("--請選擇--")){
txtAdd.setText("");
txtAge.setText("");
txtId.setText("");
txtName.setText("");
txtPhone.setText("");
txtSex.setText("");
JOptionPane.showMessageDialog(this, "請選擇填寫的方式");
return;
}
if(this.jComboBox2.getSelectedItem().equals("增加")){
String id = txtId.getText(); //編號 //
String name = txtName.getText(); //姓名 //
String sex = txtSex.getText(); //性別 //
String age = txtAge.getText(); //年齡 //
String duty= jComboBox3.getSelectedItem().toString(); //狀態(tài)
String phone = txtPhone.getText(); //電話 //
String add = txtAdd.getText(); //地址
String stat = this.jComboBox4.getSelectedItem().toString(); // 職務(wù)
String time = this.txtDate.getText(); //時間
//判斷編號是否為空
if(id.equals("")){
JOptionPane.showMessageDialog(this, "編號不能為空");
return;
}
//判斷輸入的編號是否以存在
Vector ve = sp.query1(id);
if (ve.size() != 0) {
JOptionPane.showMessageDialog(this, "此編號已存在");
return;
}
//判斷姓名是否為空
if(name.equals("")){
JOptionPane.showMessageDialog(this, "姓名不能為空");
return;
}
if(name.length() < 2 | name.length() > 4){
JOptionPane.showMessageDialog(this, "姓名字符輸入有誤");
return;
}
//判斷性別是否為空
if(!(sex.equals("男"))&& !(sex.equals("女"))){
JOptionPane.showMessageDialog(this, "性別不能為空");
return;
}
//判斷輸入的年齡是否為空
if(age.equals("")){
JOptionPane.showMessageDialog(this, "年齡不能為空");
return;
}
//判斷輸入的年齡是否為整數(shù)字
try {
Integer.parseInt(txtAge.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "年齡必須為整數(shù)");
return;
}
//判斷輸入的年齡是否小于 18 歲
if(Integer.parseInt(age) < 18 || Integer.parseInt(age) > 60){
JOptionPane.showMessageDialog(this,""+ age +" 年齡輸入不對");
return;
}
//判斷輸入的電話是否為空
if(phone.equals("")){
JOptionPane.showMessageDialog(this, "電話號碼不能為空");
return;
}
//判斷輸入的電話號碼是否為數(shù)字
try {
Float.parseFloat(this.txtPhone.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "電話號碼必須為數(shù)字");
return;
}
//判斷輸入的電話號碼是否以 13 獲 159 開頭
float num1;
float num2;
num1 = Float.parseFloat(phone.substring(0,2));
num2 = Float.parseFloat(phone.substring(0,3));
if((num1 != 13) && (num2 != 159)){
JOptionPane.showMessageDialog(this, "電話號碼輸入有誤");
return;
}
//判斷輸入的電話號碼是否已存在
Vector vec = sp.query7(phone);
if(vec.size() != 0){
JOptionPane.showMessageDialog(this, "此電話號碼已存在");
return;
}
ArrayList arraylist = sp.cont(id,name,sex,age,stat,phone,add,duty,time);
if(arraylist == null){
JOptionPane.showMessageDialog(this, "增加失敗");
}else{
JOptionPane.showMessageDialog(this, "增加成功");
this.jbInit1();
}
}else{
String id = null; //編號
String name = null; //姓名
String sex = null; //性別
String age = null; //年齡
String time = null; //日期
String stat = null; //狀態(tài)
String phone = null; //電話
String add = null; //地址
String duty = null; //職務(wù)
id = this.txtId.getText();
name = this.txtName.getText();
time = this.txtDate.getText();
sex = this.txtSex.getText();
age = this.txtAge.getText();
add = this.txtAdd.getText();
phone = this.txtPhone.getText();
stat = jComboBox3.getSelectedItem().toString(); //獲得狀態(tài)
duty = this.jComboBox4.getSelectedItem().toString(); //職務(wù)
///////////////////////////////////////////////////////////////
//判斷編號是否為空
if(id.equals("")){
JOptionPane.showMessageDialog(this, "編號不能為空");
return;
}
//判斷姓名是否為空
if(name.equals("")){
JOptionPane.showMessageDialog(this, "姓名不能為空");
return;
}
//判斷性別是否為空
if(!(sex.equals("男"))&& !(sex.equals("女"))){
JOptionPane.showMessageDialog(this, "性別不能為空");
return;
}
//判斷輸入的年齡是否為空
if(age.equals("")){
JOptionPane.showMessageDialog(this, "年齡不能為空");
return;
}
//判斷輸入的年齡是否為整數(shù)字
try {
Integer.parseInt(txtAge.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "年齡必須為整數(shù)");
return;
}
//判斷輸入的年齡是否小于 18 歲
if(Integer.parseInt(age) < 18 || Integer.parseInt(age) > 60){
JOptionPane.showMessageDialog(this,""+ age +" 年齡輸入不對");
return;
}
//判斷輸入的電話是否為空
if(phone.equals("")){
JOptionPane.showMessageDialog(this, "電話號碼不能為空");
return;
}
//判斷輸入的電話號碼是否為數(shù)字
try {
Float.parseFloat(this.txtPhone.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "電話號碼必須為數(shù)字");
return;
}
//判斷輸入的電話號碼是否以 13 獲 159 開頭
float num1;
float num2;
num1 = Float.parseFloat(phone.substring(0,2));
num2 = Float.parseFloat(phone.substring(0,3));
if((num1 != 13) && (num2 != 159)){
JOptionPane.showMessageDialog(this, "電話號碼輸入有誤");
return;
}
///////////////////////////////////////////////////////////////
ArrayList arraylist = sp.amend(id,name,time,sex,age,add,phone,stat,duty);
if(arraylist == null){
JOptionPane.showMessageDialog(this,"修改失敗");
}else{
JOptionPane.showMessageDialog(this,"修改成功");
this.jbInit1();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -