📄 modifydetail.java
字号:
package Professor;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class ModifyDetail extends JFrame{
String ID;
JLabel jl=new JLabel();
JTextField jtf1=new JTextField();
JTextField jtf2=new JTextField();
JTextField jtf3=new JTextField();
JButton jb1=new JButton();
JButton jb2=new JButton();
JLabel jl1=new JLabel();
JLabel jl2=new JLabel();
JLabel jl3=new JLabel();
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
Container cp=this.getContentPane();
public ModifyDetail(String PID)
{
ID=PID;
try{
jbinit();
}catch(Exception e){e.printStackTrace();}
}
class OnCommit implements ActionListener
{
String ID;
public OnCommit(String PID)
{
ID=PID;
}
public void actionPerformed(ActionEvent e)
{
try{
MyJDBC k=new MyJDBC();
int then;
String sql="update wengxinzhi.professor set name='"+jtf1.getText()+"',level='"+jtf2.getText()+"',key='"+jtf3.getText()+"' where pid='"+ID+"'";
then=k.insert(sql);
if(then>0)
{
JOptionPane.showMessageDialog(null,"更新完成");
}else{JOptionPane.showMessageDialog(null,"发生错误");}
}catch(Exception o){o.printStackTrace();}
}
}
private void jbinit()
{
jl.setText("请填入以下信息");
jl.setForeground(Color.RED);
jl.setFont(new Font("SansSerif", Font.PLAIN, 12));
jp1.add(jl);
jl1.setText("姓名");
jl2.setText("职称");
jl3.setText("登陆密码");
jp2.setLayout(new GridLayout(4,2));
jp2.add(jl1);
jp2.add(jtf1);
jp2.add(jl2);
jp2.add(jtf2);
jp2.add(jl3);
jp2.add(jtf3);
jb1.setText("确认");
jb1.setForeground(Color.BLUE);
jb1.setFont(new Font("SansSerif", Font.PLAIN, 12));
jb1.addActionListener(new OnCommit(ID));
jb2.setText("退出");
jb2.setForeground(Color.BLUE);
jb2.setFont(new Font("SansSerif", Font.PLAIN, 12));
jb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
});
jp2.add(jb1);
jp2.add(jb2);
cp.setLayout(new BorderLayout());
cp.add(jp1,BorderLayout.NORTH);
cp.add(jp2,BorderLayout.CENTER);
this.setLocation(250,250);
this.setSize(300,200);
this.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -