📄 load1.java
字号:
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class load1 extends JFrame implements ActionListener
{
Connection con;
ResultSet rs;
Statement st;
JButton button1,button2,button3,button4;
JTextField text1,text2,text3,text4,text5,text6,text7;
String sid1=new String();
String sname1=new String();
String ssex1=new String();
String sage1=new String();
String stel1=new String();
String saddress1=new String();
String sclass1=new String();
public void load1()
{
text1=new JTextField(10);
text2=new JTextField(10);
text3=new JTextField(10);
text4=new JTextField(10);
text5=new JTextField(10);
text6=new JTextField(10);
text7=new JTextField(10);
button1=new JButton("查询个人信息");
button1.addActionListener(this);
button2=new JButton("网上选课");
button2.addActionListener(this);
button3=new JButton("课程信息");
button3.addActionListener(this);
button4=new JButton("退出");
button4.addActionListener(this);
Box box1=Box.createHorizontalBox();
box1.add(new JLabel("学生个人信息",JLabel.CENTER));
Box box2=Box.createHorizontalBox();
box2.add(new JLabel("学号:",JLabel.CENTER));
box2.add(text1);
Box box3=Box.createHorizontalBox();
box3.add(new JLabel("姓名:",JLabel.CENTER));
box3.add(text2);
Box box4=Box.createHorizontalBox();
box4.add(new JLabel("性别:",JLabel.CENTER));
box4.add(text3);
Box box5=Box.createHorizontalBox();
box5.add(new JLabel("年龄:",JLabel.CENTER));
box5.add(text4);
Box box6=Box.createHorizontalBox();
box6.add(new JLabel("电话:",JLabel.CENTER));
box6.add(text5);
Box box7=Box.createHorizontalBox();
box7.add(new JLabel("住址:",JLabel.CENTER));
box7.add(text6);
Box box8=Box.createHorizontalBox();
box8.add(new JLabel("班级:",JLabel.CENTER));
box8.add(text7);
Box boxH=Box.createVerticalBox();
boxH.add(box1);
boxH.add(box2);
boxH.add(box3);
boxH.add(box4);
boxH.add(box5);
boxH.add(box6);
boxH.add(box7);
boxH.add(box8);
boxH.add(Box.createVerticalGlue());
JPanel pCenter=new JPanel();
pCenter.add(boxH);
setLayout(new BorderLayout());
add(pCenter,BorderLayout.CENTER);
JPanel pSouth=new JPanel();
pSouth.add(button2);
pSouth.add(button3);
pSouth.add(button4);
add(pSouth,BorderLayout.SOUTH);
JPanel pEast=new JPanel();
pEast.add(button1);
add(pEast,BorderLayout.EAST);
setVisible(true);
setBounds(100,50,300,300);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)//IF1
{
try{//连接数据库
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e2)
{
System.out.println(""+e2);
}
try{
con=DriverManager.getConnection("jdbc:odbc:lhm","","");
st=con.createStatement();
rs=st.executeQuery("Select * FROM xinxi");
}
catch(SQLException el){}//连接数据库
String id1=new String();
id1=text1.getText();
int count=0;
try{
while(rs.next())
{ sid1=rs.getString("studentid");
if(id1.equals(sid1))//IF2
{sname1=rs.getString("studentname");
ssex1=rs.getString("studentsex");
sage1=rs.getString("studentage");
stel1=rs.getString("studenttel");
saddress1=rs.getString("studentaddress");
sclass1=rs.getString("studentclass");
count++;
}//IF2结束
}//WHILE结束
}catch(Exception ee){}
if(count>0)
{text2.setText(sname1);
text3.setText(ssex1);
text4.setText(sage1);
text5.setText(stel1);
text6.setText(saddress1);
text7.setText(sclass1);
}else{JOptionPane.showMessageDialog(null,"数据库中没有该生信息!");}
}//IF1结束
if(e.getSource()==button2)
{ xuanke xk=new xuanke();
xk.setBounds(200,150,350,250);
xk.xuanke();
xk.setVisible(true);
}
if(e.getSource()==button3)
{ xuankexinxi xkxx=new xuankexinxi();
xkxx.setBounds(200,150,100,100);
xkxx.xuankexinxi();
xkxx.setVisible(true);
}
if(e.getSource()==button4) { setVisible(false);}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -