最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java學(xué)生信息管理系統(tǒng)MVC架構(gòu)詳解

 更新時(shí)間:2017年11月14日 14:05:28   作者:那茲  
這篇文章主要為大家詳細(xì)介紹了java學(xué)生信息管理系統(tǒng)MVC架構(gòu)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java學(xué)生信息管理系統(tǒng)MVC架構(gòu),供大家參考,具體內(nèi)容如下

一、項(xiàng)目結(jié)構(gòu)

        學(xué)生信息管理系統(tǒng)分三層進(jìn)行實(shí)現(xiàn)。student.java主要提供數(shù)據(jù),cotroller.java的功能是綁定試圖和計(jì)算數(shù)據(jù)。Stuview.java用于單一的用來(lái)顯示數(shù)據(jù)。

二、源碼

1.1、Student 類

/* 
 * @FileName: Student.class 
 * @version:1.0 
 * @author:nazi 
 * 描述:模型層 
 * */ 
import java.io.Serializable; 
 
/* 
 * Summary: Student類實(shí)現(xiàn)序列化接口,用于對(duì)象的保存 
 * @author:nazi 
 * @version:1.0 
 * */ 
public class Student implements Serializable { 
  //序列化id 
  private static final long serialVersionUID = 9088453456517873574L; 
  int num; 
  String name; 
  String sex; 
  int age; 
  float grade; 
   
  public Student(int num ,String nameString,String sexString,int g,float f){ 
    this.num =num; 
    name = nameString; 
    sex =sexString; 
    age =g; 
    grade =f; 
  } 
   
   
  public int getNum(){ 
    return num; 
  } 
 
  public String getName(){ 
    return name; 
  } 
 
  public String getSex(){ 
    return sex; 
  } 
 
  public int getAge(){ 
    return age; 
  } 
 
  public float getGrades(){ 
    return grade; 
  } 
   
  public String toString(){ 
    return "姓名:"+name+"學(xué)號(hào):"+num+"性別:"+sex+"年齡:"+age+"成績(jī):"+grade; 
     
  } 
 
} 

1.2、Cotroller類

/* 
 * 文件名: Cotroller.java 
 * 描述:mvc中的c,用來(lái)管理模型層的數(shù)據(jù) 
 * @authur:Nazi 
 * function :增、刪、改、查、保存、更新 
 * */ 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.ObjectInputStream; 
import java.io.ObjectOutputStream; 
import java.util.ArrayList; 
import java.util.Iterator; 
 
 
/* 
 * Cotroller類集中對(duì)ArrayList<Student>進(jìn)行操作 
 * @Author nazi 
 * @version 1.0 
 * */ 
public class Cotroller { 
   
  //student數(shù)據(jù)集合 
  private ArrayList<Student> list; 
   
  public Cotroller(ArrayList<Student> l){ 
    this.list =l; 
  } 
   
  /* 
   * rturn a ArrayList<Student> 
   * */ 
  public ArrayList<Student> getList() 
  { 
    return list; 
  } 
   
  /* 
   * 初始化Student數(shù)組 
   * */ 
  public void setList(ArrayList<Student> list) 
  { 
    this.list = list; 
  } 
   
  /* 
   * add a student to the List 
   * */ 
  public void add(Student s) 
  { 
    list.add(s); 
  } 
   
  /* 
   * remove the student from list 
   * */ 
  public void remove(int id) 
  { 
    for(Iterator<Student> iter = list.iterator(); iter.hasNext();) 
    { 
      Student s = iter.next(); 
       
      if(s.getNum() == id) 
      { 
        list.remove(s); 
      } 
    } 
  } 
 
  /* 
   * print the specific student 
   * */ 
  public String printAll(int i) { 
     return list.get(i).toString(); 
  } 
   
  /* 
   * 功能簡(jiǎn)述:將實(shí)現(xiàn)序列化后的對(duì)象寫入到文件中。 
   * 文件輸出地址:"/home/nazi/2.txt" 文件地址可以更改 
   * */ 
  public void fileOt() throws FileNotFoundException{ 
    FileOutputStream fo = new FileOutputStream("/home/nazi/2.txt"); 
    try { 
      ObjectOutputStream so = new ObjectOutputStream(fo); 
      so.writeObject(list); 
      so.close(); 
    } catch (IOException e) { 
      e.printStackTrace(); 
    } 
     
  } 
 
  /* 
   * function: 從指定路徑讀取文件,然后將對(duì)象狀態(tài)進(jìn)行賦值使用 
   * 
   * */ 
  @SuppressWarnings("unchecked") 
  public void fileIn() throws FileNotFoundException{ 
    FileInputStream fi = new FileInputStream("/home/nazi/2.txt"); 
    try { 
      ObjectInputStream si = new ObjectInputStream(fi); 
      list = (ArrayList<Student>) si.readObject(); 
      si.close(); 
    } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } catch (ClassNotFoundException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } 
  } 
   
   
   
 
} 

1.3、StuView類

