【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-Update.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
package sfms;
import java.awt.*;
import java.
sql.*;
import javax.swing.*;
import java.awt.event.*;
public class Update extends JFrame implements ActionListener{
JTextField t1;
String STNO;
JButton b1,b2,b3;
mainWindow parent4;
Update(mainWindow f4) {
super("更新档案");
parent4=f4;
Container c1=this.getContentPane();
setBackground(new Color(215, 215, 215));
c1.setLayout(new GridLayout(3,2));
t1 = new JTextField(10);
JPanel pp = new JPanel();
JLabel label0=new JLabel("请您输入学生号");
label0.setForeground(Color.blue);
label0.setFont(new Font("TRUE",Font.TRUETYPE_FONT,20));
pp.add(label0);
c1.add(pp);
JPanel p1 = new JPanel();
p1.add(new Label(""));
p1.add(t1);
c1.add(p1);
JPanel p2 = new JPanel();
b1 = new JButton("确定");
b2 = new JButton("清除");
b3 = new JButton("退出");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
p2.add(b1);
p2.add(b2);
p2.add(b3);
c1.add(p2);
this.setVisible(true);
this.setSize(400,300);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
shutDown();
}
}
);
}
public void actionPerformed(ActionEvent e) {
try {
if (e.getSource() == b1) {
UpdateDialog ud = new UpdateDialog(this);
ud.setVisible(true);
}
if (e.getSource() == b2) {
t1.setText("");
t1.repaint();
}
if (e.getSource() == b3) {
shutDown();
}
}
catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "数据转换错误!");
}
}
public void shutDown(){
parent4.setVisible(true);
this.dispose();
}
class UpdateDialog extends JFrame implements ActionListener {
JTextField tt1, t2, t3, t4, t5, t6;
JButton b4, b5, b6;
Update parent5;
UpdateDialog(Update f5) {
super("更新学生档案");
parent5=f5;
Container c2 = this.getContentPane();
setBackground(new Color(215, 215, 215));
c2.setLayout(new GridLayout(3, 1));
tt1 = new JTextField(50);
t2 = new JTextField(50);
t3 = new JTextField(50);
t4 = new JTextField(50);
t5 = new JTextField(50);
t6 = new JTextField(50);
JPanel pp1 = new JPanel();
STNO = t1.getText();
JLabel label1=new JLabel("为" + STNO + "学生的档案");
label1.setForeground(Color.blue);
label1.setFont(new Font("TRUE",Font.TRUETYPE_FONT,20));
pp1.add(label1);
c2.add(pp1);
JPanel pp2 = new JPanel(new GridLayout(6, 2));
pp2.add(new JLabel("",SwingConstants.CENTER));
tt1.setText(STNO);
pp2.add(tt1);
pp2.add(new JLabel("",SwingConstants.CENTER));
pp2.add(t2);
pp2.add(new JLabel("性别",SwingConstants.CENTER));
pp2.add(t3);
pp2.add(new JLabel("系别",SwingConstants.CENTER));
pp2.add(t4);
pp2.add(new JLabel("地址",SwingConstants.CENTER));
pp2.add(t5);
pp2.add(new JLabel("电话",SwingConstants.CENTER));
pp2.add(t6);
c2.add(pp2);
JPanel pp3 = new JPanel(new FlowLayout());
b4 = new JButton("确定");
b5 = new JButton("清除");
b6 = new JButton("退出");
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
pp3.add(b4);
pp3.add(b5);
pp3.add(b6);
c2.add(pp3);
this.setSize(400, 300);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
shutDown2();
}
}
);
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@thsspc0792:1521:SFMS";
Connection cn = DriverManager.getConnection(url, "df", "1234");
String str = "select * from DF.FILEINFO where STNO='" + STNO + "'";
PreparedStatement ps = cn.prepareStatement(str);
ResultSet rs = ps.executeQuery();
if (rs.next() == false) {
JOptionPane.showMessageDialog(null, "您输入的学生号有误,请重新输入",
"输入错误",JOptionPane.YES_NO_OPTION);
}
else {
t1.setText(rs.getString("STNO"));
t2.setText(rs.getString("SName"));
t3.setText(rs.getString("Gender"));
t4.setText(rs.getString("Department"));
t5.setText(rs.getString("NativePlace"));
t6.setText(rs.getString("TEL"));
}
cn.close();
}
catch (SQLException e) {
System.out.println("Error Code: " + e.getErrorCode());
System.out.println("Message=" + e.getMessage());
}
catch (Exception e) {
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent f) {
if (f.getSource() == b4) {
up();
}
if (f.getSource() == b5) {
t1.setText("");
t1.repaint();
t2.setText("");
t2.repaint();
t3.setText("");
t3.repaint();
t4