⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adddialog.java

📁 基于面向对象的数据库编程
💻 JAVA
字号:
package view;import java.awt.*;import javax.swing.*;import com.borland.jbcl.layout.*;import java.awt.event.*;import operation.*;import helper.*;import helper.Vertify;import brgeometry.*;import com.versant.fund.*;import com.versant.trans.*;public class AddDialog extends JDialog {  // private TransSession session ;  // ProBag probag=new ProBag();  private JPanel panel1 = new JPanel();  private XYLayout xYLayout1 = new XYLayout();  private JComboBox jComboBox1 = new JComboBox();  private JLabel jLabel1 = new JLabel();  private JTextField jTextField1 = new JTextField();  private JTextField jTextField2 = new JTextField();  private JTextField jTextField3 = new JTextField();  private JTextField jTextField4 = new JTextField();  private JLabel jLabel2 = new JLabel();  private JLabel jLabel3 = new JLabel();  private JLabel jLabel4 = new JLabel();  private JLabel jLabel5 = new JLabel();  private JButton jButton1 = new JButton();  private JButton jButton2 = new JButton();  private JButton jButton3 = new JButton();  private JLabel jLabel6 = new JLabel();  public AddDialog(Frame frame, String title, boolean modal) {    super(frame, title, modal);    try {      jbInit();      pack();    }    catch(Exception ex) {      ex.printStackTrace();    }  }  public AddDialog() {    this(null, "", false);    // this.session=session;  }  private void jbInit() throws Exception {    panel1.setLayout(xYLayout1);    jLabel1.setText("请选择增加类型");    jTextField1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jTextField1_actionPerformed(e);      }    });    jLabel2.setText("长度 ");    jLabel3.setText("宽度");    jLabel4.setText("高度");    jLabel5.setText("半径");    jButton1.setBackground(SystemColor.inactiveCaptionText);    jButton1.setBorder(BorderFactory.createLineBorder(Color.black));    jButton1.setText("确定");    jButton1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton1_actionPerformed(e);      }    });    jButton2.setBackground(SystemColor.inactiveCaptionText);    jButton2.setBorder(BorderFactory.createLineBorder(Color.black));    jButton2.setText("重置");    jButton2.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton2_actionPerformed(e);      }    });    jButton3.setBackground(SystemColor.inactiveCaptionText);    jButton3.setBorder(BorderFactory.createLineBorder(Color.black));    jButton3.setText("取消");    jButton3.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton3_actionPerformed(e);      }    });    jComboBox1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jComboBox1_actionPerformed(e);      }    });    jTextField1.setBorder(BorderFactory.createEtchedBorder());    jTextField1.setDoubleBuffered(true);    jTextField2.setBorder(BorderFactory.createEtchedBorder());    jTextField2.setDoubleBuffered(true);    jTextField3.setBorder(BorderFactory.createEtchedBorder());    jTextField3.setDoubleBuffered(true);    jTextField4.setBorder(BorderFactory.createEtchedBorder());    jTextField4.setDoubleBuffered(true);    jTextField4.setEditable(false);    jComboBox1.setBorder(BorderFactory.createEtchedBorder());    panel1.setBackground(SystemColor.info);    jLabel6.setFont(new java.awt.Font("Dialog", 1, 20));    jLabel6.setForeground(Color.red);    jLabel6.setText("增加一个几何体");    getContentPane().add(panel1);    panel1.add(jButton1,   new XYConstraints(64, 237, 93, 31));    panel1.add(jComboBox1, new XYConstraints(67, 155, 115, 27));    panel1.add(jLabel1, new XYConstraints(68, 109, 117, 22));    panel1.add(jLabel4,  new XYConstraints(209, 159, -1, -1));    panel1.add(jLabel3,  new XYConstraints(209, 125, -1, -1));    panel1.add(jLabel2, new XYConstraints(209, 89, -1, -1));    panel1.add(jLabel5,  new XYConstraints(209, 193, -1, -1));    panel1.add(jTextField1, new XYConstraints(259, 86, 135, 28));    panel1.add(jTextField2,  new XYConstraints(259, 120, 133, 28));    panel1.add(jTextField3,  new XYConstraints(259, 155, 133, 28));    panel1.add(jTextField4,  new XYConstraints(259, 187, 133, 28));    panel1.add(jButton2,  new XYConstraints(184, 238, 88, 28));    panel1.add(jButton3,  new XYConstraints(303, 235, 88, 29));    panel1.add(jLabel6, new XYConstraints(181, 28, -1, -1));    jComboBox1.addItem("长方体");    jComboBox1.addItem("立方体");    jComboBox1.addItem("圆柱体");    jComboBox1.addItem("圆锥体");    jComboBox1.addItem("球体" );  }  void jTextField1_actionPerformed(ActionEvent e) {  }  void jButton1_actionPerformed(ActionEvent e) {      String s;      Manager man=null;      s=jComboBox1.getSelectedItem().toString();      TransSession session = new TransSession("mydb");try      {         ProBag probag=new ProBag();      //产生一个立方体的管理者,      if (s.equals("长方体")){         double a=Double.parseDouble  ( jTextField1.getText());         double b=Double.parseDouble  ( jTextField2.getText());         double c=Double.parseDouble  ( jTextField3.getText());    Vertify.vertify(a,b,c);        probag.setLength(a);        probag.setWidth (b);        probag.setHigh  (c);        man=new CoboidPlaneSolidMan(session);      }      else if (s.equals("立方体")){double a=Double.parseDouble  ( jTextField1.getText());     Vertify.vertify(a);        probag.setLength(a);        man=new SquarePlaneSolidMan(session);      }      else if (s.equals("圆柱体")){        double c=Double.parseDouble  ( jTextField3.getText());         double d=Double.parseDouble  ( jTextField4.getText());      Vertify.vertify(c,d);        probag.setHigh  (c);        probag.setRadius(d);        man=new  CylinderCurveSoildMan(session);      }      else if (s.equals("圆锥体")){        double c=Double.parseDouble  ( jTextField3.getText());         double d=Double.parseDouble  ( jTextField4.getText());     Vertify.vertify(c,d);        probag.setHigh  (c);        probag.setRadius(d);        man=new ConeCurveSolidMan(session);      }      else if (s.equals("球体")){         double d=Double.parseDouble  ( jTextField4.getText());    Vertify.vertify(d);        probag.setRadius(d);        man=new SphereCurveSolidMan(session);      }      Solid solid=man.create();      solid.init(probag);      session.endSession();JOptionPane.showConfirmDialog(this,"添加成功","confirm",JOptionPane.PLAIN_MESSAGE);     // this.dispose(); }  catch (Exception ex){  JOptionPane.showConfirmDialog(this,"请输入正确数据","confirm",JOptionPane.PLAIN_MESSAGE);  session.endSession();}}  void jButton2_actionPerformed(ActionEvent e) {    jTextField1.setText("");    jTextField2.setText("");    jTextField3.setText("");    jTextField4.setText("");  }  void jButton3_actionPerformed(ActionEvent e) {    this.dispose();  }  void jComboBox1_actionPerformed(ActionEvent e) {    //长方体    String s;    s=jComboBox1.getSelectedItem().toString();    if ( s.equals("长方体")){      jTextField1.setEditable(true);      jTextField1.setVisible(true) ;      jLabel2.setVisible(true);      jTextField2.setEditable(true);      jTextField2.setVisible(true) ;      jLabel3.setVisible(true);      jTextField3.setEditable(true);      jTextField3.setVisible(true) ;      jLabel4.setVisible(true);      jTextField4.setEditable(false);      jTextField4.setVisible(false) ;      jLabel5.setVisible(false);    }    //立方体    else if (s.equals("立方体")){      jTextField1.setEditable(true);      jTextField1.setVisible(true) ;      jLabel2.setVisible(true);      jTextField2.setEditable(false);      jTextField2.setVisible(false) ;      jLabel3.setVisible(false);      jTextField3.setEditable(false);      jTextField3.setVisible(false) ;      jLabel4.setVisible(false);      jTextField4.setEditable(false);      jTextField4.setVisible(false) ;      jLabel5.setVisible(false);    }    //圆柱体    else if (s.equals("圆柱体")){      jTextField1.setEditable(false);      jTextField1.setVisible(false) ;      jLabel2.setVisible(false);      jTextField2.setEditable(false);      jTextField2.setVisible(false) ;      jLabel3.setVisible(false);      jTextField3.setEditable(true);      jTextField3.setVisible(true) ;      jLabel4.setVisible(true);      jTextField4.setEditable(true);      jTextField4.setVisible(true) ;      jLabel5.setVisible(true);    }    //圆锥体    else if (s.equals("圆锥体")){      jTextField1.setEditable(false);      jTextField1.setVisible(false) ;      jLabel2.setVisible(false);      jTextField2.setEditable(false);      jTextField2.setVisible(false) ;      jLabel3.setVisible(false);      jTextField3.setEditable(true);      jTextField3.setVisible(true) ;      jLabel4.setVisible(true);      jTextField4.setEditable(true);      jTextField4.setVisible(true) ;      jLabel5.setVisible(true);    }    //球体    else if (s.equals("球体")){      jTextField1.setEditable(false);      jTextField1.setVisible(false) ;      jLabel2.setVisible(false);      jTextField2.setEditable(false);      jTextField2.setVisible(false) ;      jLabel3.setVisible(false);      jTextField3.setEditable(false);      jTextField3.setVisible(false) ;      jLabel4.setVisible(false);      jTextField4.setEditable(true);      jTextField4.setVisible(true) ;      jLabel5.setVisible(true);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -