I don't know what is causing this, but what happens, is that my window appears, but my drawString(); doesn't appear and show the text. No errors or anything.
import java.awt.Graphics; import java.awt.Graphics2D; import javax.naming.ldap.Rdn; 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(); } public void paint(Graphics g){ g.drawString("Hey!", 200, 200); } }
ScreenHandler class:
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; 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"); 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); } }