import com.Tools.MyFont;
public class UpdateStu extends JDialog implements ActionListener {
//定义修改学生信息的相关组件
JLabel jl1,jl2,jl3,jl4,jl5,jl6,jl7,jl8;
JTextField jtf1,jtf2,jtf3,jtf4,jtf5,jtf6,jtf7,jtf8; JButton jb1,jb2,jb3; int stuAge=0;
Double stuSourse=0.0;
//这是修改学生信息的界面函数的封装 public void upView() {
//加载数据库,获得选中的那一行的所有信息
jl1=new JLabel(\学 号:\);
//因为学号是主键,设置文本框不可编辑的同时,一般也设置标签灰色显示,以
区别其他标签
jl1.setEnabled(false);
jl1.setBounds(20, 20, 60, 25); jl1.setFont(MyFont.f1);
jl2=new JLabel(\姓 名:\); jl2.setFont(MyFont.f1);
jl2.setBounds(250, 20, 60, 25);
jl3=new JLabel(\性 别:\); jl3.setFont(MyFont.f1); jl3.setBounds(20, 60, 60, 25);
- 35 -
jl4=new JLabel(\年 龄:\); jl4.setFont(MyFont.f1);
jl4.setBounds(250, 60, 60, 25);
jl5=new JLabel(\出生地:\); jl5.setFont(MyFont.f1);
jl5.setBounds(14, 100, 60, 25);
jl6=new JLabel(\专 业:\); jl6.setFont(MyFont.f1);
jl6.setBounds(20, 140, 60, 25);
jl7=new JLabel(\班 级:\); jl7.setFont(MyFont.f1);
jl7.setBounds(20, 180, 60, 25);
jl8=new JLabel(\总学分:\); jl8.setFont(MyFont.f1);
jl8.setBounds(240, 180, 60, 25);
jtf1=new JTextField(20);
//由于学号是主键,因此不能修改,即设置障碍曙jtf1不可编辑 jtf1.setEnabled(false);
jtf1.setBounds(70, 20, 130, 25);
jtf1.setBorder(BorderFactory.createLoweredBevelBorder());
jtf2=new JTextField(20);
jtf2.setBounds(300, 20, 130, 25);
jtf2.setBorder(BorderFactory.createLoweredBevelBorder());
- 36 -
jtf3=new JTextField(10); jtf3.setBounds(70, 60, 60, 25);
jtf3.setBorder(BorderFactory.createLoweredBevelBorder());
jtf4=new JTextField(10);
jtf4.setBounds(300, 60, 60, 25);
jtf4.setBorder(BorderFactory.createLoweredBevelBorder());
jtf5=new JTextField(30);
jtf5.setBounds(70, 100, 360, 25);
jtf5.setBorder(BorderFactory.createLoweredBevelBorder());
jtf6=new JTextField(20);
jtf6.setBounds(70, 140, 290, 25);
jtf6.setBorder(BorderFactory.createLoweredBevelBorder());
jtf7=new JTextField(20);
jtf7.setBounds(70, 180, 130, 25);
jtf7.setBorder(BorderFactory.createLoweredBevelBorder());
jtf8=new JTextField(20);
jtf8.setBounds(300, 180, 130, 25);
jtf8.setBorder(BorderFactory.createLoweredBevelBorder());
jb1=new JButton(\修 改\); jb1.setFont(MyFont.f1);
jb1.setBounds(100, 220, 80, 25); jb1.addActionListener(this);
jb2=new JButton(\取 消\);
- 37 -
jb2.setFont(MyFont.f1);
jb2.setBounds(280, 220, 80, 25); jb2.addActionListener(this);
jb3=new JButton(\清 除\); jb3.setFont(MyFont.f1); jb3.setBounds(190,220,80,25); jb3.addActionListener(this);
this.setLayout(null); //把组件添加到窗体 this.add(jl1); this.add(jtf1); this.add(jl2); this.add(jtf2); this.add(jl3); this.add(jtf3); this.add(jl4); this.add(jtf4); this.add(jl5); this.add(jtf5); this.add(jl6); this.add(jtf6); this.add(jl7); this.add(jtf7); this.add(jl8); this.add(jtf8); this.add(jb1); this.add(jb2); this.add(jb3);
- 38 -
}
//因为要修改信息,那么必须要获得所选中的那一行的所有信息,把它们添加到文本
框作为默认值,因此构造方法还应添加一个参数即传递一个模型tm,并传递所选中的行号row
public
UpdateStu(Frame
Main,String
title,TableModel
tm,int
rowNo,boolean model)
{
//调用修改学生信息的界面的方法 this.upView();
//先从表模型中获取所选中的那一行数据
String stuId=(String)tm.getValueAt(rowNo, 0); System.out.println(\+stuId);
String stuName=(String)tm.getValueAt(rowNo, 1); String stuSex=(String)tm.getValueAt(rowNo, 2); String stuAge=(String)tm.getValueAt(rowNo, 3); String stuJg=(String)tm.getValueAt(rowNo, 4); String stuZy=(String)tm.getValueAt(rowNo, 5); String classId=(String)tm.getValueAt(rowNo, 6); String stuSourse=(String)tm.getValueAt(rowNo, 7); //设置文本框的默认值 jtf1.setText(stuId); jtf2.setText(stuName); jtf3.setText(stuSex); jtf4.setText(stuAge); jtf5.setText(stuJg);
- 39 -
//调用父类的构造方法,实现模式对话 super(Main,title,model);