程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> 簡略完成Java版先生治理體系

簡略完成Java版先生治理體系

編輯:關於JAVA

簡略完成Java版先生治理體系。本站提示廣大學習愛好者:(簡略完成Java版先生治理體系)文章只能為提供參考,不一定能成為您想要的結果。以下是簡略完成Java版先生治理體系正文


本文實例為年夜家分享了Java完成先生治理體系的詳細代碼,供年夜家參考,詳細內容以下

package BookDemo_1; 
 
import javax.swing.*; 
 
import java.awt.*; 
import java.awt.event.*; 
 
public class Test { 
  public static void main(String[] args) { 
    StudentSys stuSys=new StudentSys("先生治理體系"); 
    stuSys.initWin(); 
  }  
} 
class StudentSys extends JFrame{ 
   
  private JPanel p1,p2,p3,combop; 
  private JTabbedPane tab; 
  private Container container; 
  private JButton b1,b2; 
  private Listener listener; 
  private Label nameLabel; 
  private Label gradeLabel; 
  private Label showLabel; 
  private JTextField textName; 
  private JTextField textGrade; 
  private TextArea showGradeArea; 
  /* 
  * 查找 
  * */ 
  private Label searchLabel; 
  private JTextField searchText; 
  private JButton sBut; 
  private JTextField resultText; 
  private String[] name; 
  private String[] grade; 
   
  /* 
  * 排序 
  * */ 
  private TextArea showTextArea; 
  private JButton sortBut; 
  private int countNum=0; 
  private JButton clearBut; 
  public StudentSys(String str){ 
    super(str); 
     
    this.name=new String[100]; 
    this.grade=new String[100]; 
    listener = new Listener(); 
    tab = new JTabbedPane(JTabbedPane.TOP);  
    //容器 
    container = this.getLayeredPane(); 
    //對象化面板 
    combop = new JPanel(); 
    p1 = new JPanel(); 
    p2 = new JPanel(); 
    p3 = new JPanel(); 
     
    b1 =new JButton("確認添加"); 
    b2 =new JButton("撤回添加"); 
    nameLabel =new Label("姓名"); 
    gradeLabel =new Label("成就"); 
     
    showLabel=new Label("以後記載為零!             "); 
     
    textName =new JTextField(15); 
    textGrade =new JTextField(15); 
    showGradeArea=new TextArea(); 
     
    /* 
    * 查找 
    * */ 
    searchLabel=new Label("請輸出姓名:"); 
    searchText=new JTextField(15); 
    sBut=new JButton("確認查找"); 
    resultText=new JTextField(15); 
    /* 
    * 排序 
    * */ 
    showTextArea=new TextArea(); 
    sortBut=new JButton("成就排序"); 
    clearBut=new JButton("清空數據"); 
  } 
  public void initWin(){ 
    this.setBounds(300, 300, 500, 400); 
    this.addWindowListener(new WindowAdapter(){ 
      public void windowClosing(WindowEvent e) { 
        super.windowClosing(e); 
        System.exit(0); 
      }}); 
      layoutWin(); 
      this.setVisible(true); 
  } 
  private void layoutWin(){ 
     
    tab.add(p1,"成就輸出"); 
    tab.add(p2,"成就查詢"); 
    tab.add(p3,"成就排序"); 
    combop.add(new JLabel("先生信息治理體系")); 
    container.setLayout(new BorderLayout()); 
    container.add(combop,BorderLayout.NORTH); 
    container.add(tab,BorderLayout.CENTER); 
     
    Container con1=new Container(); 
    con1.setLayout(new FlowLayout()); 
    con1.add(nameLabel); 
    con1.add(textName); 
     
    con1.add(gradeLabel); 
    con1.add(textGrade); 
    p1.add(con1,BorderLayout.NORTH); 
    p1.add(con1); 
    p1.add(showGradeArea); 
     
    Container con2=new Container(); 
    con2.setLayout(new FlowLayout()); 
    con2.add(b1); 
    con2.add(b2); 
    con2.add(showLabel); 
    p1.add(con2); 
    b1.addActionListener(listener); 
    b2.addActionListener(listener); 
    /* 
    * 查找結構 
    * */ 
     
    Container con3=new Container(); 
    con3.setLayout(new FlowLayout()); 
    con3.add(searchLabel); 
    con3.add(searchText); 
    con3.add(sBut); 
    p2.add(con3,BorderLayout.NORTH); 
    sBut.addActionListener(listener); 
    p2.add(resultText); 
    /* 
    * 排序結構 
    * */ 
    p3.add(showTextArea); 
    p3.add(sortBut); 
    p3.add(clearBut); 
    sortBut.addActionListener(listener); 
    clearBut.addActionListener(listener); 
  } 
  /* 
  * java外部類完成ActionListener接口 
  * */ 
  class Listener implements ActionListener{ 
    @Override 
      public void actionPerformed(ActionEvent e) { 
       
      if(e.getSource()==b1){ 
         
        if((textName.getText().equals(""))||(textGrade.getText().equals(""))){ 
          showLabel.setText("添加掉敗(姓名,成就不克不及有空)!"); 
        } 
        else{ 
          name[countNum]=textName.getText(); 
          grade[countNum]=textGrade.getText(); 
          countNum++; 
          String area="添加勝利,以後有"+countNum+"筆記錄"; 
          showLabel.setText(area); 
          sortMess(false); 
          textName.setText(""); 
          textGrade.setText(""); 
        } 
         
      } 
      if(e.getSource()==b2){ 
        if(countNum>0){ 
          countNum--; 
          String area="撤回勝利,以後有"+countNum+"筆記錄"; 
          showLabel.setText(area); 
          sortMess(false); 
        } 
      } 
      if(e.getSource()==sBut){ 
        if(!searchText.getText().equals("")){ 
          searchMess(searchText.getText()); 
        } 
      } 
      if(e.getSource()==sortBut){ 
        sortMess(true); 
      } 
      if(e.getSource()==clearBut){ 
        if(!showTextArea.getText().equals("")){ 
          showTextArea.setText(""); 
         } 
      } 
    } 
     
    public void sortMess(boolean sign) { 
      // TODO Auto-generated method stub 
      if(sign){ 
        for(int i=0;i<countNum;i++){ 
          for(int j=i+1;j<countNum;j++){ 
            if(Integer.parseInt(grade[i])<Integer.parseInt(grade[j])){ 
              String s1,s2; 
              s1=name[i]; 
              s2=grade[i]; 
               
              name[i]=name[j]; 
              grade[i]=grade[j]; 
               
              name[j]=s1; 
              grade[j]=s2; 
            } 
          } 
        } 
      }else{  
       
        if(!showGradeArea.getText().equals("")){ 
          showGradeArea.setText(""); 
        } 
      } 
      for(int i=0;i<countNum;i++){ 
        String content="姓名:"+name[i]+"\t"+"成就"+grade[i]; 
        if(sign)showTextArea.append(content+"\n"); 
        else showGradeArea.append(content+"\n"); 
      } 
    } 
     
    public void searchMess(String n) { 
      // TODO Auto-generated method stub 
       
      for(int i=0;i<countNum;i++){ 
        if(name[i].equals(n)){ 
          String content="姓名:"+name[i]+","+"成就"+grade[i]; 
          resultText.setText(content); 
          return; 
        } 
      } 
      resultText.setText("未找到該先生!"); 
    } 
  } 
} 

 

以上就是本文的全體內容,願望對年夜家進修Java法式設計有所贊助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved