2020.06.01学生管理系统

学生管理系统
首先创建六个界面
1、 帮助界面
package com.imau.view;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import com.imau.base.BaseFrame;
public class HelpView extends BaseFrame {
private JTextArea ldoc;
private JScrollPane pane;
private String doc=" 帮助内容……";
private void init() {
ldoc=new JTextArea(doc,4,4);
pane=new JScrollPane(ldoc);
this.add(pane);
}
public HelpView() {
this.setJMenuBar(initMenu());
init();
setFrame();
}
2、 }
2、登录界面
package com.imau.view;
import java.awt.;
import java.awt.event.
;
import javax.swing.*;
import com.imau.base.BaseFrame;
import com.imau.controller.UserController;
public class LoginView extends BaseFrame {
//请求
private UserController controller;
private JLabel lname;
private JLabel lpass;
private JTextField tname;
private JPasswordField tpass;//密文显示密码
private JButton login;
private void initEvnet() {
login.addActionListener(new MyListener());
}
private void init() {
lname=new JLabel(“用户名”);
lpass=new JLabel(“密 码”);
tname=new JTextField(14);
tpass=new JPasswordField(14);
login=new JButton(“登录”);

  initEvnet();
  
  this.setLayout(new FlowLayout(FlowLayout.CENTER));
  this.add(lname);
  this.add(tname);
  this.add(lpass);
  this.add(tpass);
  this.add(login);
  
    Dimension dim=getToolkit().getScreenSize() ;//获取屏幕大小
  
    int w=dim.width/2;
	int h=dim.height/2;
    this.setResizable(false);//不能更改窗口大小
    this.setTitle("用户登录");
	this.setSize(255, 125);
	this.setLocation(w-255/2, h-125/2);//屏幕中心位置        
    
    this.setVisible(true);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

        public LoginView() {
              init();
              controller=new UserController();
           }
        
        public void close() {
        	this.setVisible(false);
        }
        
        //最常用的方法是内部类
 public class MyListener implements ActionListener{
   //多个按钮可以使用e.getSource()方法判断
	@Override
	public void actionPerformed(ActionEvent e) {
		String uname=tname.getText();
		String upass=tpass.getText();
		
		//检查用户名密码
		if(controller.login(uname, upass)) {
			
			//保存用户信息
			controller.saveUserInfo(uname, upass);
			
			//关闭当前页面
			dispose();
			//打开主界面
			new MainView();
		}else {
			System.out.println("用户名密码错误");
		}
		
	}
	 
 }

}

3、主界面
package com.imau.view;

import javax.swing.*;
import javax.swing.JMenuBar;

import com.imau.base.BaseFrame;
//系统主界面:
public class MainView extends BaseFrame{
private JLabel label;

public MainView() {
	label=new JLabel("欢迎使用学生管理系统!!",JLabel.CENTER);
	this.add(label);
	this.setJMenuBar(initMenu());
	setFrame();
}

}
4、添加界面
package com.imau.view;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import com.imau.base.BaseFrame;
import com.imau.base.BaseFrame.MyListener;

//id ,name,sex,age,image,民族
public class StudentAddView extends BaseFrame {
//定义需要的组件
private JLabel lid;
private JLabel lname;
private JLabel lsex;
private JLabel lage;
private JLabel limage;
private JLabel lnation;

private JTextField tid;
private JTextField tname;
private JTextField tsex;
private JTextField tage;
private JTextField timage;
private JTextField tnation;

private JButton submit,cancel;

//构造方法
public StudentAddView() {
	this.setJMenuBar(initMenu());
	init();
	setFrame();
	
	
}

private void init() {
      lid=new JLabel("ID");
	  lname=new JLabel("姓名");
	  lsex=new JLabel("性别");
	  lage=new JLabel("年龄");
      limage=new JLabel("头像");
	  lnation=new JLabel("名族");
	  
	  tid=new JTextField(10);
	  tname=new JTextField(10);
	  tsex=new JTextField(10);
	  tage=new JTextField(10);
	  
      timage=new JTextField(10);
	  tnation=new JTextField(10);
	  
	  submit=new JButton("添加");
	  cancel=new JButton("取消");
	  //添加事件
	  addEvent();
	  //设置布局,添加组件
	  setLayout(new GridLayout(7,2));
	  this.add(lid);
	  this.add(tid);
	  
	  this.add(lname);
	  this.add(tname);

	  this.add(lnation);
	  this.add(tnation);
	  
	  this.add(lsex);
	  this.add(tsex);
	  
	  this.add(lage);
	  this.add(tage);
	  
	  this.add(limage);
	  this.add(timage);
	  
	  this.add(submit);
	  this.add(cancel);
	
}
//事件
  private void addEvent() {
	  submit.addActionListener(new MyListener());
	  cancel.addActionListener(new MyListener());
  }

//内部监听
class MyListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
	}
}

}

