Reputation: 3
I was trying to make a circle and displaying that on applet window. But after running the code it neither creates any window nor displays the Circle. My code doesn't show any error. Where is the error?
package webgame;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.logging.Level;
import java.util.logging.Logger;
public class StartingPoint extends Applet implements Runnable {
int x = 0;
int y = 0;
int dx = 2;
int dy = 2;
int radius = 10;
@Override
public void init() {
}
@Override
public void start() {
Thread thread = new Thread(this);
thread.start();
}
@Override
public void run() {
while (true) {
repaint();
try {
Thread.sleep(17);
} catch (InterruptedException e) {
//Logger.getLogger(StartingPoint.class.getName()).log(Level.SEVERE, null, e);
e.printStackTrace();
}
}
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void stop() {
}
@Override
public void destroy() {
}
@Override
public void paint(Graphics g) {
g.setColor(Color.CYAN);
g.fillOval(x, y, radius, radius);
}
public static void main(String[] args) {
// TODO code application logic here
}
}
Upvotes: 0
Views: 77
Reputation: 22972
You don't need main method to execute applet and you have to Create following html file after compiling your class.
<HTML>
<HEAD></HEAD>
<BODY>
<div>
<APPLET CODE="Main.class" WIDTH="500" HEIGHT="500">
</APPLET>
</div>
</BODY>
</HTML>
And run like this
>appletviewer Main.java
Check Out this LINK
Upvotes: 1