📄 gengxinxinxi.java
字号:
package don;
//import java.awt.CheckboxGroup;
//import java.awt.Color;
//import java.awt.Component;
//import gerenxinxi.DBSource;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.*;
public class gengxinxinxi extends JFrame //implements ActionListener
{
static ImageIcon icon=new ImageIcon("FOX.jpg");
JLabel tupian;
JLabel xuanze;
JLabel tianjia;
JLabel shanchu;
JLabel xiugai;
JRadioButton tianjia0;
JRadioButton xiugai0;
JRadioButton shanchu0;
ButtonGroup xuanze0;
JLabel xuehao;
JLabel xingming;
JLabel Lnan;
JLabel Lnv;
JPanel p1;
JLabel l1;
JTextField text1;//学号框
JTextField text2;//姓名框
JRadioButton nan;//选择性别男
JRadioButton nv;//选择性别女
ButtonGroup xingbie;//性别单选
JLabel zhuanye;
JComboBox zhuanye0;
JLabel nianji;
JComboBox nianji0;
JLabel banji;
JComboBox banji0;
JLabel zhengzhi;
JComboBox zhengzhi0;
JLabel chusheng;
JTextField nian;
JLabel fuhao1;
JTextField yue;
JLabel fuhao2;
JTextField ri;
JComboBox jiguan0;
JLabel jiguan;//设置籍贯
JLabel mima;
JTextField mima0;
JButton tuichu;
JButton tijiao;
JDialog mimachucuo;
gengxinxinxi()
{
super("更新信息");
xuanze=new JLabel("选择您要执行的操作:");
tupian=new JLabel();
ImageIcon ligong=new ImageIcon("ligong.jpg");
tupian=new JLabel(ligong);
tianjia=new JLabel("添加信息");
xiugai=new JLabel("修改信息");
shanchu=new JLabel("删除信息");
tianjia0=new JRadioButton();//添加的按钮
xiugai0=new JRadioButton();//修改的按按钮
shanchu0=new JRadioButton();
xuanze0=new ButtonGroup();
xuehao=new JLabel("学号:");
xingming=new JLabel("姓名:");
text1=new JTextField(10);
text2=new JTextField(10);
xingbie=new ButtonGroup();
nan=new JRadioButton();
nv=new JRadioButton();
Lnan=new JLabel("男");
Lnv=new JLabel("女");
zhuanye=new JLabel("专业:");
zhuanye0=new JComboBox();
zhuanye0.addItem("计算机");
zhuanye0.addItem("软件");
zhuanye0.addItem("网络");
zhuanye0.addItem("自动化");
zhuanye0.addItem("数学");
zhuanye0.addItem("化学");
nianji=new JLabel("年级:");
nianji0=new JComboBox();
nianji0.addItem("1");
nianji0.addItem("2");
nianji0.addItem("3");
nianji0.addItem("4");
banji=new JLabel("班级:");
banji0=new JComboBox();
banji0.addItem("1");
banji0.addItem("2");
banji0.addItem("3");
banji0.addItem("4");
zhengzhi=new JLabel("政治面貌:");
zhengzhi0=new JComboBox();
zhengzhi0.addItem("党员");
zhengzhi0.addItem("团员");
zhengzhi0.addItem("群众");
chusheng=new JLabel("出生日期 :");
nian=new JTextField("");
jiguan=new JLabel("籍贯:");
jiguan0=new JComboBox();
jiguan0.addItem("陕西");
jiguan0.addItem("甘肃");
jiguan0.addItem("四川");
jiguan0.addItem("河南");
jiguan0.addItem("河北");
jiguan0.addItem("湖南");
jiguan0.addItem("湖北");
jiguan0.addItem("山东");
jiguan0.addItem("山西");
jiguan0.addItem("广东");
mima=new JLabel("设置初始密码:");
mima0=new JTextField(10);
tijiao=new JButton("提交");
tuichu=new JButton("退出");
//getRootPane().setWindowDecorationStyle(JRootPane.QUESTION_DIALOG );
setBounds(180,100,650,480);//设置窗口显示的坐标及位置
setIconImage(icon.getImage());//设置图标
// setBackground(Color.green);//设置背景色
add(tupian);
add(xuanze);
add(tianjia);
add(xiugai);
add(shanchu);
add(xuehao);
add(text1);
add(xingming);
add(text2);
xuanze0.add(tianjia0);
xuanze0.add(xiugai0);
xuanze0.add(shanchu0);
add(tianjia0);
add(xiugai0);
add(shanchu0);
xingbie.add(nan);
xingbie.add(nv);
add(nan);
add(Lnan);
add(nv);
add(Lnv);
add(zhuanye);
add(zhuanye0);
add(nianji);
add(nianji0);
add(banji);
add(banji0);
add(zhengzhi);
add(zhengzhi0);
add(chusheng);
add(nian);
add(jiguan);
add(jiguan0);
add(mima);
add(mima0);
add(tuichu);
add(tijiao);
tianjia0.setSelected(false);
tupian.setBounds(0,0,650,100);
xuanze.setBounds(75,125,160,20);
tianjia.setBounds(220, 125, 80, 20);
xiugai.setBounds(320, 125, 80, 20);
shanchu.setBounds(420, 125, 80, 20);
tianjia0.setBounds(200,127,16,16);
xiugai0.setBounds(300,127,16,16);
shanchu0.setBounds(400,127,16,16);
xuehao.setBounds(70, 180, 50, 20);
text1.setBounds(105, 180, 75, 20);
xingming.setBounds(70, 260, 50, 20);
text2.setBounds(105, 260, 75, 20);
nan.setBounds(100, 218, 16, 16);
Lnan.setBounds(120, 218, 50, 20);
nv.setBounds(140, 218, 16, 16);
Lnv.setBounds(160, 218, 50, 20);
zhuanye.setBounds(70, 288, 50, 20);
zhuanye0.setBounds(105, 288, 80, 20);
nianji.setBounds(70, 338, 50, 20);
nianji0.setBounds(105, 338, 80, 20);
banji.setBounds(70, 388, 70, 20);
banji0.setBounds(105,392,80,20);
zhengzhi.setBounds(310,180,80,20);
zhengzhi0.setBounds(372, 180, 80, 20);
chusheng.setBounds(310,230, 80, 20);
nian.setBounds(372, 230, 85, 20);
jiguan.setBounds(310,288,50,20);
jiguan0.setBounds(372,288,80,20);
mima.setBounds(310,340,90,20);
mima0.setBounds(402,340,50,20);
tuichu.setBounds(405, 388, 70, 30);
tijiao.setBounds(310, 388, 70, 30);
MyListener my=new MyListener();//定义一个新的监听对象
tianjia0.addActionListener(my);//给添加框加监听
xiugai0.addActionListener(my);//给修改框加监听
shanchu0.addActionListener(my);//给删除框加监听
tuichu.addActionListener//关闭按钮的监听
(
new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
setVisible(false);
}
}
);
tijiao.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String t1;
String t2;
String t3;
String t4;
String t5;
String t6;
String t7;
String t8;
String s1;
String s2;
String s3;
String s4;
String s5;
String s6;
String s7;
String s8;
if(tianjia0.isSelected())
{
DBSource db1=new DBSource();
String sql4="select * from geren where sno='" + text1.getText() + "'";
ResultSet rs2=db1.executeQuery(sql4);//有关此学号的纪录已经存在!
try
{
if(rs2.next())
{
JOptionPane.showMessageDialog(null,"有关此学号的纪录已经存在!!!");
return;
}
else
{
boolean b2=(nan.isSelected());
if(b2)
{
s1="男";
}
else
{
s1="女";
}
s2=zhuanye0.getSelectedItem().toString();
s3=nianji0.getSelectedItem().toString();
s4=banji0.getSelectedItem().toString();
s5=zhengzhi0.getSelectedItem().toString();
s6=nian.getText().toString();
s7=jiguan0.getSelectedItem().toString();
s8=mima0.getText().toString();
DBSource db=new DBSource();
String sql3="insert into geren values ('"+text1.getText().trim()+"','"+text2.getText().trim()+"','"+s1+"','"+s4+"','"+s3+"','"+s5+"','"+s6+"','"+s7+"','"+s8+"','"+s2+"')";
boolean ba=db1.execute(sql3);
if(ba)
{
JOptionPane.showMessageDialog(null,"添加成功!!!");
}
}
}
catch (HeadlessException e1)
{
e1.printStackTrace();
}
catch (SQLException e1)
{
e1.printStackTrace();
}
}
else if(xiugai0.isSelected())
{
boolean b1=(nan.isSelected());
if(b1)
{
t1="男";
}
else
{
t1="女";
}
t2=zhuanye0.getSelectedItem().toString();
t3=nianji0.getSelectedItem().toString();
t4=banji0.getSelectedItem().toString();
t5=zhengzhi0.getSelectedItem().toString();
t6=nian.getText().toString();
t7=jiguan0.getSelectedItem().toString();
t8=mima0.getText().toString();
DBSource db=new DBSource();
String sql1="select * from geren where sno='" + text1.getText() + "'";
ResultSet rs1=db.executeQuery(sql1);
try
{
if(rs1.next())
{
DBSource db1=new DBSource();
String sql2="update geren set sname='" + text2.getText().trim() + "',ssex='"+t1+"',szhuanye='"+t2+"',sgrade='"+t3+"',sclass='"
+t4+"',szhenzhimianmao='"+t5+"',sbirthday='"+t6+"',shometown='"+t7+"',smima='"+t8+"' where sno='" + text1.getText().trim() + "'";
boolean bb=db1.execute(sql2);
if(bb)
{
JOptionPane.showMessageDialog(null,"修改成功!");
}
}
else
{
//System.out.println(bb);
JOptionPane.showMessageDialog(null,"学号不存在!");
}
}
catch (HeadlessException e1)
{
e1.printStackTrace();
}
catch (SQLException e1)
{
e1.printStackTrace();
}
}
else if(shanchu0.isSelected())
{
DBSource db=new DBSource();
String sql1="select * from geren where sno='" + text1.getText() + "'";
ResultSet rs1=db.executeQuery(sql1);
try
{
if(rs1.next())
{
DBSource db1=new DBSource();
String sql5="delete * from geren where sno='"+text1.getText()+"'";
boolean bb=db1.execute(sql5);
if(bb)
{
JOptionPane.showMessageDialog(null,"删除成功!");
}
}
else
{
JOptionPane.showMessageDialog(null,"学号不存在!");
}
}
catch (HeadlessException e1)
{
e1.printStackTrace();
}
catch (SQLException e1)
{
e1.printStackTrace();
}
}
}
}
);
setResizable(false);//设置窗口的尺寸不可改变
setLayout(null);
setState(JFrame.NORMAL);//设置窗口为标准状态,也可fra.setState(Frame.NORMAL);
setVisible(true);//继承Window类的方法,在屏幕上显示窗口也可用fra.setVisible(true);
// addWindowListener(new WindowAdapter()
// {
// public void windowClosing(WindowEvent e)
// {
// System.exit(0);
// }
//
// });
}
class MyListener implements ActionListener//设置事件处理;
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==tianjia0)
{
text1.setEditable(true);
text2.setEditable(true);
zhuanye0.setEditable(true);
nianji0.setEditable(true);
banji0.setEditable(true);
zhuanye0.setEnabled(true);
nianji0.setEnabled(true);
banji0.setEnabled(true);
zhengzhi0.setEnabled(true);
nian.setEditable(true);
jiguan0.setEnabled(true);
mima0.setEditable(true);
}
else if(e.getSource()==xiugai0)
{
text1.setEditable(true);
text2.setEditable(true);
zhuanye0.setEditable(true);
nianji0.setEditable(true);
banji0.setEditable(true);
zhuanye0.setEnabled(true);
nianji0.setEnabled(true);
banji0.setEnabled(true);
zhengzhi0.setEnabled(true);
nian.setEditable(true);
jiguan0.setEnabled(true);
mima0.setEditable(true);
}
else if(e.getSource()==shanchu0)
{
nan.setEnabled(false);
nv.setEnabled(false);
text1.setEditable(true);
text2.setEditable(false);
zhuanye0.setEditable(false);
text2.setEditable(false);
zhuanye0.setEnabled(false);
nianji0.setEnabled(false);
banji0.setEnabled(false);
zhengzhi0.setEnabled(false);
nian.setEditable(false);
jiguan0.setEnabled(false);
mima0.setEditable(false);
}
}
}
public static void main(String[] args)
{
new gengxinxinxi();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -