Hello Everyone! I'm new to java. I have an important assignment, and I would really really appreciate if someone helps me even a little.
I have to draw some balls (shapes) moving to the screen.
But I have a problem, I cannot even draw shapes.
I use the following code but it doesnt recognizes the first import. (though I am a little confused about Jframe (whether should I use it or not), Swing, AWT, I dont know very well whats their differences and what are they about.
And there is no main function in here, should I implement one?? And please, if you know a good tutorial or some links that can help me draw shapes, I will be very thankful.
import java.awt.*;
import java.applet.*;
public class DrawExample extends Applet
{
Font bigFont;
Color redColor;
Color weirdColor;
Color bgColor;
public void init()
{
bigFont = new Font("Arial",Font.BOLD,16);
redColor = Color.red;
weirdColor = new Color(60,60,122);
bgColor = Color.blue;
setBackground(bgColor);
}
public void stop()
{
}
public void paint(Graphics g)
{
g.setFont(bigFont);
g.drawString("Shapes and Colors",80,20);
g.setColor(redColor);
g.drawRect(100,100,100,100);
g.fillRect(110,110,80,80);
g.setColor(weirdColor);
g.fillArc(120,120,60,60,0,360);
g.setColor(Color.yellow);
g.drawLine(140,140,160,160);
g.setColor(Color.black);
}
}
Regards.
Edi