import java.awt.*;
import javax.swing.*;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import java.awt.event.*;
import java.util.Vector;
class Student {
private int no;
private String name;
private String sex;
private int age;
private String hobby;
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public Student(int no,String name,String sex,int age,String hobby){
this.no=no;
this.name=name;
this.sex=sex;
this.age=age;
this.hobby=hobby;
}
public Student(){
}
public String toString(){
return "学号:"+no+" 姓名"+name+" 性别:"+sex+" 年龄:"+age+" 爱好:"+hobby+"\n";
}
}
public class Main extends JFrame{
JMenuBar menuBar;
Container container;
CardLayout cardLayout;
JTextArea jTextArea;
JPanel mainPanel;
JPanel detailPanel;
JPanel addPanel;
JPanel modifyPanel;
JTextField modifInput;
JPanel searchPanel;
JTextArea searchResault;
JTextField searchInput;
JPanel removePanel;
JTextField removeInput;
JTextField addNoInput;
JTextField addNameInput;
JTextField addAgeInput;
JTextField addsexInput;
JTextField addhobbyInput;
JTextField modifyNoInput;
JTextField modifyNameInput;
JTextField modifyAgeInput;
JTextField modifySexInput;
JTextField modifyHobbyInput;
Vector<Student> students;
Main(){
students = new Vector<Student>();
students.add(new Student(100,"aa","男",18,"读书"));
students.add(new Student(101,"bb","男",19,"看报"));
container = getContentPane();
mainPanel = new JPanel();
cardLayout = new CardLayout();//设置卡片布局
mainPanel.setLayout(cardLayout);
container.setLayout(new FlowLayout());
setMenu();//设置菜单
setDetailPanel();//设置详情页
setaddPanel();//设置添加对象页
setRemovePanel();//设置删除对象页
setModifyPanel();//设置修改对象页
setSearchPanel();//设置查询对象页
container.add(mainPanel);
}
public void setMenu(){
JMenu menu;
menuBar = new JMenuBar();
this.setJMenuBar(menuBar);
menu = new JMenu("编辑");
menuBar.add(menu);
JMenuItem mainItem = new JMenuItem("显示详情");
mainItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
cardLayout.show(mainPanel,"detailPanel");//切换卡片页面
showDetails();
}
});
menu.add(mainItem);
JMenuItem addItem = new JMenuItem
对学生类(包括学号、姓名、性别、年龄、爱好等)完成GUI的设计,使能对学生对象进行添加、修改、删除、查询操作
最新推荐文章于 2022-07-04 20:38:22 发布