Basically, I am trying to drawString and I am getting some unexplained errors. Eclipse isn't redlining anything, but when I run the application, it gives an error and refuses to draw the test. Here is my source code:
MainGameClass:
public class MainGameClass { //Accesses the ScreenHandler class and makes it use 'sh' variable static ScreenHandler sh = new ScreenHandler(); //Main thingy (duh) public static void main(String[] args) { //Makes ScreenHandler class activate DrawWindow method sh.DrawWindow(); sh.paint(null); } }
ScreenHandler
import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JLabel; //Referenced by MainGameClass public class ScreenHandler { //Draws the window the game is in JFrame frame = new JFrame("Indev v0.01"); //frame.add(new paintText); paintText pt = new paintText(); public void DrawWindow(){ //Initiates window drawing frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel emptyLabel = new JLabel(""); //Makes it 800 by 600 emptyLabel.setPreferredSize(new Dimension(1000, 600)); frame.getContentPane().add(emptyLabel, BorderLayout.CENTER); frame.pack(); //Makes it visible frame.setVisible(true); //Activates the PaintWindow function below PaintWindowColor(); } public void PaintWindowColor(){ //Sets the background color to blue //frame.getContentPane().setBackground(Color.BLUE); frame.setForeground(Color.BLACK); } } @SuppressWarnings("serial") class paintText extends Canvas{ public paintText(){ System.out.println("Loaded xtraclass"); } public void paint(Graphics g){ //System.out.println("Loaded!"); g.setColor(getForeground()); g.drawString("Hey!", 200, 200); } }
I hope you can help, as any guidance would be greatly appreciated!