Java實現學生信息管理界面

本文實例為大傢分享瞭Java實現學生信息管理界面的具體代碼,供大傢參考,具體內容如下

主類

package 學生信息管理系統;
 
public class Main {
 public static void main(String[] args) {
  // TODO 自動生成的方法存根
  InterFace Menu=new InterFace();
  Menu.menu();
 }
}

添加信息

package 學生信息管理系統;
 
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.Scanner;
 
public class Add {
 static Stu[] stu=new Stu[100];
 static Scanner scanner=new Scanner(System.in);
 static  int number=0;
 static InterFace Inter=new InterFace();
 public void add() {
  while(true) {
   try {
    clear();
   } catch (AWTException e) {
    // TODO 自動生成的 catch 塊
    e.printStackTrace();
   }
   System.out.println("請輸入即將錄入的人數:");
   int N=scanner.nextInt();
   for(int i=0;i<N;i++) {
    stu[number]=new Stu();
    System.out.println("請輸入第"+(i+1)+"個學生的信息:");
    System.out.println("請輸入學號:");
    stu[number].setNum(scanner.next());
    System.out.println("請輸入姓名:");
    stu[number].setName(scanner.next());
    System.out.println("請輸入性別:");
    stu[number].setSex(scanner.next());
    System.out.println("請輸入年齡:");
    stu[number].setAge(scanner.nextInt());
    System.out.println("請輸入語文成績:");
    stu[number].setChinese(scanner.nextFloat());
    System.out.println("請輸入數學成績:");
    stu[number].setMath(scanner.nextFloat());
    System.out.println("請輸入英語成績:");
    stu[number].setEng(scanner.nextFloat());
    number++;
   }
   System.out.println("錄入完畢,即將返回!");
   Inter.menu();
  }
 }
 
 //實現控制臺清屏
 @SuppressWarnings("deprecation")
 public static void clear() throws AWTException
    {
        Robot r = new Robot();
        r.mousePress(InputEvent.BUTTON3_MASK);       // 按下鼠標右鍵
        r.mouseRelease(InputEvent.BUTTON3_MASK);    // 釋放鼠標右鍵
        r.keyPress(KeyEvent.VK_CONTROL);             // 按下Ctrl鍵
        r.keyPress(KeyEvent.VK_R);                    // 按下R鍵
        r.keyRelease(KeyEvent.VK_R);                  // 釋放R鍵
        r.keyRelease(KeyEvent.VK_CONTROL);            // 釋放Ctrl鍵
        r.delay(100);       
    }
}

主界面

package 學生信息管理系統;
 
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.*;
 
public class InterFace {
 static Scanner scanner=new Scanner(System.in);
 
 public void menu(){
  int select;
  try {
   clear();
  } catch (AWTException e) {
   // TODO 自動生成的 catch 塊
   e.printStackTrace();
  }
  do{
  System.out.println("\t\t      歡迎使用學生信息管理系統\n");
  System.out.println("\t\t ***  ╭ □═■═□═■═□ ══╮***\n");  
  System.out.println("\t\t *    │    學生信息管理系統    │  *\n");  
  System.out.println("\t\t *    ╰═══■═□═■═□═■╯  *\n");  
  System.out.println("\t\t *    ┌───────────┐    *\n");  
  System.out.println("\t\t *    │1.添加信息  2.加載信息│    *\n");  
  System.out.println("\t\t *    │                      │    *\n");  
  System.out.println("\t\t *    │3.查詢信息  4.文件操作│    *\n");  
  System.out.println("\t\t *    │                      │    *\n");  
  System.out.println("\t\t *    │5.數據排序  6.修改信息│    *\n");  
  System.out.println("\t\t *    │                      │    *\n");  
  System.out.println("\t\t *    │7.顯示信息  8.刪除信息│    *\n");
  System.out.println("\t\t *    │                      │    *\n");
  System.out.println("\t\t *    │9.保存信息  0.退出系統│    *\n");
  System.out.println("\t\t *    └───────────┘    *\n");  
  System.out.println("\t\t ************************************\n"); 
  System.out.println();
  System.out.println("\t請選擇操作方式(1~8):\n");
  select=scanner.nextInt();
  switch(select){
  case 8:
   
   break;
  case 5:
   
   break;
  case 4:
   
   break;
  case 3:
   
   break;
  case 2:
   
   break;
  case 9:
   
   break;
  case 7:
   Show show=new Show();
   show.show();
   break;
  case 1:
   Add operate=new Add();
   operate.add();
   break;
  case 0:
   
   break;
  default:
   try {
    clear();
   } catch (AWTException e) {
    // TODO 自動生成的 catch 塊
    e.printStackTrace();
   }
   this.menu();
  }
  }while(select!=8);
 }
 @SuppressWarnings("deprecation")
 public static void clear() throws AWTException
    {
        Robot r = new Robot();
        r.mousePress(InputEvent.BUTTON3_MASK);       // 按下鼠標右鍵
        r.mouseRelease(InputEvent.BUTTON3_MASK);    // 釋放鼠標右鍵
        r.keyPress(KeyEvent.VK_CONTROL);             // 按下Ctrl鍵
        r.keyPress(KeyEvent.VK_R);                    // 按下R鍵
        r.keyRelease(KeyEvent.VK_R);                  // 釋放R鍵
        r.keyRelease(KeyEvent.VK_CONTROL);            // 釋放Ctrl鍵
        r.delay(100);       
    }
}

顯示信息

package 學生信息管理系統;
 
import java.util.Scanner; 
 
public class Show {
 int n = Add.number;
 static Scanner scanner=new Scanner(System.in);
 public void show() {
  System.out.println("**********************************************************");
  System.out.println("學號        姓名 性別 年齡 語文 數學 英語");
  for (int i = 0; i < n; i++)
   System.out.println(Add.stu[i].getNum() + " " +Add.stu[i].getName()+" "+ Add.stu[i].getSex() + " " + Add.stu[i].getAge() + " "
     + Add.stu[i].getChinese() + " " + Add.stu[i].getMath() + " " + Add.stu[i].getEng());
  System.out.println("**********************************************************");
  System.out.println();
  //n為毫秒數
  try { Thread.sleep (100000) ; 
  } catch (InterruptedException ie){}
 }
}

學生類

package 學生信息管理系統;
 
public class Stu {
 private String num;
 private String name;
 private String sex;
 private int age;
 private float chinese;
 private float math;
 private float eng;
 public String getNum() {
  return num;
 }
 public void setNum(String num) {
  this.num = num;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getSex() {
  return sex;
 }
 public void setSex(String sex) {
  this.sex = sex;
 }
 public int getAge() {
  return age;
 }
 public void setAge(int age) {
  this.age = age;
 }
 public float getChinese() {
  return chinese;
 }
 public void setChinese(float chinese) {
  this.chinese = chinese;
 }
 public float getMath() {
  return math;
 }
 public void setMath(float math) {
  this.math = math;
 }
 public float getEng() {
  return eng;
 }
 public void setEng(float eng) {
  this.eng = eng;
 }
}

以上就是本文的全部內容,希望對大傢的學習有所幫助,也希望大傢多多支持WalkonNet。

推薦閱讀: