Java基本信息采集程序

采用简单的Swing用户界面组件实现基本信息采集工作。

TextComponentFrame.java

package text;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;


public class TextComponentFrame extends JFrame {

    public static final int TEXTAREA_ROWS = 8;
    public static final int TEXTAREA_COLUNS = 20;

    final JTextField textfield1 = new JTextField();
    final JTextField textfield2 = new JTextField();
    final JTextField textfield3 = new JTextField();
    final JTextField textfield4 = new JTextField();
    final JTextField textfield5 = new JTextField();

    int id = 0;
    public TextComponentFrame() {

        JPanel northpanel = new JPanel();
        northpanel.setLayout(new GridLayout(5, 2));
        northpanel.add(new JLabel("姓名:", SwingConstants.RIGHT));
        northpanel.add(textfield1);
        northpanel.add(new JLabel("性别:", SwingConstants.RIGHT));
        northpanel.add(textfield2);
        northpanel.add(new JLabel("年龄:", SwingConstants.RIGHT));
        northpanel.add(textfield3);
        northpanel.add(new JLabel("身份证号:", SwingConstants.RIGHT));
        northpanel.add(textfield4);
        northpanel.add(new JLabel("家庭住址:", SwingConstants.RIGHT));
        northpanel.add(textfield5);

        add(northpanel, BorderLayout.NORTH);

        final JTextArea textArea = new JTextArea("详细信息显示区",TEXTAREA_ROWS, TEXTAREA_COLUNS);
        JScrollPane scrollPane = new JScrollPane(textArea);

        add(scrollPane, BorderLayout.CENTER);

        JPanel southPanel = new JPanel();
        JButton insertButton = new JButton("提交");
        southPanel.add(insertButton);
        insertButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                if(id == 0) {
                    textArea.setText("");
                }
                id++;
                textArea.append(
                "编号:" + id + "\n" +
                "姓名:" + textfield1.getText() + "\n" + 
                "性别:" + textfield2.getText() + "\n" + 
                "年龄:" + textfield3.getText() + "\n" +
                "身份证号:" + textfield4.getText() + "\n" +
                "家庭住址:" + textfield5.getText() + "\n" +
                "——————————————————————————————————————" + "\n");
                resetValue();
            }
        });
        add(southPanel,BorderLayout.SOUTH);
        pack();
    }

    protected void resetValue() {
        // TODO Auto-generated method stub
        textfield1.setText("");
        textfield2.setText("");
        textfield3.setText("");
        textfield4.setText("");
        textfield5.setText("");
    }



}

测试程序

TestFrame.java

package text;

import java.awt.EventQueue;

import javax.swing.JFrame;

public class TestFrame {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
         EventQueue.invokeLater(new Runnable()
         {
            public void run()
            {
               JFrame frame = new TextComponentFrame();
               frame.setTitle("FontTest");
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               frame.setVisible(true);
            }
         });
    }

}

这里写图片描述

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值