|
|
Re: Applet Problems..
|
Posted: Jun 10, 2005 1:41 AM
|
|
"public abstract void" is the description of the method, meaning public: everyone can call it void: no return type abstract: it is not implemented, there is no written code behind it. You should have called it with appletResize(100,200);
However, this line does not what you want.
try it this way:
import java.awt.*;
import java.applet.*;
public class HelloWorld extends Applet {
public HelloWorld() {
resize (100, 200); // is the same as: this.resize(100, 200);
}
public void paint(Graphics g) {
Color backgroundcolor = new Color(0,0,255);
g.setColor(backgroundcolor);
g.fillRect(0,0,100,200);
//Draws the text in black
g.setColor(Color.black);
g.drawString("Welcome to Java!!", 50, 60 );
}
}
Some hints: 1. Instead of painting the rectangle everytime, you should set the backgroundcolor of the applet ONCE. setBackground(backgroundcolor); 2. if you override the paint method, your first line should be super.paint(g);, because otherwise buttons, labels ... in thiscontainer would not be painted. 3. instead of overriding the paint method, override the paintComponent method, this prevents flickering. If you do so, you must of course call super.paintComponent(g);
|
|