Painfully simple Applet problem.
Hey all, I'm trying to learn how to build applets, and I simply can't get my browser to run one! Originally I was using Chrome, but I switched to Firefox and got the same error.
Here's the applet trying to load: ImageShack® - Online Photo and Video Hosting
I "click for details" and this window comes up: ImageShack® - Online Photo and Video Hosting
I click "details" and this comes up: ImageShack® - Online Photo and Video Hosting
Unfortunately, I have no idea what the problem means....
Here's my applet code and my html code:
Code :
import java.applet.*;
import java.awt.*;
class MyApplet extends Applet {
Font bigFont;
Color whiteColor;
public void init() {
bigFont = new Font("Arial", Font.BOLD, 16);
whiteColor = Color.white;
setBackground(whiteColor);
}
public void paint(Graphics g) {
g.setFont(bigFont);
g.drawString("Austin Rose", 80, 20);
}
public void stop() {
}
}
Code :
<HTML>
<HEAD>
<TITLE> Austin's Applet </TITLE>
</HEAD>
<BODY>
<applet code="MyApplet.class" width="300" height="300">
</BODY>
</HTML>
Any help is greatly appreciated!
Re: Painfully simple Applet problem.
I think it is saying that your class has to be public
Re: Painfully simple Applet problem.
Changed "class MyApplet" to "public class MyApplet", still doesn't work :/
Re: Painfully simple Applet problem.
The error description says that it can not access the modifiers "" of MyApplet class. Well, i am not sure what exactly the problem is but try to comment
Code :
bigFont = new Font("Arial", Font.BOLD, 16);
this line and in paint() method draw something else and see.
Re: Painfully simple Applet problem.
The problem is in your paint method. Try this instead.
Code Java:
public void paint (Graphics g) {
//Cast the Graphics object into a Graphics2D object
Graphics g2 = (Graphics2D) g;
// Draw the string
g2.drawString("Hello", 10, 10);
//Finished painting
g2.finalize();
}
And here is a full template that works for me if you have any more problems.
Code Java:
import java.applet.Applet;
import java.awt.*;
public class MyApplet extends Applet {
public void init() {}
public void stop() {}
public void destroy() {}
public void paint (Graphics g) {
//Cast the Graphics object into a Graphics2D
Graphics g2 = (Graphics2D) g;
// Draw the string
g2.drawString("Hello", 10, 10);
//Finished painting
g2.finalize();
}
public void run () {
repaint();
}
}
Re: Painfully simple Applet problem.
Quote:
still doesn't work
Please copy and paste here the contents of the java console that shows the error message.