📄 jbgzsd.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class JBGZSD extends Frame implements ItemListener,ActionListener{
String url="jdbc:odbc:test";
Connection con;
String sql;
Statement stmt;
Choice choice;
Label label,label1;
Button ok = new Button("确定");
Button cancel = new Button("取消");
TextField Input = new TextField(15);
JBGZSD(){
Label label1=new Label("请选择工种:");
add(label1);
choice=new Choice();
choice.addItem("董事长");
choice.addItem("网络管理CEO");
choice.addItem("秘书长");
choice.addItem("部长");
choice.addItemListener(this);
label=new Label();
setLabelText(choice.getSelectedIndex(),choice.getSelectedItem());
setLayout(new FlowLayout());
add(choice);
add(label);
add(Input);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
setVisible(false);
}
});
Label label2=new Label("请输入大于1200的整数(输错不负责哈~)");
add(label2);
Panel panel3 = new Panel();
panel3.add(ok);
panel3.add(cancel);
add("South",panel3);
ok.addActionListener(this);
cancel.addActionListener(this);
Input.addActionListener(this);
setSize(300,200);
setTitle("基本工资设定");
setVisible(true);
setResizable(false);
setLocationRelativeTo(null);
}
public void actionPerformed(ActionEvent e){
if (e.getActionCommand().equals("确定")|e.getSource()==Input)
{
String GZh=choice.getSelectedItem();
String GZ=Input.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e1){
System.err.print("ClassNotFoundException:");
System.err.print("e.getMessage()");
}
try{
con = DriverManager.getConnection(url,"sa","sa");
stmt = con.createStatement();
String sql="Update work Set 基本工资='"+GZ+"' Where 工种名称='"+GZh+"';UPDATE salary set 基本工资="+GZ+" where 工种号=(Select 工种号 from work where 工种名称='"+GZh+"')";
stmt.executeUpdate(sql);
new Sucess();
stmt.close();
con.close();
}catch(SQLException ex){
System.err.println("SQLException:"+ex.getMessage());
new Error();
}
Input.setText(null);
setVisible(false);
}
if (e.getActionCommand().equals("取消"))
{
setVisible(false);
}
}
void setLabelText(int num,String text){
label.setText("请键入您要为"+text+"设定的基本工资");
}
public void itemStateChanged(ItemEvent e){
setLabelText(choice.getSelectedIndex(),choice.getSelectedItem());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -