📄 classinfomod.java~1~
字号:
package classinfo;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import com.zdsoft.gui.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import com.zdsoft.datacenter.ASDatacenter;
public class ClassInfoAdd
extends ASDialog {
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JPanel jPanel3 = new JPanel();
JLabel jLabel1 = new JLabel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JLabel jLabel2 = new JLabel();
JTextField id = new JTextField();
JLabel jLabel3 = new JLabel();
JTextField name = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField teacher = new JTextField();
ClassInfoShow cl;
public ClassInfoAdd(ClassInfoShow cls) {
cl = cls;
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setSize(new Dimension(277, 180)); //(1)定义本对话框的大小(宽度,高度);
this.getContentPane().setLayout(borderLayout1);
jLabel1.setFont(new java.awt.Font("Serif", 0, 15));
jLabel1.setText("增加班级信息");
jButton1.setFont(new java.awt.Font("Serif", 0, 12));
jButton1.setText("取消");
jButton1.addActionListener(new ClassInfoAdd_jButton1_actionAdapter(this));
jButton2.setFont(new java.awt.Font("Serif", 0, 12));
jButton2.setText("确定");
jButton2.addActionListener(new ClassInfoAdd_jButton2_actionAdapter(this));
jPanel1.setLayout(gridBagLayout1);
jLabel2.setFont(new java.awt.Font("Serif", 0, 12));
jLabel2.setText("班级编号:");
id.setPreferredSize(new Dimension(100, 22));
id.setText("");
jLabel3.setFont(new java.awt.Font("Serif", 0, 12));
jLabel3.setText("班级名称:");
name.setPreferredSize(new Dimension(100, 22));
name.setText("");
jLabel4.setFont(new java.awt.Font("Serif", 0, 12));
jLabel4.setText("班主任:");
teacher.setPreferredSize(new Dimension(100, 22));
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jLabel2, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
, GridBagConstraints.CENTER,
GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(id, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(jLabel3, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
, GridBagConstraints.CENTER,
GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(name, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(jLabel4, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
, GridBagConstraints.CENTER,
GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(teacher, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
this.getContentPane().add(jPanel2, BorderLayout.SOUTH);
jPanel2.add(jButton2, null);
jPanel2.add(jButton1, null);
this.getContentPane().add(jPanel3, BorderLayout.NORTH);
jPanel3.add(jLabel1, null);
this.setWindowCenter(); //(2)将本对话框居中;
}
void jButton1_actionPerformed(ActionEvent e) {
this.dispose(); //关闭本对话框;
}
void jButton2_actionPerformed(ActionEvent e) {
ASDatacenter dc = new ASDatacenter();
dc.connect();
String sql = "insert into bj_info(id,name,teacher) values(" + id.getText() +
",'" +
name.getText() + "','" + teacher.getText() + "')";
String[] msg = dc.update(sql);
if (msg[0].equals("true")) {
int row = cl.ds.addRow();
try {
cl.ds.setObjectAt(row, "id", new Integer(id.getText())); //调用ASDatastore类的setObjectAt方法,将增加的相应值的“对象”
cl.ds.setObjectAt(row, "name", name.getText());
cl.ds.setObjectAt(row, "teacher", teacher.getText());
//填入ds的相应行和列
//通知显示ds数据的表格,ds的数据已发生改变
cl.jTable1.ASTableRepant();
}
catch (Exception ex) {
ex.printStackTrace();
}
//(2)关闭本本对话框
this.dispose();
}
else { //数据库增加失败
//弹出错误信息提示框
dc.disconnect();
JOptionPane.showMessageDialog(this, "数据库增加失败!", "错误",
JOptionPane.ERROR_MESSAGE);
this.dispose();
}
//关闭数据库连接
dc.disconnect();
}
}
class ClassInfoAdd_jButton1_actionAdapter
implements java.awt.event.ActionListener {
ClassInfoAdd adaptee;
ClassInfoAdd_jButton1_actionAdapter(ClassInfoAdd adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class ClassInfoAdd_jButton2_actionAdapter
implements java.awt.event.ActionListener {
ClassInfoAdd adaptee;
ClassInfoAdd_jButton2_actionAdapter(ClassInfoAdd adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -