why the button is hided?

N

nick

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SimpleFrame
extends JFrame {
Image im;
public SimpleFrame() {
super("test");

final JButton button = new JButton("fdsfdffs ");
Container container = getContentPane();
container.setLayout(null);
button.setBounds(50, 100, 100, 100);
container.add(button);

button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button.setBounds(10, 10, 10, 10);
}
}
);
setSize(500, 500);

this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

im = Toolkit.getDefaultToolkit().getImage("scdog3.gif");
int width = 0;
int height = 0;

while (width > 0 && height > 0) {
width = im.getWidth(this);
height = im.getHeight(this);
}

this.setVisible(true);

}

public static void main(String arg[]) {
new SimpleFrame();
}

public void update(Graphics g) {
paint(g);

}

public void paint(Graphics g) {
g.drawImage(im, 50, 50, this);

}

}


thanks!
 
A

Andrew Thompson

On Sun, 28 Nov 2004 08:58:13 +0800, nick wrote:

A better group for GUI matters is..
<http://www.physci.org/codes/javafaq.jsp#cljg>

But a better group for beginners is..
<http://www.physci.org/codes/javafaq.jsp#cljh>

In the event, you're code is broken (largely) because you..

final JButton button = new JButton("fdsfdffs ");
Container container = getContentPane();
// you start going wronng here, use a LayOut.
container.setLayout(null);
// and do *not* set the bounds of components
button.setBounds(50, 100, 100, 100);

set layout to 'null'. Which is generally the wrong thing to do.

Find out about lay outs and how to use them. Links from..
<http://www.physci.org/guifaq.jsp#7.1>

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,743
Latest member
WoodrowMea

Latest Threads

Top