Я хочу отображать несколько JFrame с задержкой в несколько секунд в цикле, нажав кнопку. Рамки бывают, но они достаточно белые, с заголовком, но без тела (кнопки не видны). Без цикла, следовательно, один раз вызывая JFrame, нет проблем. Что мне делать? Есть ли у вас еще одна идея?
Основной класс:
public class Game3 {
game3.NewJFrame2 start_frame = new game3.NewJFrame2();
public Game3() throws InterruptedException {
this.start_frame.setSize(500,500);
start_frame.setVisible(true);
final JButton enter = new JButton("Enter");
enter.setBounds(10,10,50,50);
start_frame.add(enter);
enter.setVisible(true);
enter.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
start_frame.dispose();
try {
new Play();
} catch (InterruptedException ex) {
Logger.getLogger(Game3.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
public static void main(String[] args) throws InterruptedException {
new Game3();
}
}
и игровой класс:
public class Play {
game3.NewJFrame2 start_frame1 = new game3.NewJFrame2();
public Play() throws InterruptedException {
this.select_rnd_word();
}
public static void select_rnd_word() throws InterruptedException {
for (int i = 0; i < 5; i++) {
game3.NewJFrame2 frame = new game3.NewJFrame2();
frame.setSize(200, 200);
JButton b = new JButton("A");
b.setBounds(0, 0, 30, 30);
frame.add(b);
b.setVisible(true);
frame.setVisible(true);
Thread.sleep(2000);
frame.dispose();
}
}
}
В следующем коде тоже есть эта проблема:
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i < 3; i++) {
new Game3();
}
}




Одна из идей заключается в перемещении 'new Play ()' из ActionListener.
enter.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
start_frame.dispose();
}
});
Thread.sleep(10000);
start_frame.dispose();
new Play();
Эта проблема решена путем создания новой темы.
enter.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
start_frame.dispose();
new Thread() {
@Override
public void run() {
try {
new Play();
} catch (InterruptedException ex) {
Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex);
}
}
}.start();
}
});
для получения дополнительной информации: Поток отправки событий
Я решил эту идею, но до сих пор не знаю проблемы
new Play()сActionListener.