📄 glyshanchuframe.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class GLYShanChuFrame extends Frame implements ActionListener,ItemListener
{
Label label1 = new Label("请输入员工编号");
Label label2 =new Label("用户类型");
TextField textField1 = new TextField();
Button button1 = new Button("确定");
Button button2 = new Button("取消");
Choice choice1=new Choice();
int n;
Connection conn;
Statement stmt;
ResultSet rs;
String strurl;
public GLYShanChuFrame() throws Exception
{
super("管理员删除窗口");
setSize(400,300);
setBackground(new Color(110,200,150));
this.setLocation(200,200);
setLayout(null);
choice1.add("普通用户");
choice1.add("超级用户");
label2.setBounds(101,120,80,23);
label1.setBounds(101, 62, 144, 23);
textField1.setBounds(101, 96, 180, 23);
button1.setBounds(102, 250, 87, 25);
button1.addActionListener(this);
button2.setBounds(200, 250, 85, 25);
choice1.setBounds(101, 150, 103, 23);
choice1.addItemListener(this);
button2.addActionListener(this);
add(button1);
add(label2);
add(button2);
add(textField1);
add(label1);
add(choice1);
strurl ="jdbc:odbc:Library";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(strurl);
stmt = conn.createStatement();
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
setVisible(false);
}
});
}
public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
if (str.equals("确定"))
{
if(n==0){
if(textField1.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "不能为空", "提示",
JOptionPane.WARNING_MESSAGE);
}
else{
try
{
rs = stmt.executeQuery("select * from GLYB where 员工编号 ='"+textField1.getText()+"'" );
if(rs.next()){
stmt.execute("DELETE * FROM GLYB where 员工编号='" + textField1.getText() +"'");
textField1.setText("");
JOptionPane.showMessageDialog(null, "删除成功", "提示",
JOptionPane.WARNING_MESSAGE);
}
else{ JOptionPane.showMessageDialog(null, "删除错误", "提示",
JOptionPane.WARNING_MESSAGE);
}
}
catch (Exception eg) {
JOptionPane.showMessageDialog(null, "删除错误", "提示",
JOptionPane.WARNING_MESSAGE);
eg.printStackTrace();
}
}
}
else
{
if(textField1.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "输入不能为空", "提示",
JOptionPane.WARNING_MESSAGE);
}
else{
try
{
rs = stmt.executeQuery("select * from CJGLYB where 员工编号 ='"+textField1.getText()+"'" );
if(rs.next()){
stmt.execute("DELETE * FROM CJGLYB where 员工编号='" + textField1.getText() +"'");
JOptionPane.showMessageDialog(null, "删除成功", "提示",
JOptionPane.WARNING_MESSAGE);
textField1.setText("");
}
else{ JOptionPane.showMessageDialog(null, "删除错误", "提示",
JOptionPane.WARNING_MESSAGE);
}
}
catch (Exception eg) {
JOptionPane.showMessageDialog(null, "删除错误", "提示",
JOptionPane.WARNING_MESSAGE);
eg.printStackTrace();
}
}
}
}
if(str.equals("取消"))
{
setVisible(false);
}
}
public void itemStateChanged(ItemEvent e)
{
if(choice1.getSelectedIndex()==1)
{
n=1;
}
else
{
n=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -