Tuesday, 9 August 2011

HOW to Extends Frame Class and How to implement an Interface for ActionListener


import java.awt.*;
import java.awt.event.*;
class MyPackage extends Frame implements ActionListener{


               MyPackage(){
Frame f=new Frame();
Button b=new Button();
b.addActionListener(this);
b.setLabel("OK");
f.add(b);
f.setLayout(new FlowLayout());
f.setVisible(true);
System.out.println("Testing Package");

}


public static void main(String m[]){
new MyPackage();

/*Button b=new Button();
b.addActionListener(this);
//b.addActionListener(f);
 b.setLabel("OK");
f.add(b);
f.setLayout(new FlowLayout());
f.setVisible(true);
System.out.println("Testing Package");*/

}


public void actionPerformed(ActionEvent s){
System.exit(0);
}

}

No comments:

Post a Comment