// ButtonApp.java // This can be both an application and an applet. // Also demonstrates difference between named and anonymouse inner classes. import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.*; public class GUI extends Applet { private Button b1 = new Button("Execute"); private List operation =new List(3,false); private List table =new List(5,false); private TextField textfield= new TextField(10); private TextArea display=new TextArea("",20,50); String query; DataAC dac; DataCA dca; // private IconMatrix ico = new IconMatrix(16,12,8,8,.4f,.6f,true,false); public GUI() { /** Intialization starts*/ dac=new DataAC(); dca=new DataCA(); comm t = new comm(7,1214,0,0,dac,dca); /* initialise the lower comm layer */ /** Initialization ends*/ } public void init() { setSize(100,100); operation.add("view"); operation.add("insert_last"); operation.add("delete_last"); table.add("cities"); table.add("countries"); table.add("cars"); table.add("credit_cards"); table.add("computers"); add(operation); add(table); b1.addActionListener(new B1()); textfield.addKeyListener(new T1()); textfield.addActionListener(new T2()); textfield.setBackground(Color.white); operation.setBackground(Color.white); table.setBackground(Color.white); b1.setBackground(new Color(230,230,250)); add(textfield); add(b1); add(display); display.setBackground(Color.white); } public void sendQuery(String query) { display.replaceRange("",0,display.getColumns()); CoreMessage cm=new CoreMessage(0,query,1); System.out.println(query); dac.Produce(cm); Message m=(Message)dca.Consume(); display.insert(((CoreMessage)m.getmessageobj()).getQuery(),0); } // Inner classe for button 1. private class B1 implements ActionListener { public void actionPerformed(ActionEvent e) { //System.out.println(operation.getSelectedItem()); //System.out.println(table.getSelectedItem()); //System.out.println(textfield.getText()); if(textfield.getText().equals("")) query=operation.getSelectedItem()+" "+table.getSelectedItem()+" #"; else query=operation.getSelectedItem()+" "+table.getSelectedItem()+" "+textfield.getText(); System.out.println(query); sendQuery(query); } /*public void mouseClicked(MouseEvent e) { System.out.println("SINGLE CLICK"); }*/ } private class T2 implements ActionListener { public void actionPerformed(ActionEvent e) { } } private class T1 implements KeyListener { /*public void actionPerformed(ActionEvent e) { }*/ public void keyTyped(KeyEvent e) { //System.out.println("KEY TYPED:"); } /** Handle the key pressed event from the text field. */ public void keyPressed(KeyEvent e) { //supresses if (!Character.isLetter(e.getKeyChar())) { Toolkit.getDefaultToolkit().beep(); e.consume(); } if(e.getKeyCode()==10) { // System.out.println(Integer.parseInt(textfield.getText())); // textfield.setText("ABCAST-SENT"); } } /** Handle the key released event from the text field. */ public void keyReleased(KeyEvent e) { //System.out.println("KEY RELEASED:"); } } // Application-only code (not executed if running as applet) public static void main(String[] args) { GUI gui; Applet applet = new GUI(); applet.init(); // initialize the applet applet.start(); // start it //Construct the frame that contains the applet. Frame frame = new Frame("client"); frame.setBounds(0,0,400,400); //applet.b1.setBounds(100,100,20,1);// add the buttons //frame.setLayout(new BorderLayout(200, 200)); //frame.setLocation(10,10); frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { System.exit(0); }}); frame.add(applet); // add applet to the frame //frame.pack(); // resize the frame to fit its children frame.show(); // display it } }