当用户按任意按钮时,如何从Java Frame中的用户输入获取?

时间:2018-05-13 10:38:49

标签: java

package jdbcapp5;

import java.awt.Button;

import java.awt.Color;

import java.awt.FlowLayout;

import java.awt.Frame;

import java.awt.TextField;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

class myframe extends Frame implements ActionListener
   { 
      TextField tx1,tx2,tx3;

      Label l1,l2,l3;

      Button b1,b2,b3;

      Connection con;

      ResultSet rs;

      int result;

      myframe()

      {

      try
       {
     this.setVisible(true);

     this.setSize(400,400);

     this.setTitle("JDBC Small Project");

     this.setLayout(new FlowLayout());

     this.setBackground(Color.green);

     Class.forName("oracle.jdbc.driver.OracleDriver");

 con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");

Statement st=con.createStatement();

String q1 ="create table student(eid rollno,ename varchar2(30),ename course varchar2(20))";


int x =st.executeUpdate(q1);

System.out.println("Table is created"+x);

}

     catch(Exception e)

 {

        {
         e.printStackTrace();

         }

 }

     l1=new Label("Admission       Management System     ");

     b1=new Button("Add");

     b2=new Button("Update");

     b3=new Button("Search");

     b1.addActionListener(this);

     b2.addActionListener(this);

     b3.addActionListener(this);

     this.add(l1);

     this.add(b1);

     this.add(b2);

     this.add(b3);

     this.addWindowListener((WindowListener) new mywindow());    
    }

public void actionPerformed(ActionEvent e)

     {  
        String label=e.getActionCommand();

         try{

            if(label.equals("Add"))

          {

            }

          if(label.equals("Update"))

          {
              }
          if(label.equals("Search"))
          {


          }

         }

         catch(Exception ee)

         {

              ee.printStackTrace();

}
     }


   }

0 个答案:

没有答案