|
楼主 |
发表于 2013-5-14 07:38:43
|
显示全部楼层
第二个class文件
package com.chun.view;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
import com.chun.model.EmpModel;
import com.chun.mytools.MyTools;
public class AddDialog extends JDialog implements ActionListener{
Image titleIco,headport;
JPanel jp0,jp1,jp2,jp3,jp4;
JLabel jp0_jl1,jp0_jl2,jp1_jl3,jp1_jl4,jp1_jl5,jp1_jl6,jp1_jl7,jp1_jl8,jp2_jl1,jp2_jl2,jp2_jl3,jp2_jl4,jp2_jl5,jp2_jl6,jp2_jl7,jp2_jl8,jp2_jl9,jp2_jl10;
JTextField jp1_jtf1,jp1_jtf2,jp1_jtf3,jp1_jtf4,jp1_jtf5,jp1_jtf6,jp1_jtf7,jp2_jtf1,jp2_jtf2,jp2_jtf3,jp2_jtf4,jp2_jtf5,jp2_jtf6,jp2_jtf7,jp2_jtf8,jp2_jtf9,jp2_jtf10;
JPasswordField jpassword;
JButton jp3_jb1,jp3_jb2;
//owner--他的父窗口
//title--窗口名
//model--指定是模式窗口还是非模式窗口
public AddDialog(Frame owner,String tittle,boolean modal) {
super(owner,tittle,true);
try {
titleIco=ImageIO.read(new File("images/renshidengji.png"));
this.setIconImage(titleIco);
} catch (IOException e) {
e.printStackTrace();
}
Container ct=this.getContentPane();
this.setLayout(null);
jp0=new JPanel(new BorderLayout());
jp0.setBounds(75, 30, 101, 143);
jp0_jl1=new JLabel("用户头像");
jp0.setAlignmentY(CENTER_ALIGNMENT);
jp0_jl1.setFont(MyTools.f1);
jp0_jl1.setForeground(Color.red);
jp0_jl2=new JLabel(new ImageIcon("images/users.gif"));
jp0.add(jp0_jl1,"North");
jp0.add(jp0_jl2,"Center");
jp1=new JPanel();
jp1.setLayout(new GridLayout(5,2,0,8));
jp1.setBounds(20,193,220, 150);
jp1_jl3=new JLabel("员工编号");
jp1_jtf3=new JTextField();
jp1_jl3.setFont(MyTools.f1);
jp1_jl3.setForeground(Color.black);
jp1_jtf3.setForeground(Color.black);
jp1_jtf3.setFont(MyTools.f1);
jp1_jl4=new JLabel("姓 名");
jp1_jtf4=new JTextField();
jp1_jl4.setFont(MyTools.f1);
jp1_jl4.setForeground(Color.black);
jp1_jtf4.setForeground(Color.black);
jp1_jtf4.setFont(MyTools.f1);
jp1_jl5=new JLabel("性 别");
jp1_jtf5=new JTextField();
jp1_jl5.setFont(MyTools.f1);
jp1_jl5.setForeground(Color.black);
jp1_jtf5.setForeground(Color.black);
jp1_jtf5.setFont(MyTools.f1);
jp1_jl6=new JLabel("年 龄");
jp1_jtf6=new JTextField();
jp1_jl6.setFont(MyTools.f1);
jp1_jl6.setForeground(Color.black);
jp1_jtf6.setForeground(Color.black);
jp1_jtf6.setFont(MyTools.f1);
jp1_jl7=new JLabel("身份证号");
jp1_jtf7=new JTextField();
jp1_jl7.setFont(MyTools.f1);
jp1_jl7.setForeground(Color.black);
jp1_jtf7.setForeground(Color.black);
jp1_jtf7.setFont(MyTools.f1);
jp1.add(jp1_jl3);
jp1.add(jp1_jtf3);
jp1.add(jp1_jl4);
jp1.add(jp1_jtf4);
jp1.add(jp1_jl5);
jp1.add(jp1_jtf5);
jp1.add(jp1_jl6);
jp1.add(jp1_jtf6);
jp1.add(jp1_jl7);
jp1.add(jp1_jtf7);
jp2=new JPanel(new GridLayout(10,2,0,8));
jp2.setBounds(341,45,220, 295);
//jp2.setBorder(BorderFactory.createLineBorder(Color.gray));
jp2_jl1=new JLabel("国 家");
jp2_jtf1=new JTextField();
jp2_jl1.setFont(MyTools.f1);
jp2_jl1.setForeground(Color.black);
jp2_jtf1.setForeground(Color.black);
jp2_jtf1.setFont(MyTools.f1);
jp2_jl2=new JLabel("地 址");
jp2_jtf2=new JTextField();
jp2_jl2.setFont(MyTools.f1);
jp2_jl2.setForeground(Color.black);
jp2_jtf2.setForeground(Color.black);
jp2_jtf2.setFont(MyTools.f1);
jp2_jl3=new JLabel("邮 编");
jp2_jtf3=new JTextField();
jp2_jl3.setFont(MyTools.f1);
jp2_jl3.setForeground(Color.black);
jp2_jtf3.setForeground(Color.black);
jp2_jtf3.setFont(MyTools.f1);
jp2_jl4=new JLabel("入职日期");
jp2_jtf4=new JTextField();
jp2_jl4.setFont(MyTools.f1);
jp2_jl4.setForeground(Color.black);
jp2_jtf4.setForeground(Color.black);
jp2_jtf4.setFont(MyTools.f1);
jp2_jl5=new JLabel("工 作");
jp2_jtf5=new JTextField();
jp2_jl5.setFont(MyTools.f1);
jp2_jl5.setForeground(Color.black);
jp2_jtf5.setForeground(Color.black);
jp2_jtf5.setFont(MyTools.f1);
jp2_jl6=new JLabel("薪 水");
jp2_jtf6=new JTextField();
jp2_jl6.setFont(MyTools.f1);
jp2_jl6.setForeground(Color.black);
jp2_jtf6.setForeground(Color.black);
jp2_jtf6.setFont(MyTools.f1);
jp2_jl7=new JLabel("邮 箱");
jp2_jtf7=new JTextField();
jp2_jl7.setFont(MyTools.f1);
jp2_jl7.setForeground(Color.black);
jp2_jtf7.setForeground(Color.black);
jp2_jtf7.setFont(MyTools.f1);
jp2_jl8=new JLabel("手 机 号");
jp2_jtf8=new JTextField();
jp2_jl8.setFont(MyTools.f1);
jp2_jl8.setForeground(Color.black);
jp2_jtf8.setForeground(Color.black);
jp2_jtf8.setFont(MyTools.f1);
jp2_jl9=new JLabel("婚 否");
jp2_jtf9=new JTextField();
jp2_jl9.setFont(MyTools.f1);
jp2_jl9.setForeground(Color.black);
jp2_jtf9.setForeground(Color.black);
jp2_jtf9.setFont(MyTools.f1);
jp2_jl10=new JLabel("教育背景");
jp2_jtf10=new JTextField();
jp2_jl10.setFont(MyTools.f1);
jp2_jl10.setForeground(Color.black);
jp2_jtf10.setForeground(Color.black);
jp2_jtf10.setFont(MyTools.f1);
jp2.add(jp2_jl1);
jp2.add(jp2_jtf1);
jp2.add(jp2_jl2);
jp2.add(jp2_jtf2);
jp2.add(jp2_jl3);
jp2.add(jp2_jtf3);
jp2.add(jp2_jl4);
jp2.add(jp2_jtf4);
jp2.add(jp2_jl5);
jp2.add(jp2_jtf5);
jp2.add(jp2_jl6);
jp2.add(jp2_jtf6);
jp2.add(jp2_jl7);
jp2.add(jp2_jtf7);
jp2.add(jp2_jl8);
jp2.add(jp2_jtf8);
jp2.add(jp2_jl9);
jp2.add(jp2_jtf9);
jp2.add(jp2_jl10);
jp2.add(jp2_jtf10);
//组件间水平间距为30像素,垂直间距为5像素
jp3=new JPanel(new FlowLayout(FlowLayout.RIGHT,30,5));
jp3.setBounds(-1, 375,602,50);
jp3.setBorder(BorderFactory.createLineBorder(Color.gray));
jp3_jb1=new JButton("添加");
jp3_jb1.addActionListener(this);
jp3_jb1.setFont(MyTools.f1);
jp3_jb2=new JButton("取消");
jp3_jb2.setFont(MyTools.f1);
jp3_jb2.addActionListener(this);
jp3.add(jp3_jb1);
jp3.add(jp3_jb2);
jp4=new JPanel(new GridLayout(10,2,0,4));
jp4.setBounds(301,-1,300, 377);
jp4.setBorder(BorderFactory.createLineBorder(Color.gray));
ct.add(jp1);
ct.add(jp0);
ct.add(jp2);
ct.add(jp3);
ct.add(jp4);
//ct.add(jp1_jl4);
this.setSize(600,450);
//禁止更改窗体大小
this.setResizable(false);
int width=Toolkit.getDefaultToolkit().getScreenSize().width;
int height=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setLocation(width/2-380, height/2-340);
this.setVisible(true); //窗口可视
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jp3_jb1) {
String sql="insert into stu values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
String[] paras= {jp1_jtf1.getText(),jp1_jtf2.getText(),jp1_jtf3.getText(),jp1_jtf4.getText(),jp1_jtf5.getText(),jp1_jtf6.getText(),jp1_jtf7.getText(),jp2_jtf1.getText(),jp2_jtf2.getText(),jp2_jtf3.getText(),jp2_jtf4.getText(),jp2_jtf5.getText(),jp2_jtf6.getText(),jp2_jtf7.getText(),jp2_jtf8.getText(),jp2_jtf9.getText(),jp2_jtf10.getText()};
EmpModel temp=new EmpModel();
if(!temp.upEmp(sql, paras))
{
JOptionPane.showMessageDialog(this, "添加失败!");
}
//关闭对话框
this.dispose();
}
} |
|