Java GUI实现学生成绩管理系统

 更新时间:2018年01月16日 11:26:12   作者:只要你能好  
这篇文章主要为大家详细介绍了Java GUI实现学生成绩管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud

(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

学习java有一年多了,一直在做web方面的练习,在一个项目中发现需要用到GUI的相关知识,结果没法做出来,网上这方面的文章又不是很多,所有只好自己硬着头皮从头再学一遍了,不过学习后发现,其实GUI是非常有趣的,他并不像WEB程序一样依赖互联网,而且还有许多布局和android相差不是很大,这才发现自己竟又爱上GUI的开发了,不多说了,直接上代码吧,相信有过android或相关界面开发的都明白这其中的道理。

先看看效果吧

1.登录主界面

package edu.gzu.stuManager; 
 
import java.awt.EventQueue; 
 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JOptionPane; 
 
import java.awt.Toolkit; 
 
import javax.swing.JTextField; 
 
import edu.gzu.stuManager.Dao.UserLoginValid; 
import edu.gzu.stuManager.Domain.StudentInfo; 
import edu.gzu.stuManager.View.StudentMainView; 
 
import java.awt.Choice; 
import java.awt.Font; 
import java.awt.Button; 
import java.awt.event.MouseAdapter; 
import java.awt.event.MouseEvent; 
 
public class MainUI { 
 
 private JFrame frame; 
 private JTextField textField; 
 private JTextField textField_1; 
 
 /** 
 * Launch the application. 
 */ 
 public static void main(String[] args) { 
 EventQueue.invokeLater(new Runnable() { 
 public void run() { 
 try { 
  MainUI window = new MainUI(); 
  window.frame.setVisible(true); 
 } catch (Exception e) { 
  e.printStackTrace(); 
 } 
 } 
 }); 
 } 
 
 /** 
 * Create the application. 
 */ 
 public MainUI() { 
 initialize(); 
 } 
 
 /** 
 * Initialize the contents of the frame. 
 */ 
 private void initialize() { 
 frame = new JFrame(); 
 frame.setTitle("\u6210\u7EE9\u7BA1\u7406\u7CFB\u7EDF\uFF08\u767B\u5F55\uFF09"); 
 frame.setIconImage(Toolkit.getDefaultToolkit().getImage(MainUI.class.getResource("/image/func_list7_privmana.png"))); 
 frame.setBounds(400, 250, 450, 300); 
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
 frame.getContentPane().setLayout(null); 
 
 JLabel lblNewLabel = new JLabel("\u5B66\u751F\u6210\u7EE9\u7BA1\u7406\u7CFB\u7EDF\u7528\u6237\u767B\u5F55\uFF01"); 
 lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 16)); 
 lblNewLabel.setBounds(111, 17, 287, 15); 
 frame.getContentPane().add(lblNewLabel); 
 
 JLabel lblNewLabel_1 = new JLabel("\u7528\u6237\u540D\uFF1A"); 
 lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 14)); 
 lblNewLabel_1.setBounds(87, 67, 67, 15); 
 frame.getContentPane().add(lblNewLabel_1); 
 
 textField = new JTextField(); 
 textField.setBounds(154, 64, 141, 21); 
 frame.getContentPane().add(textField); 
 textField.setColumns(10); 
 
 JLabel label = new JLabel("\u5BC6 \u7801\uFF1A"); 
 label.setFont(new Font("宋体", Font.PLAIN, 14)); 
 label.setBounds(87, 108, 67, 15); 
 frame.getContentPane().add(label); 
 
 textField_1 = new JTextField(); 
 textField_1.setColumns(10); 
 textField_1.setBounds(154, 103, 141, 21); 
 frame.getContentPane().add(textField_1); 
 
 JLabel lblNewLabel_2 = new JLabel("\u6211\u7684\u8EAB\u4EFD\u662F\uFF1A"); 
 lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 14)); 
 lblNewLabel_2.setBounds(105, 150, 97, 15); 
 frame.getContentPane().add(lblNewLabel_2); 
 
 final Choice choice = new Choice(); 
 choice.setBounds(210, 147, 74, 21); 
 choice.add("学生"); 
 choice.add("教师"); 
 choice.add("系统管理员"); 
 frame.getContentPane().add(choice); 
 
 Button button = new Button("\u767B\u5F55"); 
 button.setBounds(87, 194, 76, 23); 
 button.addMouseListener(new MouseAdapter() { 
 @Override 
 public void mouseClicked(MouseEvent e) { 
 String user=textField.getText(); 
 String password=textField_1.getText(); 
 String shenfen=choice.getSelectedItem(); 
 if(user.equals("")||user==null){ 
  JOptionPane.showMessageDialog(frame, shenfen+":您好,帐号不能为空!"); 
  return; 
 }else if(password.equals("")||password==null){ 
  JOptionPane.showMessageDialog(frame, shenfen+":您好,密码不能为空!"); 
  return; 
 }else{ 
  StudentInfo stu=new StudentInfo(Integer.parseInt(user), 
  Integer.parseInt(password),shenfen); 
  UserLoginValid dao=new UserLoginValid(); 
  String result=dao.isValid(stu); 
  
  if("登录成功!".equals(result)){ 
  JOptionPane.showMessageDialog(frame,result); 
  StudentMainView index=new StudentMainView(stu); 
  JFrame frame2=index.getFrame(); 
  frame2.setVisible(true); 
  frame.dispose(); 
  }else{ 
  JOptionPane.showMessageDialog(frame,result); 
  } 
  
 } 
 } 
 }); 
 frame.getContentPane().add(button); 
 
 Button button_1 = new Button("\u53D6\u6D88"); 
 button_1.setBounds(219, 194, 76, 23); 
 frame.getContentPane().add(button_1); 
 
 
 } 
 
} 

2.登录验证逻辑

package edu.gzu.stuManager.Dao; 
 
import edu.gzu.stuManager.Domain.StudentInfo; 
 
public class UserLoginValid { 
 
 public String isValid(StudentInfo stu){ 
 int idnum=stu.getIdnum(); 
 int password=stu.getPassword(); 
 String idntify=stu.getIdentify(); 
 String result=null; 
 
 if("学生".equals(idntify)){ 
 if(idnum==1207010209&&password==123){ 
 stu.setName("刘明胜 同学"); 
 result="登录成功!"; 
 }else{ 
 result="学生帐号中不存在此用户,请确认身份后再次登录!"; 
 } 
 }else if("教师".equals(idntify)){ 
 if(idnum==1174386356&&password==123){ 
 stu.setName("刘明胜 老师"); 
 result="登录成功!"; 
 }else{ 
 result="教师帐号中不存在此用户,请确认身份后再次登录!"; 
 } 
 }else if("系统管理员".equals(idntify)){ 
 if(idnum==999999&&password==123){ 
 stu.setName("系统管理员"); 
 result="登录成功!"; 
 }else{ 
 result="系统管理员帐号中不存在此用户,请确认身份后再次登录!"; 
 } 
 } 
 
 
 return result; 
 } 
} 

3.用户对象(这是一个简单bean)

package edu.gzu.stuManager.Domain; 
 
public class StudentInfo { 
 private int idnum; 
 private String name; 
 private int password; 
 private String identify; 
 
 public StudentInfo(int idnum,int password, String identify) { 
 super(); 
 this.idnum = idnum; 
 this.password = password; 
 this.identify = identify; 
 } 
 public int getIdnum() { 
 return idnum; 
 } 
 public void setIdnum(int idnum) { 
 this.idnum = idnum; 
 } 
 public String getName() { 
 return name; 
 } 
 public void setName(String name) { 
 this.name = name; 
 } 
 public int getPassword() { 
 return password; 
 } 
 public void setPassword(int password) { 
 this.password = password; 
 } 
 public String getIdentify() { 
 return identify; 
 } 
 public void setIdentify(String identify) { 
 this.identify = identify; 
 } 
 
 
} 

4.登录成功后的主界面

package edu.gzu.stuManager.View; 
 
import java.awt.Button; 
import java.awt.Canvas; 
import java.awt.Choice; 
import java.awt.Color; 
import java.awt.Toolkit; 
import java.awt.event.ItemEvent; 
import java.awt.event.ItemListener; 
 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JOptionPane; 
import javax.swing.JPanel; 
import javax.swing.JTextField; 
 
import edu.gzu.stuManager.Domain.StudentInfo; 
 
public class StudentMainView{ 
 private JFrame frame; 
 private JTextField textField; 
 private JTextField textField_1; 
 private JTextField textField_2; 
 private JTextField textField_3; 
 
 private StudentInfo info; 
 
 /** 
 * Create the frame. 
 * @wbp.parser.entryPoint 
 */ 
 public StudentMainView(StudentInfo info) { 
 this.info=info; 
 } 
 
 public JFrame getFrame(){ 
 initialize(); 
 return frame; 
 } 
 
