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
posted
0
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
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.