Results 1 to 3 of 3
Thread: Applet not working correctly?
- 04-18-2011, 06:25 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Applet not working correctly?
I'm new to java and wanted to start with a simple animation applet. The applet consists of a red circle being moved across the screen (to the right), but for some reason the ball never moves. I'm not sure if my run method is ever starting. Some input on this problem would be much appreciated. :)
and the html file is...Java Code:package def; import java.applet.*; import java.awt.*; public class BallApplet extends Applet implements Runnable{ int x_pos = 20; int y_pos = 100; int radius = 20; private Image dbImage; private Graphics dbg; public void init(){ setBackground (Color.black); } public void start(){ Thread th1 = new Thread(); th1.start(); } public void stop(){} public void destroy(){} public void run(){ Thread.currentThread().setPriority(Thread.MIN_PRIORITY); while(true){ x_pos++; repaint(); try{ Thread.sleep(20); }catch(InterruptedException ex){} Thread.currentThread().setPriority(Thread.MAX_PRIORITY); } } public void paint(Graphics g){ g.setColor(Color.red); g.fillOval(x_pos - radius, y_pos - radius, 2 * radius, 2 * radius); } public void update(Graphics g){ if(dbImage==null){ dbImage = createImage(this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics(); } dbg.setColor(getBackground()); dbg.fillRect(0, 0, this.getSize().width, this.getSize().height); dbg.setColor(getForeground()); paint(dbg); } }
Java Code:<html> <body> <p><applet code ="BallApplet.class" width=700 height=400> </applet></p> </body> </html>
Last edited by Fubarable; 04-18-2011 at 06:29 AM. Reason: mod edit: code tags corrected
-
Don't ever call paint directly. Do all of your graphics in the paint method itself.
Question: why AWT and not Swing which while not fully up to date, is much more up to date, robust and flexible than AWT.
- 04-18-2011, 06:32 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
drawString() method not working correctly
By tnixon22 in forum New To JavaReplies: 2Last Post: 02-25-2011, 08:57 PM -
Error Checking not working correctly
By RickAintree in forum New To JavaReplies: 1Last Post: 12-15-2010, 01:54 PM -
My rotate 2d pos method isnt working correctly..
By Addez in forum New To JavaReplies: 5Last Post: 12-01-2009, 09:04 AM -
Gueesing Game Almost done, but not working correctly
By mbnumba6 in forum New To JavaReplies: 5Last Post: 03-18-2009, 03:01 AM -
[SOLVED] \t not working correctly?
By Gakusei in forum New To JavaReplies: 5Last Post: 05-06-2008, 04:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks