因为个人原因,在可视化这方面落下了课程,我尽力在补,目前功能不完善,后续会完善。
登录界面
代码
package APP;
import javax.swing.*;
import java.awt.*;
public class LoginView extends JFrame {
//建立弹簧布局
SpringLayout springLayout = new SpringLayout();
//设置 流布局的管理器为弹簧布局
JPanel jPanel = new JPanel(springLayout);
//定义组件
JLabel title = new JLabel("学生信息管理系统");
JLabel user = new JLabel("用户名:");
JTextField username = new JTextField();
JLabel password = new JLabel("密 码:");
JTextField password1 = new JTextField();
JButton login = new JButton("登录");
//构造组件
public LoginView() {
//名字
super("弹簧布局");
Container tan_huang_bu_ju_mian_ban = getContentPane();
jPanel.setBackground(Color.CYAN);
jPanel.add(title);
jPanel.add(user);
jPanel.add(username);
username.setPreferredSize(new Dimension(200, 30));//设置titleText大小
jPanel.add(password);
jPanel.add(password1);
password1.setPreferredSize(new Dimension(200, 30));
jPanel.add(login);
login.setPreferredSize(new Dimension(80, 30));
//写法1
//设置title位置
SpringLayout.Constraints title1 = springLayout.getConstraints(title);//获取title布局信息
title1.setX(Spring.constant(200));//离左100
title1.setY(Spring.constant(50));//离上50
//写法2
/*参数
e1:哪个边界
c1:要设置的组件
pdd:距离值
e2:相对边界
c2:参照物
*/
//设置user
springLayout.putConstraint(SpringLayout.WEST, user, -170, SpringLayout.EAST, title);
springLayout.putConstraint(SpringLayout.NORTH, user, 25, SpringLayout.SOUTH, title);
springLayout.putConstraint(SpringLayout.WEST, username, 0, SpringLayout.EAST, user);
springLayout.putConstraint(SpringLayout.NORTH, username, 25, SpringLayout.SOUTH, title);
//设置其他组件位置
springLayout.putConstraint(SpringLayout.EAST, password, 0, SpringLayout.EAST, user);
springLayout.putConstraint(SpringLayout.NORTH, password, 25, SpringLayout.SOUTH, user);
springLayout.putConstraint(SpringLayout.EAST, password1, 0, SpringLayout.EAST, username);
springLayout.putConstraint(SpringLayout.NORTH, password1, 10, SpringLayout.SOUTH, username);
springLayout.putConstraint(SpringLayout.WEST, login, 50, SpringLayout.EAST, password);
springLayout.putConstraint(SpringLayout.NORTH, login, 20, SpringLayout.SOUTH, password);
tan_huang_bu_ju_mian_ban.add(jPanel); //添加到面板
//大小
setSize(500, 400);
//大小不可改变
setResizable(false);
//居中
//1自动居中
//jFrame.setLocationRelativeTo(null);
//2自行计算后居中
Dimension ping_mu_size = Toolkit.getDefaultToolkit().getScreenSize();//获取屏幕大小
int offsetX = (ping_mu_size.width - 600) / 2;//设置横向偏移
int offsetY = (ping_mu_size.height - 400) / 2;//设置纵向偏移
setLocation(offsetX, offsetY);
//关闭后退出
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//可见
setVisible(true);
}
//主函数
public static void main(String[] args) {
new LoginView();
}
}
效果
主界面
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
public class Menu {
private JButton but1 = new JButton("增加数据"); // 按钮
private JButton but2 = new JButton("删除数据");
private JButton but3 = new JButton("修改数据");
private JButton but4 = new JButton("查看数据");
private JButton but0 = new JButton("退出系统");
private JButton but5 = new JButton("显示");
private JButton clear = new JButton("清空");
private JTextField number = new JTextField();// 文本框
private JTextField name = new JTextField();
private JTextField dor = new JTextField();
private JTextField address = new JTextField();
private JTextField sex = new JTextField();
private JTextField date = new JTextField();
private JTextField pol = new JTextField();
private JTextField phone = new JTextField();
private JTextArea show = new JTextArea(16, 30);
private JLabel lab1 = new JLabel("姓名:");// 标签
private JLabel lab2 = new JLabel("学院:");
private JLabel num = new JLabel("学号:");
private JLabel lab4 = new JLabel("性别:");
private JLabel lab5 =