我正在嘗試爲遊戲創建標題屏幕。到目前爲止,一切都很順利,只是這個JFrame拒絕關閉。我在不同的JFrame中使用不同的JPanel中的JButton。我得到的錯誤Static setVisible JFrame
「不能使靜態參考從式窗口的非靜態方法 調用setVisible(布爾)」
package ZombieFunTimeGo;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SuperZombieFunTimeGo extends JFrame{
private TitleScreen ts;
boolean visible;
public SuperZombieFunTimeGo() {
add(new TitleScreen());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(1280, 720);
ts = new TitleScreen();
Container pane = getContentPane();
pane.add(ts);
setContentPane(ts);
setLocationRelativeTo(null);
setTitle("Super Zombie Fun Time Go!");
setResizable(false);
setVisible(true);
}
public void pullThePlug() {
WindowEvent wev = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
}
public static void main(String[] args) {
new SuperZombieFunTimeGo();
}
}
*「我想創建一個遊戲的標題屏幕。」*使用['SplashScreen'](http://docs.oracle.com/javase/7/docs/ api/java/awt/SplashScreen.html)。 – 2012-07-29 02:33:12
pullThePlug有什麼意義?只需setVisibe(false)。您需要確保您將標題框的有效參考傳遞給負責關閉它的類 – MadProgrammer 2012-07-29 04:34:32