Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
is JFRAME so hard to work to????? how do i make the button to work???? Posted by lwiq on 11 Apr 2007 at 11:51 AM
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???????

Report
Re: is JFRAME so hard to work to????? how do i make the button to work Posted by zibadian on 11 Apr 2007 at 12:33 PM
: 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");
    }




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.