5、学生列表界面

package com.imau.view;

import java.awt.BorderLayout;

import javax.swing.*;
import com.imau.base.BaseFrame;

public class StudentListView extends BaseFrame{
//组件
//第一部分
//搜索框
private JTextField tsearch;
//搜索按钮
private JButton searchBtn;
//添加学生按钮
private JButton addStu;

//第二部分
//学生列表
private JTable table;
private String columnNames[]= {“序列”,“ID”,“姓名”,“学号”,“年龄”,“性别”,“民族”};
private Object rowData[][]= {
{“1”,“1”,“AAA”,“2018001”,23,“男”,“汉族”},
{“2”,“2”,“BBB”,“2018002”,23,“女”,“蒙族”},
{“3”,“3”,“CCC”,“2018003”,23,“男”,“蒙族”}
};
private JScrollPane scrollpane;

//第三部分
//首页,上一页,下一页,尾页,跳转按钮
private JButton homeBtn,upBtn,nextBtn,endBtn,jumpBtn;
//跳转输入框
private JTextField tjump;
//显示页面基本信息
private JLabel lpage;
//装载每一部分的组件
private JPanel panel,panel3;

public StudentListView() {
	this.setJMenuBar(initMenu());
	init();
	setFrame();
}

private void init() {
	tsearch=new JTextField("按照姓名查询",10);
	searchBtn=new JButton("搜索");
	addStu=new JButton("添加学生");
	
	table=new JTable(rowData,columnNames);
	scrollpane=new JScrollPane(table);
	
	homeBtn=new JButton("首页");
	upBtn=new JButton("上一页");
	nextBtn=new JButton("下一页");
	endBtn=new JButton("尾页");
	jumpBtn=new JButton("跳转");
	tjump=new JTextField(5);
	lpage=new JLabel("共5032条 11/420");
	
	panel=new JPanel();
	panel3=new JPanel();

	panel.add(tsearch);
	panel.add(searchBtn);
	panel.add(addStu);
	
	panel3.add(lpage);
	panel3.add(homeBtn);
	panel3.add(upBtn);
	panel3.add(nextBtn);
	panel3.add(endBtn);
	panel3.add(tjump);
	panel3.add(jumpBtn);
	
	this.add(panel,BorderLayout.NORTH);
	this.add(scrollpane,BorderLayout.CENTER);
	this.add(panel3,BorderLayout.SOUTH);

}

}

6、修改密码界面
package com.imau.view;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.imau.base.BaseFrame;
import com.imau.controller.UserController;
import com.imau.entry.User;
import com.imau.util.UserInfo;
import com.imau.view.LoginView.MyListener;

public class UserPassEditView extends BaseFrame{
private UserController controller;

private JLabel loldPass;
private JLabel lnewPass;
private JLabel lnewPassConfim;

private JPasswordField toldPass;
private JPasswordField tnewPass;
private JPasswordField tnewPassConfim;

private JPanel panel;

private JButton submit,cancel;

//构造方法
public UserPassEditView() {
controller=new UserController();
this.setJMenuBar(initMenu());
init();
setFrame();
}

private void init() {
	loldPass=new JLabel("旧密码");
	lnewPass=new JLabel("新密码");
	lnewPassConfim=new JLabel("确认新密码");
	
	toldPass=new JPasswordField(10);
    tnewPass=new JPasswordField(10);
	tnewPassConfim=new JPasswordField(10);
	
	submit=new JButton("确认");
	  cancel=new JButton("取消");
	  panel=new JPanel();
	 
	  panel.add(loldPass);
	  panel.add(toldPass);
	  
	  panel.add(lnewPass);
	  panel.add(tnewPass);

	  panel.add(lnewPassConfim);
	  panel.add(tnewPassConfim);
	
	  panel.add(submit);
	  panel.add(cancel);
	  this.add(panel);
}
private void initEvnet() {
	submit.addActionListener(new MyListener2());
	cancel.addActionListener(new MyListener2());
}

public class MyListener2 implements ActionListener{
    //多个按钮可以使用e.getSource()方法判断
	@Override
	public void actionPerformed(ActionEvent e) {
		String newpass=tnewPass.getText();
		String oldpass=toldPass.getText();
		String newPassConfim=tnewPassConfim.getText();
		//判断旧密码正确?
		
		if(!UserInfo.getUser().getUpass().equals(oldpass)) {
			System.out.println("旧密码输入不正确");
		}
		
		
		//新密码   确认密码 一致
	if(!newpass.equals(newPassConfim)) {
		System.out.println("两次密码输入不正确");
	}
	User user=UserInfo.getUser();
	user.setUpass(newpass);
		controller.editpass(user);
	}
 	 
  }

}

你可能感兴趣的:(Java,笔记)