java实现学生信息录入界面(java录入学生信息的界面)

网友投稿 435 2022-08-02


本文实例为大家分享了java实现学生信息录入界面的具体代码,供大家参考,具体内容如下

按如下要求完成编程:

1、创建一个学生信息录入界面,学生有学号、姓名、年龄、班级和成绩信息,界面中包含“确定”和“重置”按钮。

2、实现事件处理,单击“确定”按钮将学生信息封装到对象中,并通过输出对象将学生信息显示在终端控制台上;点击“重置”按钮情况界面中用户输入的信息。

package work;

import java.awt.Button;

import java.awt.Frame;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.FocusEvent;

import java.awt.event.FocusListener;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class work6 implements ActionListener,WindowListener,FocusListener{

JTextField jt1 = new JTextField(30);

JTextField jt2 = new JTextField(30);

JTextField jt3 = new JTextField(30);

JTextField jt4 = new JTextField(30);

JTextField jt5 = new JTextField(30);

public work6(){

Frame f = new Frame("学生信息管理系统");

JPanel jp1,jp2,jp3,jp4,jp5,jp6;

jp1=new JPanel(); //创建6个面板

jp2=new JPanel();

jp3=new JPanel();

jp4=new JPanel();

jp5=new JPanel();

jp6=new JPanel();

JLabel l1 = new JLabel("学号");

JLabel l2 = new JLabel("姓名");

JLabel l3 = new JLabel("年龄");

JLabel l4 = new JLabel("班级");

JLabel l5 = new JLabel("成绩");

Button b1 = new Button("确定");

Button b2 = new Button("重置");

f.setLayout(new GridLayout(6, 1));

f.add(jp1);

f.add(jp2);

f.add(jp3);

f.add(jp4);

f.add(jp5);

f.add(jp6);

jp1.add(l1);

jp1.add(jt1);

jp2.add(l2);

jp2.add(jt2);

jp3.add(l3);

jp3.add(jt3);

jp4.add(l4);

jp4.add(jt4);

jp5.add(l5);

jp5.add(jt5);

jp6.add(b1);

jp6.add(b2);

f.setLocation(300, 300);

f.setSize(500, 450);

// f.setBounds(300, 300, 500, 500);

f.setVisible(true);

// MyListener m1 = new MyListener();

b1.addActionListener(this);

b2.addFocusListener(this);

f.addWindowListener(this);

}

public static void main(String[] args) {

// TODO Auto-generated method stub

new work6();

}

@Override

public void windowActivated(WindowEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void windowClosed(WindowEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void windowClosing(WindowEvent arg0) {

// TODO Auto-generated method stub

System.exit(0);

}

@Override

public void windowDeactivated(WindowEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public voGjmkROYnBIid windowDeiconified(WindowEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void windowIconified(WindowEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void windowOpened(WindowEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

System.out.println("学生\n学号:"+jt1.getText()+"\n姓名:"+jt2.getText()+"\n年龄:"+jt3.getText()+"\n班级:"+jt4.getText()+"\n成绩:"+jt5.getText());

// System.out.println("学生");

}

@Override

public void focusGained(FocusEvent e) {

// TODO Auto-generated method stub

jt1.setText("");

jt2.setText("");

jt3.setText("");

jt4.setText("");

jt5.setText("");

}

@Override

public void focusLost(FocusEvent e) {

// TODO Auto-generated method stub

}

}

结果

点击确认:

点击重置:


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:java swing实现简单计算器界面(java培训)
下一篇:Java实现简单GUI登录和注册界面(java编写注册登录界面)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~