私のプログラムに問題がある場合、コードの最初の実行は完全に実行されますが、新しいオブジェクトを作成してから、正しいタイトルで正しいサイズで表示されていますが、コンポーネントは表示されません。新しいオブジェクトが作成されたときにJFrameがコンポーネントを表示しない
スタティック変数がないことを確認しました。すべての必要な変数がコンストラクタで初期化されています。ウィンドウを表示
クラス:
public class DifficultySelect implements ActionListener
{
private JPanel getInput;
private JFrame startFrame;
private JButton easy;
private JButton medium;
private JButton hard;
private JButton custom;
private JLabel labelRow;
private JLabel labelColumn;
private JLabel labelMines;
private JTextArea textRow;
private JTextArea textColumn;
private JTextArea textMines;
public ArrayList<Integer> getArray;
public DifficultySelect()
{
getInput = new JPanel();
startFrame = new JFrame("Select Difficulty:");
easy = new JButton();
medium = new JButton();
hard = new JButton();
custom = new JButton();
labelRow = new JLabel();
labelColumn = new JLabel();
labelMines = new JLabel();
textRow = new JTextArea(5, 20);
textColumn = new JTextArea(5, 20);
textMines = new JTextArea(5, 20);
getArray = new ArrayList<Integer>();
}
public void setDisplay()
{
getInput.setLayout(new BoxLayout(getInput, BoxLayout.PAGE_AXIS));
getInput.setVisible(true);
Dimension buttonSize = new Dimension(300,40);
easy.setText("Easy: 5x5 - 4 Mines");
easy.setMaximumSize(buttonSize);
easy.addActionListener(this);
medium.setText("Medium: 10x10 - 20 Mines");
medium.setMaximumSize(buttonSize);
medium.addActionListener(this);
hard.setText("Hard: 15 x 15 - 50 Mines");
hard.setMaximumSize(buttonSize);
hard.addActionListener(this);
custom.setText("Custom: Enter Rows/Columns/Mines then Click");
custom.setMaximumSize(buttonSize);
custom.addActionListener(this);
labelRow.setText("Enter Row Size: ");
labelColumn.setText("Enter Column Size: ");
labelMines.setText("Enter Amount of Mines:");
textRow.setAlignmentX(0);
textColumn.setAlignmentX(0);
textMines.setAlignmentX(0);
getInput.add(easy);
getInput.add(medium);
getInput.add(hard);
getInput.add(custom);
getInput.add(labelRow);
getInput.add(textRow);
getInput.add(labelColumn);
getInput.add(textColumn);
getInput.add(labelMines);
getInput.add(textMines);
startFrame.add(getInput);
startFrame.setSize(310, 250);
startFrame.setResizable(false);
startFrame.setVisible(true);
startFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
コードの次のブロックがプログラム
に後で呼び出されたときに、私は、メインから呼び出されたときに動作するGUIクラスを呼び出していますが、動作しない方法を示していますprivate DifficultySelect d;
public StartGame()
{
d = new DifficultySelect();
d.setDisplay();
}
私はこの作業を行うためにさまざまな方法を試してきましたが、現在はコンストラクタで呼び出しがありますので、正しいですが白い画面が空白になるStartGame newGame = new StartGame();
というオブジェクトを呼び出していますサイズ、および持っています正しいJFrame名。これは、いくつかの側面が正しく作成されていることを意味します。
[MCVE]または[短く、自己完結型の正しい例](http://www.sscce.org/)を投稿してください。 –
JPanelやJFrameを 'repaint()'しようとしましたか? –
私は再描画を試みましたが、成功しませんでした – Pengoid