?? productadd.java
字號(hào):
package Manager;import javax.swing.*;import com.borland.jbcl.layout.*;import java.awt.*;import java.awt.event.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class productAdd extends JFrame { private DBManager db =new DBManager();//定義數(shù)據(jù)庫(kù)操作對(duì)象 XYLayout xYLayout1 = new XYLayout(); JLabel jLabel4 = new JLabel(); JLabel jLabel2 = new JLabel(); JButton jButtonExit = new JButton(); JLabel jLabel1 = new JLabel(); JLabel jLabel3 = new JLabel(); JTextField jTextFieldname = new JTextField(); JButton jButtonAdd = new JButton(); JTextField jTextFieldperson = new JTextField(); JTextField jTextFielddep = new JTextField(); JTextField jTextFielddanwei = new JTextField(); JTextField jTextFieldprice = new JTextField(); JLabel jLabel5 = new JLabel(); JLabel jLabel6 = new JLabel(); JTextField jTextFieldcomment = new JTextField(); JButton jButtonClear = new JButton(); public productAdd() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { productAdd productAdd = new productAdd(); } private void jbInit() throws Exception { jButtonAdd.addMouseListener(new userAdd_jButtonAdd_mouseAdapter(this)); jButtonAdd.setText("添加"); jButtonAdd.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldname.setText(""); jTextFieldname.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel3.setText("所屬部門"); jLabel3.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel1.setText("名稱"); jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonExit.addMouseListener(new userAdd_jButtonExit_mouseAdapter(this)); jButtonExit.setText("取消"); jButtonExit.addMouseListener(new userAdd_jButtonExit_mouseAdapter(this)); jButtonExit.addMouseListener(new userAdd_jButtonExit_mouseAdapter(this)); jButtonExit.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel2.setText("負(fù)責(zé)人"); jLabel2.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel4.setText("單位"); jLabel4.setFont(new java.awt.Font("Dialog", 0, 16)); this.getContentPane().setLayout(xYLayout1); jTextFieldperson.setText(""); jTextFieldperson.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFielddep.setText(""); jTextFielddep.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFielddanwei.setText(""); jTextFielddanwei.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldprice.setText(""); jTextFieldprice.setFont(new java.awt.Font("Dialog", 0, 16)); xYLayout1.setWidth(444); xYLayout1.setHeight(398); jLabel5.setText("單價(jià)"); jLabel5.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel6.setText("描述"); jLabel6.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldcomment.setFont(new java.awt.Font("Dialog", 0, 16)); jTextFieldcomment.setText(""); jButtonClear.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonClear.setText("清空"); jButtonClear.addMouseListener(new productAdd_jButtonClear_mouseAdapter(this)); this.setTitle("添加產(chǎn)品信息"); this.getContentPane().add(jTextFieldname, new XYConstraints(239, 25, 111, 28)); this.getContentPane().add(jLabel1, new XYConstraints(88, 26, 99, 34)); this.getContentPane().add(jTextFieldperson, new XYConstraints(238, 69, 111, 26)); this.getContentPane().add(jTextFielddep, new XYConstraints(240, 111, 111, 27)); this.getContentPane().add(jTextFielddanwei, new XYConstraints(240, 155, 111, 27)); this.getContentPane().add(jTextFieldprice, new XYConstraints(240, 198, 111, 28)); this.getContentPane().add(jLabel2, new XYConstraints(85, 70, 80, 34)); this.getContentPane().add(jLabel3, new XYConstraints(84, 111, 110, 36)); this.getContentPane().add(jLabel4, new XYConstraints(85, 157, 105, 34)); this.getContentPane().add(jLabel5, new XYConstraints(83, 199, 105, 34)); this.getContentPane().add(jLabel6, new XYConstraints(82, 244, 105, 34)); this.getContentPane().add(jButtonClear, new XYConstraints(61, 325, 95, 31)); this.getContentPane().add(jButtonExit, new XYConstraints(286, 327, 94, 30)); this.getContentPane().add(jButtonAdd, new XYConstraints(175, 326, 91, 31)); this.getContentPane().add(jTextFieldcomment, new XYConstraints(241, 240, 111, 28)); } void jTextFielddep_actionPerformed(ActionEvent e) { }//退出此窗口 void jButtonExit_mouseClicked(MouseEvent e) { this.dispose(); }//添加產(chǎn)品信息 void jButtonAdd_mouseClicked(MouseEvent e) { String strSQL ; //判斷是否產(chǎn)品名稱為空 if(jTextFieldname.getText().trim().equals("")) {JOptionPane.showMessageDialog(null,"產(chǎn)品名稱不可為空 ,請(qǐng)確認(rèn)!"); return; } //判斷是否負(fù)責(zé)人為空 if(jTextFieldperson.getText().trim().equals("")) {JOptionPane.showMessageDialog(null,"負(fù)責(zé)人不可為空 ,請(qǐng)確認(rèn)!"); return; } //判斷是否產(chǎn)品所屬部門為空 if(jTextFielddep.getText().trim().equals("")) {JOptionPane.showMessageDialog(null,"產(chǎn)品所屬部門不可為空 ,請(qǐng)確認(rèn)!"); return; } //生成sql語(yǔ)句 strSQL="insert into productinfo(Name,Principal,Department,Units,Unitprice,Comment) values('"; strSQL= strSQL+jTextFieldname.getText().trim() +"','"; strSQL= strSQL+jTextFieldperson.getText().trim() +"','"; strSQL= strSQL+jTextFielddep.getText().trim() +"','"; strSQL= strSQL+jTextFielddanwei.getText().trim() +"','"; strSQL= strSQL+jTextFieldprice.getText().trim() +"','"; strSQL= strSQL+jTextFieldcomment.getText().trim() +"'"; strSQL= strSQL+ ")"; //由DBManager對(duì)象執(zhí)行過(guò)程,若成功返回成功信息,若失敗返回失敗提示 if(db.executeSql(strSQL)) {JOptionPane.showMessageDialog(null,"成功添加!"); } else { JOptionPane.showMessageDialog(null," 添加失敗,請(qǐng)重新操作!"); } }//清空文本框 void jButtonClear_mouseClicked(MouseEvent e) { jTextFieldname.setText(""); jTextFieldperson.setText(""); jTextFielddep.setText(""); jTextFielddanwei.setText(""); jTextFieldprice.setText(""); jTextFieldcomment.setText(""); }}class userAdd_jButtonExit_mouseAdapter extends java.awt.event.MouseAdapter { productAdd adaptee; userAdd_jButtonExit_mouseAdapter(productAdd adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonExit_mouseClicked(e); }}class userAdd_jButtonAdd_mouseAdapter extends java.awt.event.MouseAdapter { productAdd adaptee; userAdd_jButtonAdd_mouseAdapter(productAdd adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonAdd_mouseClicked(e); }}class productAdd_jButtonClear_mouseAdapter extends java.awt.event.MouseAdapter { productAdd adaptee; productAdd_jButtonClear_mouseAdapter(productAdd adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonClear_mouseClicked(e); }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -