|
-
Oct 19th, 2005, 10:06 AM
#1
Thread Starter
Member
Working With Java Applets ...
hi,
I just started working in java, using applets. Maybe i'm missing the general idea, but when I have a button on the page, it takes up the entire page and so I cant see the other labels on the applet (even tho I fixed the size of the button in init()). So I tried testing the init() function and found that if I change the button properties in the paint function, it works fine. So i made another function called displayInitComponents() where I re-size the button. but why doesnt the init function work for the button but work for the labels?
here's my code:
public class HelloWorldApplet extends JApplet implements MouseMotionListener {
JLabel test = new JLabel();
JLabel testid = new JLabel();
JButton b = new JButton();
public void paint(Graphics g) {
super.paint(g);
displayInitComponents();
}
public void init() {
super.init();
b.setText("button");
test.setText ("hi1");
testid.setText ("hi2");
test.setBackground(Color.blue);
testid.setForeground(Color.yellow);
test.setLocation(10,120);
testid.setLocation(10,130);
testid.setSize(50,20);
test.setSize(50,20);
add(testid);
add(test);
add(b);
validate();
// Add the MouseMotionListener to your applet
testid.addMouseMotionListener(this);
test.addMouseMotionListener(this);
b.addMouseMotionListener(this);
addMouseMotionListener(this);
repaint();
}
public void mouseDragged(MouseEvent me)
{ ... }
public void mouseMoved(MouseEvent me)
{...}
void displayInitComponents(){
b.setBounds(50,50,80,20);
}
Thanks
Last edited by nima1985; Oct 19th, 2005 at 10:22 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|