?? 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 + -