Howdy, Stranger!

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

Categories

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.