学生信息管理系统(GUI界面布局+java版本+文件保存)
学生信息管理系统(GUI界面布局+文件保存+源码) 自动检查重复学号 java版本
java实现聊天室:
java学生成绩管理系统:
新代码视频教学地址:
旧代码视频教学地址:
public class StudentUI {
// 定义容器
public static JFrame jframe_1 =new JFrame("学生信息管理系统");
// 定义面板
public static JPanel jpanel_1=new JPanel(new FlowLayout());//流式布局
public static JPanel jpanel_2=new JPanel(null);//空布局
// 设置文本区用于显示信息
public static JTextArea j_1=new JTextArea();
public static void main(String[] args) {
// 实例化
StudentUI ui=new StudentUI();
// 调用方法
ui.init_1();
}
// 主界面
public void init_1() {
// 窗口大小
jframe_1.setSize(810,400);
// 空布局
jframe_1.setLayout(null);
// 窗口不可调整
jframe_1.setResizable(false);
// 关闭窗口则退出程序
jframe_1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 菜单栏
JMenuBar bar=new JMenuBar();
// 一级菜单
JMenu men_1=new JMenu("基本操作");
JMenu men_2=new JMenu("工具");
// 子菜单
JMenuItem item_1=new JMenuItem("添加学生");
JMenuItem item_2=new JMenuItem("修改学生");
JMenuItem item_3=new JMenuItem("删除学生");
JMenuItem item_4=new JMenuItem("查询学生");
JMenuItem item_5=new JMenuItem("保存");
// 定义字体
Font font=new Font("黑体",Font.PLAIN,15);
// 设置菜单字体
men_1.setFont(font);
men_2.setFont(font);
item_1.setFont(font);
item_2.setFont(font);
item_3.setFont(font);
item_4.setFont(font);
item_5.setFont(font);
// 加入
men_1.add(item_1);
men_1.add(item_2);
men_1.add(item_3);
men_1.add(item_4);
men_2.add(item_5);
bar.add(men_1);
bar.add(men_2);
jframe_1.setJMenuBar(bar);
// 设置面板位置、大小、颜色
jpanel_1.setBounds(0,0,200,400);
jpanel_2.setBounds(210,0,600,400);
jpanel_1.setBackground(Color.LIGHT_GRAY);
jpanel_2.setBackground(Color.LIGHT_GRAY);
jframe_1.add(jpanel_1);
jframe_1.add(jpanel_2);
//设置文本区不能编辑
j_1.setEditable(false);
//将j1作为可滚动面板sp的显示区域
JScrollPane sp=new JScrollPane(j_1);
sp.setSize(585,340);
StudentUI.jpanel_2.add(sp);
// 窗口居中
jframe_1.setLocationRelativeTo(null);
// 窗口显示
jframe_1.setVisible(true);
// 注册 添加学生 按钮的监听
item_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
// 调用方法
StudentUI.init_2();
}
});
旧代码部分源码如下:
public class StudentUI {
//设置变量
JFrame f =new JFrame("学生信息管理系统");
JButton a[]=new JButton [5];
JPanel p = new JPanel(null);
public static void main(String[] args) {
StudentUI student=new StudentUI();
student.init();
}
//初始化
public void init() {
//设置布局
f.setLayout(null);
f.setLocation(400,40);
f.setSize(600,300);
//退出后关闭所有窗口
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
for(int i=0;i<a.length;i++)
{
//实例化对象
a[i]=new JButton();
//设置按钮位置
a[i].setBounds(0,0+40*i,100,40);
//将按钮加入容器
f.add(a[i]);
}
//设置按钮标签
a[0].setText("1:增加学生");
a[1].setText("2:删除学生");
a[2].setText("3:修改学生");
a[3].setText("4:查询学生");
a[4].setText("5:保存学生");
//窗口不能调整
f.setResizable(false);
//显示窗口
f.setVisible(true);
//设置面板
p.setLocation(250,0);
p.setSize(350,400);
p.setBackground(Color.LIGHT_GRAY);
f.add(p);
//创建事件类
StudentListen f1=new StudentListen( p,a,f);
for(int i=0;i<a.length;i++) {
a[i].addActionListener(f1);
}
}
}
上一篇:
IDEA上Java项目控制台中文乱码
