国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Java > 正文

Java GUI實現學生成績管理系統

2024-07-13 10:16:48
字體:
來源:轉載
供稿:網友

學習java有一年多了,一直在做web方面的練習,在一個項目中發現需要用到GUI的相關知識,結果沒法做出來,網上這方面的文章又不是很多,所有只好自己硬著頭皮從頭再學一遍了,不過學習后發現,其實GUI是非常有趣的,他并不像WEB程序一樣依賴互聯網,而且還有許多布局和android相差不是很大,這才發現自己竟又愛上GUI的開發了,不多說了,直接上代碼吧,相信有過android或相關界面開發的都明白這其中的道理。

先看看效果吧

Java,學生管理系統,Java成績管理系統,學生成績管理系統,GUI學生成績管理系統Java,學生管理系統,Java成績管理系統,學生成績管理系統,GUI學生成績管理系統Java,學生管理系統,Java成績管理系統,學生成績管理系統,GUI學生成績管理系統

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);  }  } 

這樣就能輕松實現登錄驗證了,本打算從數據庫讀取數據的,由于時間關系,這里就簡單的直接驗證了,后續有時間的話再做其他的部分。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到JAVA教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 苏尼特左旗| 登封市| 安新县| 平昌县| 聊城市| 威海市| 武夷山市| 天长市| 安图县| 罗田县| 翁牛特旗| 抚州市| 离岛区| 乌拉特前旗| 大姚县| 大同市| 金山区| 罗甸县| 区。| 麻江县| 南郑县| 巴东县| 涞水县| 长葛市| 兴山县| 湖南省| 陆川县| 绥江县| 祥云县| 金堂县| 工布江达县| 友谊县| 洛宁县| 清水河县| 连云港市| 金山区| 大同市| 调兵山市| 通许县| 厦门市| 厦门市|