/* 
 * FileName:StuView.class 
 * 描述:以特定的方式展示數(shù)據(jù) 
 * @Atuthor:nazi 
 * @version:1.0 
 * */ 
import java.awt.Font; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.io.FileNotFoundException; 
import java.util.ArrayList; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JTextArea; 
import javax.swing.JTextField; 
 
 
/* 
 * StuView 類用于展示數(shù)據(jù) 
 * @author:nazi 
 * @version:1.0 
 * */ 
public class StuView {  
  private static Cotroller cotroller; 
  public static void main(String args[]){ 
    //創(chuàng)建管理者 
    cotroller = new Cotroller(new ArrayList<Student>()); 
    //界面 
    initFrame(); 
  } 
   
  /* 
   * InitFrame()中含有各種類型的控件,以及控件所對(duì)應(yīng)的事件處理步驟 
   * */ 
  protected static void initFrame(){ 
      JFrame frame = new JFrame("學(xué)生信息管理系統(tǒng)"); 
      frame.setSize(600,600); 
      frame.setLocation(500, 100); 
      frame.setLayout(null); 
      //生成組件 
      final JTextField name = new JTextField(); 
      name.setBounds(79, 10, 103, 25); 
      final JTextField num = new JTextField(); 
      num.setBounds(79, 53, 103, 25); 
      final JTextField sex = new JTextField(); 
      sex.setBounds(79, 101, 103, 25); 
      final JTextField age = new JTextField(); 
      age.setBounds(79, 161, 103, 25); 
      final JTextField g1 = new JTextField(); 
      g1.setBounds(79, 216, 103, 25); 
 
      final JTextArea show = new JTextArea(); 
      show.setBounds(194, 12, 388, 274); 
      frame.add(show); 
      show.setFont(new Font("Serif",Font.BOLD,18)); 
     
       
       
      frame.add(show); 
      frame.add(name); 
      frame.add(num); 
      frame.add(sex); 
      frame.add(age); 
      frame.add(g1); 
      frame.add(show); 
       
      JLabel label = new JLabel("學(xué)號(hào):"); 
      label.setBounds(12, 55, 63, 13); 
      frame.getContentPane().add(label); 
       
      JLabel label_1 = new JLabel("姓名:"); 
      label_1.setBounds(12, 10, 63, 13); 
      frame.getContentPane().add(label_1); 
       
      JLabel label_2 = new JLabel("性別:"); 
      label_2.setBounds(12, 110, 63, 13); 
      frame.getContentPane().add(label_2); 
       
      JLabel label_3 = new JLabel("年齡:"); 
      label_3.setBounds(12, 167, 63, 13); 
      frame.getContentPane().add(label_3); 
       
      JLabel label_4 = new JLabel("成績(jī):"); 
      label_4.setBounds(12, 226, 70, 13); 
      frame.getContentPane().add(label_4); 
       
       
       
      //添加學(xué)生 
      JButton btnAdd =new JButton("添加"); 
      btnAdd.setBounds(12, 362, 104, 23); 
      frame.add(btnAdd); 
      btnAdd.addActionListener(new ActionListener() { 
        public void actionPerformed(ActionEvent arg0) { 
          Student s1 = new Student(Integer.parseInt(num.getText()),name.getText(), sex.getText(),Integer.parseInt(age.getText()),Integer.parseInt(g1.getText())); 
          //放到集合 
          cotroller.getList().add(s1); 
          //打印 
          for(int i = 0;i<cotroller.getList().size();i++){ 
            show.append("\n"); 
            show.append(cotroller.printAll(i)); 
          } 
           
           
        } 
      }); 
       
      //保存為文件 
      JButton btnSave =new JButton("保存");; 
      btnSave.setBounds(478, 362, 104, 23); 
      frame.add(btnSave); 
      btnSave.addActionListener(new ActionListener() { 
        public void actionPerformed(ActionEvent arg0) { 
          try { 
            cotroller.fileOt(); 
          } catch (FileNotFoundException e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
          } 
        } 
      }); 
       
      //刷新 
      JButton btnRefresh = new JButton("刷新"); 
      btnRefresh.setBounds(327, 362, 104, 23); 
      frame.add(btnRefresh); 
      btnRefresh.addActionListener(new ActionListener() { 
         
        @Override 
        public void actionPerformed(ActionEvent arg0) { 
          try { 
            cotroller.fileIn(); 
          } catch (FileNotFoundException e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
          } 
          //打印 
          for(int i = 0;i<cotroller.getList().size();i++){ 
            show.append("\n"); 
            show.append(cotroller.printAll(i)); 
          } 
           
        } 
      }); 
       
      //刪除 
      JButton button_1 = new JButton("刪除"); 
      button_1.setBounds(169, 362, 104, 23); 
      button_1.addActionListener(new ActionListener() { 
         
        @Override 
        public void actionPerformed(ActionEvent arg0) { 
          // TODO Auto-generated method stub 
           
        } 
      }); 
      frame.add(button_1); 
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
      frame.setVisible(true);  
    } 
 
} 

