I'm making a text editor in Java and I want to have a JFrame with a JPanel in it, and then a JTextArea and a JToolBar inside of the JPanel. The frame shows up how I want it, and the toolbar does although it's empty right now, but the JTextArea doesn't even appear. I thought I might need to specify a size but even when I did that it didn't make it appear.
I have three classes, the Main class, the GUI class, and the Screen class.
Here's the code in my Main class
public class Main {
// Attributes:
private static Screen screen = new Screen();
private static GUI ui = new GUI();
// Behaviors:
public static void main(String[] args) {
// Creates the JFrame with its preset attributes
screen.createFrame();
ui.addGUI();
Screen.frame.pack();
Screen.frame.setVisible(true);
}
Here's the code in my Screen class:
public class Screen {
// Attributes / Instance Variables:
private final int WIDTH = 854;
private final int HEIGHT = 480;
private final static String TITLE = "Lightweight Java Text Editor";
public static JFrame frame = new JFrame(TITLE);
private Dimension dimensions = new Dimension(WIDTH, HEIGHT);
// Behaviors / Methods:
/*
* Generates the frame to have a certain size, allows it to be resized, centers
* it on the screen, terminates Java when the window is closed, and makes it
* visible.
*
* The width and height are ALWAYS initially 854x480!
*/
public void createFrame() {
frame.setPreferredSize(dimensions);
frame.setResizable(true);
frame.setLocationRelativeTo(null);
// frame.pack(); makes the three
// lines above actually show up
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
// Getters and Setters for private variables that may be needed
public Dimension getDimensions() {
return dimensions;
}
public void setDimensions(Dimension dimensions) {
this.dimensions = dimensions;
}
public int getWIDTH() {
return WIDTH;
}
public int getHEIGHT() {
return HEIGHT;
}
public String getTITLE() {
return TITLE;
}
}
And finally, here's the code in my GUI class
public class GUI {
// Attributes / Instance Variables:
// The container
JPanel panel = new JPanel();
// The area where the user types
JTextArea textEditingField = new JTextArea(600,200);
// The tool-bar on the left side
JToolBar tools = new JToolBar();
public void addGUI() {
Screen.frame.add(panel);
Screen.frame.add(textEditingField);
Screen.frame.add(tools);
}
}
What have I done wrong?