Confused about painting in Java2D
HI, I'm trying to get a simple app - note I don't want to do this in an Applet - that displays some text on screen and then exits when a key is pressed. I don't know how to get it to paint if I just call paint() from the class constructor it complains about the parameter.
paint(java.awt.Graphics) cannot be applied to ()
If I try to call paint from the calling class I get the same problem.
Do I need a JPanel and if so, what for? Where should I use paint() and not paintComponent() or vice versa and what's the difference? I've seen pieces of code which draw without a JPanel or JFrame but I don't know how those work. Here's what I've got so far:
publicclass Controller
{
public CallingClass
{
Intro intro =new Intro();
}
publicstaticvoid main(String[] args)
{
Controller callingClass =new CallingClass;
}
}
import java.awt.*;
import java.awt.Color;
publicclass Intro
{
public Intro()
{
paint();
}
publicvoid paint(Graphics g)
{
setBackgrond(Color.black);
g.setColor(Color.green);
g.drawString("Blah",512,20);
g.drawString("Blah",20,60);
g.drawString("Blah",20,80);
g.drawString("Blah",20,120);
g.drawString("Blah",20,140);
g.drawString("Blah",20,160);
g.drawString("Blah",20,180);
g.drawString("Press F to start or q to quit",20,200);
}
publicvoid keyDown(Event e,int key)
{
switch(key)
{
case'F':
//MainClass mainClass = new MainClass();//ignore this
break;
case'Q':
System.exit(0);
break;
}
}
}
I know I sound like a noob but I'm having trouble finding this sort of information.

