当前位置:编程学习 > JAVA >>

【急】【怎么把对话框的数据添加到表格中 急用 谢谢朋友】【


----------------------------第二个文件---------------------------------------
package Rong;

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;
}



}


对话框中确定按钮事件怎么写 谢谢你们 帮忙下 --------------------编程问答-------------------- 你分真多,一次性发两贴,那边回答你了
http://topic.csdn.net/u/20120425/10/3b37fd2c-ba6b-4807-97db-b3cd3b0bc908.html?33234 --------------------编程问答-------------------- 帮忙把 --------------------编程问答--------------------
补充:Java ,  Java相关
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,