For software engineering course information into the system

 

 

 

  1 import java.awt.Color;
  2 import java.awt.Container;
  3 import java.awt.FlowLayout;
  4 import java.awt.event.ActionEvent;
  5 import java.awt.event.ActionListener;
  6 import java.io.FileWriter;
  7 import java.io.IOException;
  8 
  9 import javax.swing.*;
 10 
 11 public class Test extends JFrame{
 12     int i=0;
 13     String arr[][]=newString [30] [. 3 ];
 14      
15      the JLabel La = new new the JLabel ( "course name" );
 16      the JLabel LB = new new the JLabel ( "teachers" );
 . 17      the JLabel LC = new new the JLabel ( "Venue" );
 18 is      the JTextField = JT1 new new the JTextField (15 );
 . 19      the JTextField = JT2 new new the JTextField (15 );
 20 is      the JTextField JT3 = new new the JTextField (15 );
 21 is          
22 is      the JButton JB1 = new new the JButton ( "entry" );
 23 is      the JButton JB2 =new JButton("退出");
 24     
 25     public Test() {
 26         setDefaultCloseOperation(EXIT_ON_CLOSE);
 27         setTitle("课程信息录入");
 28         setBounds(580, 250, 320, 250);
 29         setResizable(false);
 30         
 31         Container c=getContentPane();
 32         c.add(la);
 33         c.add(lb);
 34         c.add(lc);
 35         c.add(jt1);
 36         c.add(jt2);
 37         c.add(jt3);
 38         c.add(jb1);
 39         c.add(jb2);
 40         
 41         la.setBounds(20,40,50,18);
 42         lb.setBounds(20,80,50,18);
 43         lc.setBounds(20, 120, 50, 18);
 44         jt1.setBounds(70,40,200,18);
 45         jt2.setBounds(70,80,200,18);
 46         jt3.setBounds(70,120,200,18);
 47         jb1.setBounds(40, 160, 80, 20);
 48         jb2.setBounds(170, 160, 80, 20);
 49         c.setLayout(null);
 50         c .setBackground(Color.white);
 51         setVisible(true);
 52     }
 53     void information() {
 54             jb1.addActionListener(new ActionListener() {//录入按钮
 55                 public void actionPerformed(ActionEvent e) {
 56                     boolean flag1=true;
 57                     boolean flag2=true;
 58                     boolean flag3=true;
 59                     for(int j=0;j<i;j++) {
 60                         IF (. jt1.getText () the equals (ARR [J] [0])) { // Analyzing unique program 
61 is                              FLAG1 = to false ;
 62 is                              BREAK ;
 63 is                          }
 64                          // Analyzing the teacher's name 
65                          IF (jt2.getText ()! .equals ( "Wang") &&! jt2.getText (). equals ( " Liu Lijia") &&! jt2.getText (). equals ( " Dan") &&! jt2.getText (). equals ( " Wang Hui" !) && jt2.getText () equals ( " Yang Zaiguang." ))
 66                          {
 67                              FLAG2 = to false ;
 68                              BREAK ;
69                          }
 70                          // Analyzing Venue
 71                         if(jt3.getText().charAt(0)!='一'&&jt3.getText().charAt(0)!='二'&&jt3.getText().charAt(0)!='三'&&jt3.getText().charAt(0)!='基') {
 72                             flag3=false;
 73                             break;
 74                         }
 75                         if(jt3.getText().charAt(1)!='教') {
 76                             flag3=false;
 77                             break;
 78                         }
 79                         
 80                     }
 81                     if(flag1&&flag2&&flag3) {
 82                         arr[i][0]=jt1.getText();
 83                         arr[i][1]=jt2.getText();
 84                         arr[i][2]=jt3.getText();    
 85                         i++;
 86                         JDialog jd=new JDialog();
 87                         jd.setVisible(true);
 88                         jd.setBounds(650, 360, 100, 60);
 89                         Container c=jd.getContentPane();
 90                         c.add(new JLabel("录入成功"));
 91 is                      }
 92                      the else // error prompt window, 
93                      {
 94                          IF (! FLAG1) {
 95                              the JDialog JD = new new the JDialog ();
 96                              jd.setVisible ( to true );
 97                              jd.setBounds (650, 360, 100, 60 );
 98                              Container C = jd.getContentPane ();
 99                              c.add ( new new the JLabel ( "entry course repeat" ));
 100                          }
101                          IF (! FLAG2) {
 102                              the JDialog JD = new new the JDialog ();
 103                              jd.setVisible ( to true );
 104                              jd.setBounds (650, 360, 100, 60 );
 105                              Container C = jd.getContentPane ();
 106                              C .add ( new new the JLabel ( "teacher's name input error" ));
 107                          }
 108                          IF (! Flag3) {
 109                              the JDialog JD = new new the JDialog ();
110                              jd.setVisible ( to true );
 111                              jd.setBounds (650, 360, 100, 60 );
 112                              Container C = jd.getContentPane ();
 113                              c.add ( new new the JLabel ( "entry Venue bad" ));
 114                          }
 115                      }
 1 16                      jt1.setText ( "" );
 117                      jt2.setText ( "" );
 1 18                      jt3.setText ( "" );
 119                  }
 120             });
 121              jb2.addActionListener ( new new the ActionListener () {
 122                  public  void the actionPerformed (the ActionEvent E) {
 123                      fileExport ();
 124                  }
 125              });
 126      }
 127      void fileExport () {
 128          the try {
 129              FileWriter FW = new new FileWriter ( "Temo", to true ); // represents input information does not cover 
130.              for ( int J = 0; J <I; J ++ ) {
 131 is                 String s = String.valueOf ( "Course name:" + arr [j] [ 0] + " Instructor:" + arr [j] [ 1] + " Venue:" + ARR [J] [2 ]);
 132                  fw.write (S + "\ n-" );
 133              }
 134              fw.close ();
 135          } the catch (IOException E) {
 136              e.printStackTrace ();
 137          }
 138      }
 139      public  static  void main (String [] args ) {
 140          the Test Test = new new the Test ();
 141 is          test.information ();
 142          test.fileExport ();
 143     }
144 }

Run the test results:

 

 

 

Guess you like

Origin www.cnblogs.com/dongao/p/11694688.html