 /** 
 * Initialize the contents of the frame. 
 * @wbp.parser.entryPoint 
 */ 
 public void initialize() { 
 frame = new JFrame(); 
 frame.setTitle("\u6210\u7EE9\u7BA1\u7406\u7CFB\u7EDF\uFF08\u5B66\u751F\u7248\uFF09"); 
 frame.setIconImage(Toolkit.getDefaultToolkit().getImage(StudentMainView.class.getResource("/image/func_list7_privmana.png"))); 
 frame.setBounds(300,150, 550, 300); 
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
 frame.getContentPane().setLayout(null); 
 
 JLabel lblNewLabel = new JLabel("欢迎【"+info.getName()+"】登录学生成绩管理系统!"); 
 lblNewLabel.setBounds(54, 10, 322, 15); 
 frame.getContentPane().add(lblNewLabel); 
 
 JPanel panel = new JPanel(); 
 panel.setBounds(29, 52, 250, 180); 
 frame.getContentPane().add(panel); 
 panel.setLayout(null); 
 
 JLabel lblNewLabel_1 = new JLabel("\u6210\u7EE9\u6570\u636E"); 
 lblNewLabel_1.setBounds(94, 10, 65, 15); 
 panel.add(lblNewLabel_1); 
 
 JLabel lblNewLabel_2 = new JLabel("\u5B66\u53F7\uFF1A"); 
 lblNewLabel_2.setBounds(22, 37, 40, 15); 
 panel.add(lblNewLabel_2); 
 
 textField = new JTextField(); 
 textField.setBounds(72, 35, 154, 21); 
 textField.setText(info.getIdnum()+""); 
 panel.add(textField); 
 textField.setColumns(10); 
 
 JLabel lblNewLabel_3 = new JLabel("\u59D3\u540D\uFF1A"); 
 lblNewLabel_3.setBounds(22, 67, 44, 15); 
 panel.add(lblNewLabel_3); 
 
 textField_1 = new JTextField(); 
 textField_1.setBounds(72, 66, 154, 21); 
 textField_1.setText(info.getName()); 
 panel.add(textField_1); 
 textField_1.setColumns(10); 
 
 Canvas canvas = new Canvas(); 
 canvas.setBackground(Color.BLUE); 
 canvas.setBounds(22, 100, 205, 1); 
 panel.add(canvas); 
 
 JLabel lblNewLabel_4 = new JLabel("\u8BFE\u7A0B\u540D"); 
 lblNewLabel_4.setBounds(22, 116, 47, 15); 
 panel.add(lblNewLabel_4); 
 
 JLabel lblNewLabel_5 = new JLabel("\u6210\u7EE9"); 
 lblNewLabel_5.setBounds(160, 116, 43, 15); 
 panel.add(lblNewLabel_5); 
 
 textField_2 = new JTextField(); 
 textField_2.setBounds(22, 140, 123, 21); 
 panel.add(textField_2); 
 textField_2.setColumns(10); 
 
 textField_3 = new JTextField(); 
 textField_3.setBounds(159, 140, 66, 21); 
 panel.add(textField_3); 
 textField_3.setColumns(10); 
 
 JPanel panel_1 = new JPanel(); 
 panel_1.setBounds(317, 52, 110, 180); 
 frame.getContentPane().add(panel_1); 
 panel_1.setLayout(null); 
 
 JLabel lblNewLabel_6 = new JLabel("\u64CD\u4F5C\u83DC\u5355"); 
 lblNewLabel_6.setBounds(15, 10, 54, 15); 
 panel_1.add(lblNewLabel_6); 
 
 Button button = new Button("\u7B2C\u4E00\u95E8\u8BFE\u7A0B"); 
 button.setBounds(10, 31, 76, 23); 
 panel_1.add(button); 
 
 Button button_1 = new Button("\u4E0B\u4E00\u95E8\u8BFE\u7A0B"); 
 button_1.setBounds(10, 61, 76, 23); 
 panel_1.add(button_1); 
 
 Button button_2 = new Button("\u4E0A\u4E00\u95E8\u8BFE\u7A0B"); 
 button_2.setActionCommand("\u4E0A\u4E00\u95E8\u8BFE\u7A0B"); 
 button_2.setBounds(10, 90, 76, 23); 
 panel_1.add(button_2); 
 
 Button button_3 = new Button("\u6700\u540E\u4E00\u95E8\u8BFE"); 
 button_3.setBounds(10, 117, 76, 23); 
 panel_1.add(button_3); 
 
 Choice choice = new Choice(); 
 choice.setBounds(10, 149, 76, 21); 
 choice.add("选择课程"); 
 choice.add("高等数学"); 
 choice.add("大学英语"); 
 choice.add("马列主义"); 
 choice.add("毛泽东思想"); 
 choice.add("计算机图形学"); 
 choice.addItemListener(new ItemListener() { 
 
 @Override 
 public void itemStateChanged(ItemEvent e) { 
 Object[] objs=e.getItemSelectable().getSelectedObjects(); 
 for(Object ob:objs){ 
//  JOptionPane.showMessageDialog(frame, ob.toString()); 
  if("高等数学".equals(ob.toString())){ 
  textField_2.setText("高等数学"); 
  textField_3.setText("98"); 
  }else if("大学英语".equals(ob.toString())){ 
  textField_2.setText("大学英语"); 
  textField_3.setText("87"); 
  }else if("马列主义".equals(ob.toString())){ 
  textField_2.setText("马列主义"); 
  textField_3.setText("88"); 
  }else if("毛泽东思想".equals(ob.toString())){ 
  textField_2.setText("毛泽东思想"); 
  textField_3.setText("73"); 
  }else if("计算机图形学".equals(ob.toString())){ 
  textField_2.setText("计算机图形学"); 
  textField_3.setText("97"); 
  } 
 } 
  
  
 } 
 }); 
 
 panel_1.add(choice); 
 } 
 
} 

这样就能轻松实现登录验证了,本打算从数据库读取数据的,由于时间关系,这里就简单的直接验证了,后续有时间的话再做其他的部分。

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持程序员之家。

相关文章

  • 聊聊finally中的代码一定会执行吗

    聊聊finally中的代码一定会执行吗

    通常在面试中,只要是疑问句一般答案都是“否定”的,因为如果是“确定”和“正常”的,那面试官就没有必要再问了嘛,本文想和大家聊聊finally中的代码一定会执行吗?,感兴趣的朋友跟着小编一起来看看吧
    2023-12-12
  • java简单工厂模式入门

    java简单工厂模式入门

    下面小编就为大家带来一篇java工厂模式入门文章。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2021-07-07
  • springboot以FTP方式上传文件到远程服务器

    springboot以FTP方式上传文件到远程服务器

    这篇文章主要介绍了springboot以FTP方式上传文件到远程服务器,需要的朋友可以参考下
    2019-12-12
  • HttpClient详细使用示例详解

    HttpClient详细使用示例详解

    这篇文章主要介绍了HttpClient详细使用示例详解,本文给大家介绍的非常想详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-01-01
  • 详解HTTP请求与响应基础及实例

    详解HTTP请求与响应基础及实例

    这篇文章主要介绍了详解HTTP请求与响应基础及实例的相关资料,这里对http的请求和响应进行详细分析并附有实现实例,需要的朋友可以参考下
    2017-07-07
  • Fluent Mybatis快速入门详细教程

    Fluent Mybatis快速入门详细教程

    由于FluentMybatis是基于mybatis上做封装和扩展的,所以这里主要聊聊mybatis处理的方式,以及给出FluentMybatis的解放方案。对Fluent Mybatis入门相关知识感兴趣的朋友一起看看吧
    2021-08-08
  • Java实现简易扑克牌游戏的完整实例

    Java实现简易扑克牌游戏的完整实例

    这篇文章主要介绍了Java实现简易扑克牌游戏的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-04-04
  • JDK15正式发布(新增功能预览)

    JDK15正式发布(新增功能预览)

    这篇文章主要介绍了JDK15正式发布,新增功能预览,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2020-09-09
  • Java值得使用Lambda的8个场景合集

    Java值得使用Lambda的8个场景合集

    可能对不少人来说,Lambda显得陌生又复杂,觉得Lambda会导致代码可读性下降,但毕竟2023年了,JDK都出了那么多新版本,是时候试试Lambda了
    2023-08-08
  • Java的PriorityBlockingQueue优先级阻塞队列代码实例

    Java的PriorityBlockingQueue优先级阻塞队列代码实例

    这篇文章主要介绍了Java的PriorityBlockingQueue优先级阻塞队列代码实例,PriorityBlockingQueue顾名思义是带有优先级的阻塞队列,为了实现按优先级弹出数据,存入其中的对象必须实现comparable接口自定义排序方法,需要的朋友可以参考下
    2023-12-12

最新评论

?


http://www.vxiaotou.com