A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

package Lianx;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.regex.Pattern;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
public class AddDialog extends JDialog{
private JLabel account,name,sex,phone,password;
private JTextField jaccount,jname,jsex,jphone,jpassword;
private JButton ok,res;
private JLabel fu,fu1,fu2;
private CardLyouta datetable;
private CardLyouta modelForm;
private CardLyouta jf;

public void init(){
JPanel north = new JPanel();
north.setPreferredSize(new Dimension(0,10));
JPanel center = new JPanel();
center.setLayout(null);
account=new JLabel("帐 号:");
name=new JLabel("姓 名:");
sex=new JLabel("性 别:");
phone=new JLabel("电 话:");
password=new JLabel("密 码:");
account.setBounds(22, 5, 70, 25);
name.setBounds(22, 31, 70, 25);
sex.setBounds(22, 54, 70, 25);
phone.setBounds(22, 77, 70, 25);
password.setBounds(22, 100, 70, 25);
jaccount=new JTextField();
jname=new JTextField();
jsex=new JTextField();
jphone=new JTextField();
jpassword=new JTextField();
jaccount.setBounds(71, 8, 255, 19);
jname.setBounds(71, 34, 255, 19);
String[] abc={"男","女"};
JComboBox jc=new JComboBox(abc);
jc.setBounds(71, 57, 255, 19);
jphone.setBounds(71,80, 255, 19);
jpassword.setBounds(71,103, 255, 19);
fu=new JLabel(" *");
fu.setForeground(Color.red);
fu.setBounds(333, 8, 22, 19);
fu1=new JLabel(" *");
fu1.setForeground(Color.red);
fu1.setBounds(333, 80, 22, 19);
fu2=new JLabel(" *");
fu2.setForeground(Color.red);
fu2.setBounds(333, 103, 22, 19);
ok=new JButton("确定");
ok.setBounds(99,140, 70, 24);
res=new JButton("重置");
res.setBounds(188,140, 70, 24);
center.add(ok);
center.add(res);
center.add(account);
center.add(name);
center.add(sex);
center.add(phone);
center.add(password);
center.add(jaccount);
center.add(jname);
center.add(jc);
center.add(jphone);
center.add(jpassword);
center.add(fu);
center.add(fu1);
center.add(fu2);
center.add(ok);
center.add(res);
setLayout(new BorderLayout());
add(north,BorderLayout.NORTH);
add(center,BorderLayout.CENTER);
//事件处理
ActionListener action=new ActionListener()
{
public void actionPerformed(ActionEvent e ){
if(e.getSource()==ok){
String s =jaccount.getText().trim()+""+"@"+jname.getText().trim()+""+"@"+ jsex.getSelectedText()+""+"@"+jphone.getText().trim()+""+"@"+jpassword.getText().trim()+"";
String fen="\\@";
Pattern pat=Pattern.compile(fen);
String[] str=pat.split(s);
// for(int i=0;i<str.length;i++){
//
// }
modelForm.addRow(str);

// String str1=jaccount.getText();
// String str2=jname.getText();
// String str3=jsex.getSelectedText();
// String str4=jphone.getText();
// String str5=jpassword.getText();
// String[] data = {str1, str2, str3, str4 ,str5};
// modelForm.addRow(data);


}
else if(e.getSource()==res){
jaccount.setText(" ");
jname.setText(" ");
jphone.setText(" ");
jpassword.setText(" ");
}
}
};
res.addActionListener(action);
ok.addActionListener(action);

setModal(true);
setSize(430 ,220);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setVisible(true);
}
//
public JTextField getJaccount() {
return jaccount;
}
public JTextField getJname() {
return jname;
}
public JTextField getJsex() {
return jsex;
}
public JTextField getJpjone() {
return jphone;
}
public JTextField getJpassword() {
return jpassword;
}



}


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马