Results 1 to 6 of 6
Thread: Applet not working
- 04-15-2009, 02:30 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
Applet not working
i had done a small applet program in which i want to move my alphabet A horizontally
but i m getting an error like dis
symbol : constructor Thread(priyas)
location: class java.lang.Thread
t=new Thread(this);
my program is
please try to help me out to perform this applet to workJava Code:import java.applet.*; import java.awt.*; /* <applet code=priyas width=500 height=500> </applet> */ public class priyas extends Applet { int x;int y; Thread t=null; public void run() { for(;;) { try { repaint(); Thread.sleep(0); if(x<392) x++; else x=7; } catch(Exception e) { } } } public void init() { setBackground(Color.black); Font f=new Font("Comic Sans",Font.BOLD,32); setFont(f); t=new Thread(this); t.start(); } public void paint(Graphics g) { g.setColor(Color.white); g.drawRect(4,178,72,10); g.drawRect(402,10,6,110); g.drawRect(254,310,10,379); g.drawRect(405,310,85,10); g.drawString("A",19,110); g.drawString("B",111,379); g.drawString("C",416,393); showStatus("Bouncing Alphabets"); } }
- 04-15-2009, 02:42 PM #2
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
i dont know what is the problem java forum people are not replying to my thread posted
- 04-15-2009, 03:17 PM #3
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
As you are creating a Thread object in this class and overriding run method in he same class, you need to implement Runnable interface
Java Code:import java.applet.*; import java.awt.*; /* <applet code=priyas width=500 height=500> </applet> */ public class priyas extends Applet implements Runnable { int x;int y; Thread t=null; public void run() { for(;;) { try { repaint(); Thread.sleep(0); if(x<392) x++; else x=7; } catch(Exception e) { } } } public void init() { setBackground(Color.black); Font f=new Font("Comic Sans",Font.BOLD,32); setFont(f); t=new Thread(this); t.start(); } public void paint(Graphics g) { g.setColor(Color.white); g.drawRect(4,178,72,10); g.drawRect(402,10,6,110); g.drawRect(254,310,10,379); g.drawRect(405,310,85,10); g.drawString("A",19,110); g.drawString("B",111,379); g.drawString("C",416,393); showStatus("Bouncing Alphabets"); } }
- 04-15-2009, 04:04 PM #4
Member
- Join Date
- Mar 2009
- Posts
- 51
- Rep Power
- 0
but my alphabets are just blinking but not moving
-
- 04-16-2009, 08:18 AM #6
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Similar Threads
-
Calling another applet on click of button in one applet
By niteshwar.bhardwaj in forum Java 2DReplies: 1Last Post: 02-19-2009, 12:54 PM -
Shape drawing applet not working...
By evapisces in forum Java AppletsReplies: 0Last Post: 11-17-2008, 11:46 PM -
Java mail problem(working in intranet,but not working in iternet)
By sundarjothi in forum Advanced JavaReplies: 8Last Post: 05-28-2008, 07:00 AM -
Applet button not working
By letmeoutofhere in forum Java AppletsReplies: 9Last Post: 11-14-2007, 12:15 PM -
Applet, To center text and To open I engage in a dialog in an Applet
By Marcus in forum Java AppletsReplies: 4Last Post: 06-08-2007, 06:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks