Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

is JFRAME so hard to work to????? how do i make the button to work????

lwiqlwiq Posts: 15Member
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???????

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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:
    [code]
    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");
    }
    [/code]
Sign In or Register to comment.