내 프로그램에서 문제가 발생하면 코드를 처음 실행하면 완벽하게 실행되지만 새 개체를 만든 다음 창을 표시 한 원래 메서드를 다시 호출하면 창 올바른 제목으로 올바른 크기로 표시되지만 구성 요소를 표시하지 않습니다.새 개체를 만들 때 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