📄 findmessage.java
字号:
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Findmessage{
JDialog f=new JDialog();
JTextField t1=new JTextField(7);
JTextField t2=new JTextField(20);
JTextField t4=new JTextField(20);
JTextField t5=new JTextField(20);
JTextField t6=new JTextField(20);
ButtonGroup radioGroup = new ButtonGroup();
JRadioButton rb1=new JRadioButton("男",false);
JRadioButton rb2=new JRadioButton("女",false);
public Findmessage(){
JLabel l1=new JLabel("输入要查询的学号:");
JLabel l2=new JLabel("姓名:");
JLabel l3=new JLabel("性别:");
radioGroup.add(rb1);
radioGroup.add(rb2);
JLabel l4=new JLabel("专业:");
JLabel l5=new JLabel("年级:");
JLabel l6=new JLabel("出生:");
t2.setEditable(false);
t4.setEditable(false);
t5.setEditable(false);
t6.setEditable(false);
JButton b1=new JButton("查询");
Container c=f.getContentPane();
c.setLayout(new BorderLayout());
JPanel p1=new JPanel(new BorderLayout());
JPanel g=new JPanel(new GridLayout(6,1));
JPanel j=new JPanel(new FlowLayout());
JPanel p2=new JPanel(new FlowLayout());
JPanel p3=new JPanel(new FlowLayout());
JPanel p4=new JPanel(new FlowLayout());
JPanel p5=new JPanel(new FlowLayout());
JPanel p6=new JPanel(new FlowLayout());
JPanel p7=new JPanel(new FlowLayout());
p2.add(l1);p2.add(t1);p2.add(b1);
p3.add(l2);p3.add(t2);
p4.add(l3);p4.add(rb1);p4.add(rb2);
p5.add(l4);p5.add(t4);
p6.add(l5);p6.add(t5);
p7.add(l6);p7.add(t6);
g.add(p2);
g.add(p3);
g.add(p4);
g.add(p5);
g.add(p6);
g.add(p7);
p1.add(g,BorderLayout.NORTH);
c.add(p1,BorderLayout.CENTER);
f.setTitle("查询对话框");
f.setBounds(200,200,400,280);
f.setVisible(true);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent E) {
t2.setText("");t4.setText("");t5.setText("");t6.setText("");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.println("SQLException: "+e.getMessage());
}
try{
Connection con = DriverManager.getConnection("jdbc:odbc:DB");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from student");
while(rs.next()){
if(t1.getText().equals(rs.getString("Stuno"))){
t2.setText(rs.getString("Stuname"));
if(rs.getString("Stusex").equals("男")){
rb1.setSelected(true);
}
else {rb2.setSelected(true);}
t4.setText(rs.getString("Stuspecialy"));
t5.setText(rs.getString("Stugread"));
t6.setText(rs.getString("Stubirth"));
break;
}
else if(t1.getText().equals("")){
JOptionPane.showMessageDialog(null,"请输入学号查找!", "警告",JOptionPane.WARNING_MESSAGE);
break;
}
}
rs.close();
stmt.close();
con.close();
}
catch(SQLException e){
JOptionPane.showMessageDialog(null,e.getMessage(), "警告",JOptionPane.WARNING_MESSAGE);
}
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -