📄 zgcx.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import java.awt.Window;
class zgcx extends Frame implements ActionListener
{ private condb conc=null;
private ResultSet rs=null;
private String sql=null;
private Label chao=new Label("职工号:");
private Label cname=new Label("姓名:");
private Label csex=new Label("性别:");
private Label cage=new Label("年龄:");
private Label cdep=new Label("所在部门:");
private TextField chaotx=new TextField();
private Label cnametx=new Label("");
private Label csextx=new Label("");
private Label cagetx=new Label("");
private Label cdeptx=new Label("");
private Button cx=new Button("查询");
private Button tc=new Button("退出");
public zgcx()
{ setTitle("职工查询");
setSize(400,250);
setBackground(Color.LIGHT_GRAY);
this.setLocationRelativeTo(this.getParent());
this.setResizable(false);
setLayout(null);
chao.setBounds(80,50,50,20);
cname.setBounds(80,80,50,20);
csex.setBounds(80,110,50,20);
cage.setBounds(80,140,50,20);
cdep.setBounds(80,170,50,20);
chaotx.setBounds(160,50,150,20);
cnametx.setBounds(160,80,150,20);
csextx.setBounds( 160,110,150,20);
cagetx.setBounds(160,140,150,20);
cdeptx.setBounds(140,170,150,20);
cx.setBounds(60,205,50,20);
tc.setBounds(300,205,50,20);
add(chao);
add(cname);
add(cagetx);
add(cage);
add(csex);
add(cdep);
add(chaotx);
add(cnametx);
add(csextx);
add(cdeptx);
add(cx);
add(tc);
setVisible(true);
cx.addActionListener(this);
tc.addActionListener(this);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{dispose();}
}
);
}
public void actionPerformed(ActionEvent e)
{ if(e.getActionCommand().equals("退出"))
this.dispose();
if(e.getActionCommand().equals("查询"))
{ conc=new condb();
sql="select * from 职工 where 职工号='"+chaotx.getText()+"'";
try { rs=conc.getrs(conc.con,sql);
if(rs.next())
{
cnametx.setText(rs.getString("姓名"));
csextx.setText(rs.getString("性别"));
cagetx.setText(Integer.toString(rs.getInt("年龄")));
cdeptx.setText(rs.getString("所在部门"));
conc.dbclose(conc.con,rs);
conc=null;
rs=null;}
else {JOptionPane jop=new JOptionPane();
jop.showConfirmDialog(null,"该用户不存在!","警告",-1);
}
}
catch(Exception ee){}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -