I am having trouble accessing several components in a JFrame to use their setText("...") method. My main is in a seperate class, because the actual program has many windows that need to be managed at the same time.
public GameWindow() {
initialize();
gameFrame.setVisible(true);
}
private void initialize() {
gameFrame = new JFrame();
JTextPane gameTextPane = new JTextPane(); // text pane to contain all game text
gameTextPanel.add(gameTextPane);
And this is my main:
public class GameMain {
public static GameWindow gW = new GameWindow();
//I have tried using the code below with various numbers, but the "setText()" method is never available
gW.getGameFrame().getContentPane().getComponent(x);
}
I am trying to set the text of this from a seperate class, but I can not access the components. Ultimately, the final code should look something like this:
public static void main(String[] args) {
// make the GUI and initilize
changeTheText();
}
public static void changeTheText() {
[CODE TO ACCESS TEXTFIELD].setText("Hello World");
}
I have tried many different methods I've found searching around, but I don't really understand any of them, and none of them still allow me to access the methods I need.