📄 bmcx.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.awt.Window;
import java.sql.*;
import javax.swing.*;
class bmcx 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 cph=new Label("电话");
private TextField chaotx=new TextField();
private Label cnametx=new Label("");
private Label cphtx=new Label("");
private Button cx=new Button("查询");
private Button tc=new Button("退出");
public bmcx()
{ 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);
cph.setBounds(80,110,50,20);
chaotx.setBounds(160,50,150,20);
cnametx.setBounds(160,80,150,20);
cphtx.setBounds( 160,110,150,20);
cx.setBounds(60,180,50,20);
tc.setBounds(300,180,50,20);
add(chao);
add(cname);
add(cph);
add(chaotx);
add(cnametx);
add(cphtx);
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("部门名称"));
cphtx.setText(rs.getString("电话"));
conc.dbclose(conc.con,rs);
conc=null;
rs=null;}
else {JOptionPane jop=new JOptionPane();
jop.showConfirmDialog(null,"该用户不存在!","警告",-1);
}
}
catch(Exception ee){System.out.println("部门查询出错");}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -