JAVA GUI 的小程序 大家帮下忙
classstudent:名字name,地址address,邮编zipclasslab:弹出一个窗口,上面有三个textbox分别可以输入名字地址和邮编,并且有个保存按钮...
class student:
名字name, 地址address, 邮编zip
class lab:
弹出一个窗口,上面有三个text box 分别可以输入名字地址和邮编,并且有个保存按钮,当点击保存按钮时 将会把输入的信息保存到文件里
希望各位大虾帮忙 可以加分!
急用啊 谢谢 展开
名字name, 地址address, 邮编zip
class lab:
弹出一个窗口,上面有三个text box 分别可以输入名字地址和邮编,并且有个保存按钮,当点击保存按钮时 将会把输入的信息保存到文件里
希望各位大虾帮忙 可以加分!
急用啊 谢谢 展开
6个回答
展开全部
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
public class Test extends JFrame implements ActionListener
{
private JTextField text1=null;
private JTextField text2=null;
private JTextField text3=null;
public Test()
{
setTitle("文件简单操作");
setSize(200,150) ;
setResizable(true) ;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭窗口动作
Dimension screen=Toolkit.getDefaultToolkit().getScreenSize(); //使屏幕居中
setLocation((screen.width-200)/2,(screen.height-300)/2); //使屏幕居中
//----------------------
Container c=getContentPane();
c.setLayout(new GridLayout(4,2));
c.add(new JLabel("姓名:"));
text1=new JTextField();
c.add(text1);
c.add(new JLabel("地址:"差脊));
text2=new JTextField();
c.add(text2);
c.add(new JLabel("邮虚段渗编:"));
text3=new JTextField();
c.add(text3);
JButton b=new JButton("保存");
b.addActionListener(this);
c.add(b);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
try
{
FileWriter fos=new FileWriter("data.txt",true);
BufferedWriter bos=new BufferedWriter(fos);
PrintWriter pw=new PrintWriter(bos);
pw.println("姓名:"+text1.getText());
pw.println("地址:"+text2.getText());
pw.println("燃姿邮编:"+text3.getText());
pw.close();
}
catch(Exception ee){JOptionPane.showMessageDialog(null,"打开文件异常:"+ee.toString());}
}
public static void main(String [] args)
{
new Test();
}
}
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
public class Test extends JFrame implements ActionListener
{
private JTextField text1=null;
private JTextField text2=null;
private JTextField text3=null;
public Test()
{
setTitle("文件简单操作");
setSize(200,150) ;
setResizable(true) ;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭窗口动作
Dimension screen=Toolkit.getDefaultToolkit().getScreenSize(); //使屏幕居中
setLocation((screen.width-200)/2,(screen.height-300)/2); //使屏幕居中
//----------------------
Container c=getContentPane();
c.setLayout(new GridLayout(4,2));
c.add(new JLabel("姓名:"));
text1=new JTextField();
c.add(text1);
c.add(new JLabel("地址:"差脊));
text2=new JTextField();
c.add(text2);
c.add(new JLabel("邮虚段渗编:"));
text3=new JTextField();
c.add(text3);
JButton b=new JButton("保存");
b.addActionListener(this);
c.add(b);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
try
{
FileWriter fos=new FileWriter("data.txt",true);
BufferedWriter bos=new BufferedWriter(fos);
PrintWriter pw=new PrintWriter(bos);
pw.println("姓名:"+text1.getText());
pw.println("地址:"+text2.getText());
pw.println("燃姿邮编:"+text3.getText());
pw.close();
}
catch(Exception ee){JOptionPane.showMessageDialog(null,"打开文件异常:"+ee.toString());}
}
public static void main(String [] args)
{
new Test();
}
}
展开全部
先占位置
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
怎么说呢。现在没有时间,晚点没有人帮你写的话,我写给你好了。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个是比较简单,用IO,和JInternalFrame就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼主是纯信棚陆手工代码吗?
建议用ide开发工具
Myeclipse 或者Jbuilder
像你滑顷现在做和亩的Swing,还是用Jbuilder吧
很简单的
建议用ide开发工具
Myeclipse 或者Jbuilder
像你滑顷现在做和亩的Swing,还是用Jbuilder吧
很简单的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.RowFilter;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
/*
* NewJFrame.java
*
* Created on 2008年10月19日, 下午3:36
*/
/**
*
* @author ZouLiXing
*/
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
student = new Student();
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new java.awt.FlowLayout());
jLabel1.setText("姓名:");
getContentPane().add(jLabel1);
jTextField1.setText("jTextField1");
getContentPane().add(jTextField1);
jLabel2.setText("地址:");
getContentPane().add(jLabel2);
jTextField2.setText("jTextField2");
getContentPane().add(jTextField2);
jLabel3.setText("邮编:");
getContentPane().add(jLabel3);
jTextField3.setText("jTextField3");
getContentPane().add(jTextField3);
jButton1.setText("保存");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
pack();
}// </editor-fold>
/**
* 保存事件
* @param evt
*/
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
student.name = jTextField1.getText();
student.address = jTextField2.getText();
student.zip = jTextField3.getText();
try{
save(); //保存文件中....
}catch(Exception e){
}
}
public boolean save()throws Exception{
String filename="学信息生.txt";
java.io.File file = new java.io.File(filename);
if (!file.exists()) {
if (!file.createNewFile()) {
return false;
}
}
java.io.FileOutputStream fos;
String content = "name=" + student.name + "\r\n";
content = content + "address=" + student.address + "\r\n";
content = content + "zip=" + student.zip + "\r\n";
fos = new java.io.FileOutputStream(file);
byte[] b = content.getBytes();
fos.write(b);
fos.close();
return true;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
private Student student;
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration
}
//
public class Student {
public String name="";
public String address="";
public String zip="";
}
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.RowFilter;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
/*
* NewJFrame.java
*
* Created on 2008年10月19日, 下午3:36
*/
/**
*
* @author ZouLiXing
*/
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
student = new Student();
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new java.awt.FlowLayout());
jLabel1.setText("姓名:");
getContentPane().add(jLabel1);
jTextField1.setText("jTextField1");
getContentPane().add(jTextField1);
jLabel2.setText("地址:");
getContentPane().add(jLabel2);
jTextField2.setText("jTextField2");
getContentPane().add(jTextField2);
jLabel3.setText("邮编:");
getContentPane().add(jLabel3);
jTextField3.setText("jTextField3");
getContentPane().add(jTextField3);
jButton1.setText("保存");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
pack();
}// </editor-fold>
/**
* 保存事件
* @param evt
*/
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
student.name = jTextField1.getText();
student.address = jTextField2.getText();
student.zip = jTextField3.getText();
try{
save(); //保存文件中....
}catch(Exception e){
}
}
public boolean save()throws Exception{
String filename="学信息生.txt";
java.io.File file = new java.io.File(filename);
if (!file.exists()) {
if (!file.createNewFile()) {
return false;
}
}
java.io.FileOutputStream fos;
String content = "name=" + student.name + "\r\n";
content = content + "address=" + student.address + "\r\n";
content = content + "zip=" + student.zip + "\r\n";
fos = new java.io.FileOutputStream(file);
byte[] b = content.getBytes();
fos.write(b);
fos.close();
return true;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
private Student student;
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration
}
//
public class Student {
public String name="";
public String address="";
public String zip="";
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询