How do I link between the circle class I have and the RunCircle class which creates a circle.
Code for Circle Class:
Code:
import java.awt.*;
import java.applet.*;
public class Circle extends Applet
{
public void paint(Graphics g)
{
Circle myCircle = new Circle
g.setColor(Color.black);
g.drawOval(85,45,75,75);
}
}
Code for RunCircle (Correct)
Code:
import java.awt.*;
public class RunCircle
{
public static void main(String[] args)
{
Frame frame = new Frame();
Circle myCircle = new Circle(100,50,50); // is this line that is linked to the circle class??
frame.setSize(300.300);
frame.setBackground(Color.yellow);
frame.add(myCircle);
frame.setVisible(true);
}
}
I’m doing some self-study reading a book and this properly isn’t the best way of going about it mixing frames and applets but that’s what I am doing.
how are you activating your applet? do you need to "initialize" and "start" it within your main method?
Try adding
myCircle.init();
myCircle.start();
before your frame.setxxx stuff and see if you get something new ...
An applet needs to be initialized and started. If you are looking at an applet over the internet, the html page which refers to the applet includes the <applet> code which cues the browser to do that. If you are creating an application, then your application needs to do it.