写一个学生信息输入表格java GUI

package gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LabelFrame extends JFrame
{
    private final JLabel label1;
    private final JLabel label2;
    private final JLabel label3;
    private final JLabel label4;
    private final JLabel label5;
    private JTextField Field1,Field2,Field3,Field4;
    private JButton cButton;
    public LabelFrame()
    {   

        super("Student information");
        setLayout(new FlowLayout());
        label1 = new JLabel("Student name:");
        add(label1);
        Field1 = new JTextField(5);
        add(Field1);
        label1.setToolTipText("studentA");

        Icon photo = new ImageIcon(getClass().getResource( "photo.gif"));
        label2 = new JLabel("Student photo:", photo,SwingConstants.RIGHT);
        label2.setHorizontalTextPosition(SwingConstants.LEFT);
        //Icon photo = new ImageIcon(getClass().getResource( "photo.gif"));
        add(label2);

        label3 = new JLabel("Student number: ");
        label3.setToolTipText("123456");
        add(label3);
        Field2 = new JTextField(5);
        add(Field2);

        label4 = new JLabel("major:");
        add(label4);
        Field3 = new JTextField(10);
        add(Field3);
        //label4.setHorizontalTextPosition(SwingConstants.CENTER);
        label5 = new JLabel("Student Age: ");
        add(label5);
        Field4 = new JTextField(5);
        add(Field4);
        cButton = new JButton("提交");
        add(cButton);
        ActionEventHandler handler=new ActionEventHandler();
        cButton.addActionListener(handler);
    }
    static JFrame jf = new JFrame();
    public static void main(String[] args)
    {
        LabelFrame labelFrame = new LabelFrame();
        labelFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        labelFrame.setSize(200,250);
        labelFrame.setVisible(true);
        jf.setSize(200,250);
        jf.setLayout(new FlowLayout());

    }
     private class ActionEventHandler implements ActionListener{
         public void actionPerformed(ActionEvent event){
                if (event.getSource()== cButton){
                    jf.setVisible(true);
                    JLabel labelx;
                    JLabel labelx2;
                    JLabel labelx3;
                    JLabel labelx4;
                    JLabel labelx5;
                    Icon photo2 = new ImageIcon(getClass().getResource( "photo.gif"));
                    labelx=new JLabel("Student name: "+Field1.getText());
                    jf.add(labelx);
                    labelx5 = new JLabel("Student photo:", photo2,SwingConstants.RIGHT);
                    labelx5.setHorizontalTextPosition(SwingConstants.LEFT);
                    jf.add(labelx5);
                    labelx2=new JLabel(" Student number: "+Field2.getText());
                    jf.add(labelx2);
                    labelx3=new JLabel(" Student major: "+Field3.getText());
                    jf.add(labelx3);
                    labelx4=new JLabel(" Student Age: "+Field4.getText());
                    jf.add(labelx4);


                }

     }
     }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值