: import java.awt.*;
: import javax.swing.*;
:
: public class jframe2 extends JFrame {
:
: public jframe2()
: {
: setTitle("frame");
: setSize(300,300);
:
: JPanel content = (JPanel) getContentPane();
: content.setLayout(null);
: content.add(new JButton("OK")).reshape(30,30,100,30);
: }
:
: public static void main(String args[])
: {
: jframe2 app = new jframe2();
: app.setVisible(true);
: }
:
: public boolean action (Event evt, Object arg)
: {
: if(evt.target instanceof JButton)
: {
: System.exit(0);
: return true;
: }
: return false;
: }
: }
:
:
: why doesnt work the button???????
:
:
You didn't add an ActionListener to the button:
class Frame;
JButton helloWorld;
public void init() {
helloWorld = new JButton("Hello world");
b.addListener(this);
add(b);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource = helloWorld) {
System.out.println("Hello world pressed");
}