Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Bailey Evans   on Nov 27 In Java Category.

  
Question Answered By: Alyssa Campbell   on Nov 27

Check this code it should compile


import java.awt.*;
import java.awt.event.*;

public class  Test2 implements ActionListener{
Frame frame  = null;
FlowLayout flow = null;
TextField text1 = null;
TextField text2 = null;
Button button = null;

public Test2(){
frame = new Frame("Hullo");
frame.setBounds(0,0,200,200);
flow = new FlowLayout();
frame.setLayout(flow);
text1 = new TextField("This is .....");
text2 = new TextField("Second one");
button = new Button("First");

frame.add(text1);
frame.add(text2);
frame.add(button);
frame.setVisible(true);
button.addActionListener(this);
}

public static  void main(String[]args){
Test2 test = new Test2();

}

public void  actionPerformed(ActionEvent ee){

String msg = new String("Button pressed");

if(ee.getSource() == button){
text2.setText(msg);
}
}

}

Share: 

 
 
Didn't find what you were looking for? Find more on Event Handling - (compilation error) Or get search suggestion and latest updates.


Tagged: