wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Painting a frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Painting a frame" Watch "Painting a frame" New topic
Author

Painting a frame

Howard Ralston
Ranch Hand

Joined: Jun 25, 2001
Posts: 105
Hi guys,
I'm having another problem doing basic coding. What I am trying to do is make a frame with a button which when pushed will create a "balloon" which travels from the bottom of the frame to the top. Every time you push the button, you get a new balloon. I am trying to do this using threads in the makeBalloons class, but I get an error saying that there is no method update() in class makeBalloons. I could figure out how to do this in an applet, but I cannot do it in a frame. Can anybody help me out here?
Thanks in advance,
Howard
<code>
import java.awt.*;
import java.awt.event.*;
public class LooseBall extends Frame implements ActionListener{
Panel p;
Canvas c1;
Button push;
Label label;
LooseBall(){
super("Floating Ballons");

setBounds(20,20,500,500);
p = new Panel();
c1 = new Canvas();
label = new Label();
push = new Button("Push");
push.addActionListener(this);
p.add(push);
p.add(label);

add(p,BorderLayout.NORTH);
add(c1,BorderLayout.CENTER);
}
public static void main(String []args){
LooseBall lb = new LooseBall();
lb.setBounds(20,20,500,500);
lb.pack();
lb.setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource() == push){
makeBalloons mb = new makeBalloons();

Thread t = new Thread(mb);
t.start();
}
}
}
//new class which makes the balloons
class makeBalloons implements Runnable{
int x = 100,y = 300;
int diameter = 7;

public void run(){
while(y > 0){
try{
Thread.sleep(400);
}
catch(InterruptedException e){
}
update(g);
}
}
public void update(Graphics g){
paint(g);
}
public void paint(Graphics g){
g.setColor(Color.red);
g.fillOval(x,y-=3,10,10);
}
}
</code>

<a href="http://www.getlocaldeals.com" target="_blank" rel="nofollow">Free local coupons</a>
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
problem is what is update(g) in your class ? all though you have created a method update(Graphics) there is no grphics object associated anywhere there in your class. What you can do is just pass your class to that class or just a Graphics object maybe and then you can paint on it. Other wise just do all these operations in same class.


Val SCJP <BR>going for SCJD
 
 
subject: Painting a frame
 
Similar Threads
Text canvas vertical scroll
Help: Exception occurred during event dispatching
Can't seem to paint on to a Frame.
Problem linking button to mouse event - Please help!
display text diagonally