JAVA课程设计:学生成绩管理系统(第一部分)

JAVA课程设计:学生成绩管理系统

  • 首先我先设计了一个管理员登陆界面,并实现了登陆的相关Demo。
package windowuser;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

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

public class WindowUser	extends JFrame {
	public static void main(String[] args) {
	  new WindowUser();
}
	public WindowUser(){
		this.setSize(300,290);
		this.setTitle("登陆界面");
		this.setLocation(500,500);
		JLabel jl1 = new JLabel("用户名");
		JLabel jl2 = new JLabel("密     码");
		JTextField jt = new JTextField(15);			//实例化用户名框
		JPasswordField jp = new JPasswordField(15); //实例化密码框
		jp.setEchoChar('*'); //密码以**显示
		JButton jb1 = new JButton("登陆");
		JButton jb2 = new JButton("退出");
		this.setVisible(true);
		JPanel m= new JPanel();  //获取一个容器
		m.add(jl1);
		m.add(jl2);
		m.add(jt);
		m.add(jp);
		m.add(jb1);
		m.add(jb2);
		m.setBounds(300, 300, 300, 290);
		m.setLayout(null);
		jl1.setBounds(10, 40, 50, 18);
		jl2.setBounds(10, 80, 50, 18);
		jt.setBounds(60, 40, 200, 18);
		jp.setBounds(60, 80, 200, 18);
		jb1.setBounds(80, 180, 60, 30);
		jb2.setBounds(150, 180, 60, 30);
		this.add(m);
		
		//进入学生管理系统界面
		jb1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
			if(jt.getText().trim().equals("admin")&&new String(jp.getPassword()).equals("123456")){
				JOptionPane.showMessageDialog(null, "登陆成功","消息",JOptionPane.INFORMATION_MESSAGE);
				dispose();
				new  View();
			}else{
				JOptionPane.showMessageDialog(null, "登陆失败","消息",JOptionPane.ERROR_MESSAGE);
				//置输入框内容为空 	
				jt.setText("");
				jp.setText("");
			}
			}
		});
		jb2.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
		//对文本框进行监听 
		KeyListener key = new KeyListener() {

			public void keyTyped(KeyEvent e) {}		
			public void keyReleased(KeyEvent e) {}
			public void keyPressed(KeyEvent e) {
				if(e.getKeyChar()==KeyEvent.VK_ENTER){
					if(jt.getText().trim().equals("admin")&&new String(jp.getPassword()).equals("123456")){
					JOptionPane.showMessageDialog(null,"登陆成功","消息",JOptionPane.INFORMATION_MESSAGE);
					new  View();
					}
				}else if(e.getKeyChar()==KeyEvent.VK_ESCAPE){
					JOptionPane.showConfirmDialog(null, "是否退出","消息",JOptionPane.YES_NO_OPTION);
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e1) {
						e1.printStackTrace();
					}
					System.exit(-1);
				}
				
			}
		};
		//添加监听器
		jt.addKeyListener(key);
		jp.addKeyListener(key);
	}
}

**
2.主程序管理界面的设计
在这里插入图片描述


```java
package llxy.project.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.nio.channels.SelectableChannel;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import llxy.project.Tools.GuiTools;
import llxy.project.play.SelectStuMessage;


```java
public  class StuGradeWindow extends JFrame{
	public static void main(String[] args) {
		new StuGradeWindow();
}
	 public StuGradeWindow(){
		 this.setSize(622,470);
		 //this.setLocation(300, 200);
		 this.setVisible(true);
		 this.setTitle("学生管理系统");
		 this.setResizable(false);   //窗口大小固定
		 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		 //背景图片
			JPanel bg =new JPanel();
			ImageIcon img = new ImageIcon("ppp.png");
			JLabel j1 =new JLabel(img);
			j1.setBounds(0, 0,img.getIconHeight(), img.getIconWidth());
			bg.add(j1);
			this.add(bg, BorderLayout.NORTH);
		 JPanel panel = new JPanel(); //创建一个面板 存储组件
		 JButton btn1 = new JButton("1.查询学生信息");
		 JButton btn2 = new JButton("2.学生成绩排序");
		 JButton btn3 = new JButton("3.学生信息管理");
		 JButton btn4 = new JButton("4.其他查询");
		 JButton btn5 = new JButton("     退出        ");

		 panel.add(btn1);
		 btn1.setBackground(Color.GREEN);
		 panel.add(btn2);
		 btn2.setBackground(Color.green);
		 panel.add(btn3);
		 btn3.setBackground(Color.green);
		 panel.add(btn4);
		 btn4.setBackground(Color.green);
		 panel.add(btn5);
		 btn5.setBackground(Color.green);
		 panel.setBackground(Color.lightGray);
		 this.add(panel,BorderLayout.SOUTH);
		 GuiTools.center(this);
		 GuiTools.setTitleImage(this,"1.jpg");
		 //btn1
		 btn1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {  
			SelectStuMessage sel =	new SelectStuMessage();
				 
				
			}
		});
		 //
		 btn2.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
			
				
			}
		});
		 //
		 btn3.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				
				
			}
		});
		 //
		 btn4.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				
				
			}
		});
		 
		 //
		 btn5.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				 System.exit(0);
				
			}
		});
	
	 }
	
}

目前实现了以上界面的设计,在其中学习到了许多的知识点。
1.对于密码的隐私处理:使用password.setEchoChar(’’); 让密码部分变成*****
2.JOptionPane.showMessageDialog:消息框

四种消息提示框方法

showConfirmDialog():确认对话框
showInputDialog():输入对话框
showMessageDialog():消息对话框
showOptionDialog():选择对话框

五种消息类型(图标的种类):

ERROR_MESSAGE:错误
INFORMATION_MESSAGE:普通
WARNING_MESSAGE:警告
QUESTION_MESSAGE:问
PLAIN_MESSAGE:无图标

对了,还有工具类让GUI界面居中,而且为他添加title的图标。

package llxy.project.Tools;
/**
 * GUI工具类
 */
import java.awt.Component;
import java.awt.Toolkit;

import javax.swing.JFrame;

public class GuiTools {
	static Toolkit kit = Toolkit.getDefaultToolkit();
	//居中
	public static void center(Component c){
		int x = (kit.getScreenSize().width-c.getWidth())/2;
		int y = (kit.getScreenSize().height-c.getHeight())/2;
		c.setLocation(x, y);
	}
	//指定窗口设置图标标题
	public static void setTitleImage(JFrame frame,String titleIconPath){
		frame.setIconImage(kit.createImage(titleIconPath));
	}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值