我在不止一台计算机上遇到问题(这意味着不仅仅是一台计算机给我带来了问题)。我使用 Eclipse 作为我的 Java IDE,但我似乎无法解决我的问题。我在我的视频游戏的启动器中添加了几个 JButton,当我调试项目时,这些按钮不会出现,直到我将鼠标滑过它们,或者最小化并重新打开窗口。我已经导出了项目并且大部分按钮都可以使用,但有时我仍然需要最小化并重新打开窗口。我不想这样做,因为这将是一个商业视频游戏,人们不应该这样做。
如果您需要,这里是我的启动器窗口的代码:
package net.renderedspoon.sombrero.gui;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import net.renderedspoon.sombrero.Configuration;
import net.renderedspoon.sombrero.Game;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import net.renderedspoon.sombrero.RunGame;
public class Launcher extends JFrame {
private static final long serialVersionUID = 1L;
protected JPanel window = new JPanel();
private JButton play, options, help, exit;
private Rectangle rplay, roptions, rhelp, rexit;
Configuration config = new Configuration();
private int width = 250;
private int height = 350;
protected int button_width = 80;
protected int button_height = 40;
public Launcher(int id) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
setTitle("Launcher || Sombrero");
setSize(new Dimension(width, height));
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().add(window);
setLocationRelativeTo(null);
setResizable(false);
setVisible(true);
window.setLayout(null);
requestFocus();
if(id == 0) {
drawButtons();
}
}
private void drawButtons() {
play = new JButton("Play");
rplay = new Rectangle((width / 2) - (button_width / 2), 50, button_width, button_height);
play.setBounds(rplay);
window.add(play);
options = new JButton("Options");
roptions = new Rectangle((width / 2) - (button_width / 2), 100, button_width, button_height);
options.setBounds(roptions);
window.add(options);
help = new JButton("Help");
rhelp = new Rectangle((width / 2) - (button_width / 2), 150, button_width, button_height);
help.setBounds(rhelp);
window.add(help);
exit = new JButton("Quit");
rexit = new Rectangle((width / 2) - (button_width / 2), 200, button_width, button_height);
exit.setBounds(rexit);
window.add(exit);
play.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(Game.debug) System.out.println("BUTTON HIT: PLAY");
dispose();
new RunGame();
}
});
options.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(Game.debug) System.out.println("BUTTON HIT: OPTIONS");
dispose();
new Options();
}
});
help.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(Game.debug) System.out.println("BUTTON HIT: HELP");
}
});
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(Game.debug) System.out.println("BUTTON HIT: EXIT");
System.exit(0);
}
});
}
}