Ok I am making a user interface for Battleship and want a Frame to appear on the side with the title and instructions of the game in a disabled JTextArea. With the code I have now I can get the JFrame to open blank. The JTextArea only appears if I resize the window. I also can't keep the JTextArea within the bounds of the JFrame/ JPanel. Any help? In this code there is a JTextField, But I have tried Labels and Areas, with the same result.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package battleship;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import javax.swing.*;
/**
*
* @author Xaver
*/
public class Instructions extends JFrame
{
private JPanel myPanel;
public Instructions()
{ setTitle("Instructions");
setLayout(new GridBagLayout());
setSize(700, 450); // default size is 0,0
setLocation(700, 0); // default is 0,0 (top left corner)
//setResizable(false);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setUpPanel();
}
public final void setUpPanel()
{ myPanel = new JPanel();
String myString = "Welcome to BattleShip"
+"This game is a turn based strategy game that "
+"the basic need is to sink the enemy ships before "
+"the enemy sinks yours, you have to input x and \n"
+"y coordinates within the range. On the enemy side \n"
+"~ means misses and * means hits. Happy Hunting!\n";
JTextField jTC= new JTextField(100);
//myPanel.setSize(700,400);
jTC.setText(myString);
//jTC.setBounds(750, 100, 100, 100);
jTC.setEnabled(false);
repaint();
myPanel.add(jTC);
add(myPanel);
}
}