三、運(yùn)行效果(初始界面、添加界面、刷新界面)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Spring整合redis(jedis)實(shí)現(xiàn)Session共享的過(guò)程

    Spring整合redis(jedis)實(shí)現(xiàn)Session共享的過(guò)程

    這篇文章主要介紹了Spring整合redis(jedis)實(shí)現(xiàn)Session共享,需要的朋友可以參考下
    2018-06-06
  • Java9新特性中的模塊化詳解

    Java9新特性中的模塊化詳解

    今天介紹一個(gè)Java?9的功能,模塊化(Modular),這可能使Java有史以來(lái)最大的Feature,對(duì)Java9模塊化相關(guān)知識(shí)感興趣的朋友一起看看吧
    2022-03-03
  • JavaWeb頁(yè)面中防止點(diǎn)擊Backspace網(wǎng)頁(yè)后退情況

    JavaWeb頁(yè)面中防止點(diǎn)擊Backspace網(wǎng)頁(yè)后退情況

    當(dāng)鍵盤敲下后退鍵(Backspace)后怎么防止網(wǎng)頁(yè)后退情況呢?今天小編通過(guò)本文給大家詳細(xì)介紹下,感興趣的朋友一起看看吧
    2016-11-11
  • SpringBoot開(kāi)發(fā)實(shí)戰(zhàn)系列之動(dòng)態(tài)定時(shí)任務(wù)

    SpringBoot開(kāi)發(fā)實(shí)戰(zhàn)系列之動(dòng)態(tài)定時(shí)任務(wù)

    在我們?nèi)粘5拈_(kāi)發(fā)中,很多時(shí)候,定時(shí)任務(wù)都不是寫死的,而是寫到數(shù)據(jù)庫(kù)中,從而實(shí)現(xiàn)定時(shí)任務(wù)的動(dòng)態(tài)配置,下面這篇文章主要給大家介紹了關(guān)于SpringBoot開(kāi)發(fā)實(shí)戰(zhàn)系列之動(dòng)態(tài)定時(shí)任務(wù)的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • Java 函數(shù)編程詳細(xì)介紹

    Java 函數(shù)編程詳細(xì)介紹

    這篇文章主要介紹了Java函數(shù)式編程,lambda表達(dá)式可以被認(rèn)為是一個(gè)匿名函數(shù),可以在函數(shù)接口的上下文中使用。函數(shù)接口是只指定一個(gè)抽象方法的接口,下面來(lái)看文章的詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-11-11
  • springboot2.3 整合mybatis-plus 高級(jí)功能及用法詳解

    springboot2.3 整合mybatis-plus 高級(jí)功能及用法詳解

    這篇文章主要介紹了springboot2.3 整合mybatis-plus 高級(jí)功能,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09
  • 解決Spring中@Value注解取值為null問(wèn)題

    解決Spring中@Value注解取值為null問(wèn)題

    近期應(yīng)用中因業(yè)務(wù)迭代需要接入 user 客戶端,接入后總是啟動(dòng)失敗,報(bào)注冊(cè) user bean 依賴的配置屬性為 null,所以接下來(lái)小編就和大家一起排查分析這個(gè)問(wèn)題,感興趣的小伙伴跟著小編一起來(lái)看看吧
    2023-08-08
  • 面試官:怎么做JDK8的垃圾收集器的調(diào)優(yōu)(面試常問(wèn))

    面試官:怎么做JDK8的垃圾收集器的調(diào)優(yōu)(面試常問(wèn))

    這篇文章主要介紹了面試官:怎么做JDK8的垃圾收集器的調(diào)優(yōu),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Java處理延時(shí)任務(wù)的常用幾種解決方案

    Java處理延時(shí)任務(wù)的常用幾種解決方案

    本文主要介紹了Java處理延時(shí)任務(wù)的常用幾種解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05
  • 使用filter實(shí)現(xiàn)url級(jí)別內(nèi)存緩存示例

    使用filter實(shí)現(xiàn)url級(jí)別內(nèi)存緩存示例

    這篇文章主要介紹了使用filter實(shí)現(xiàn)url級(jí)別內(nèi)存緩存示例,只需要一個(gè)靜態(tài)類,在filter中調(diào)用,也可以全部寫到filt里面??梢愿鶕?jù)查詢參數(shù)分別緩存,需要的朋友可以參考下
    2014-03-03

最新評(píng)論

嘉定区| 安丘市| 梁河县| 淅川县| 昔阳县| 鄂托克旗| 祁阳县| 花垣县| 治多县| 鹰潭市| 都安| 津南区| 大港区| 龙南县| 湖南省| 鄂伦春自治旗| 左贡县| 阆中市| 治县。| 忻城县| 遂昌县| 锡林浩特市| 班戈县| 饶河县| 许昌市| 弋阳县| 菏泽市| 腾冲县| 肇庆市| 正阳县| 银川市| 资源县| 隆安县| 乌拉特前旗| 漳平市| 加查县| 买车| 沂水县| 西平县| 泰州市| 肇州县|