I have 2 class files called PaintMe.java and Starter.java.
PaintMe.java contains:
import java.applet.Applet;
import java.awt.*;
public class PaintMe extends Applet {
public void paint(Graphics g) {
g.setColor(Color.red);
g.drawString("HELLOOO", 15, 25);
}
}
Starter.java contains:
import java.applet.Applet;
import java.awt.Graphics;
public class Starter {
public static void main(String[] args) {
PaintMe ring = new PaintMe();
ring.paint();
}
}
So question is, how can I paint my string with calling a paint method from Starter.java?
To get it to compile, change
..to..
Notes
JApplet).main(String[]). An applet is started by the JRE when it is embedded in a web page (or launched using JWS). A GUI can be designed in a panel, that is then put in a free-floating application or applet. That is known as a hybrid. But both frame and applet separately add the GUI, which is (most often) a different class to either.Update 1
Try this.
Source
Prompt
Screenshot
Update 2
I think that is a silly requirement, and it seems like JWS (as mentioned & linked in comments) launching a
JFrameis the best way to view this GUI. OTOH, here is a (very) naive implementation of theStarterclass that will show that applet on-screen.It mixes AWT and Swing (bad), it does not attempt to implement any sort of applet context, and does not call the applet
init/start/stop/destroymethods, but is enough to get the applet on-screen from another class.