我創建的JFrame窗口在所謂的核心,然後在主創造這樣的窗口中的一個類:的JFrame - 從KeyListener的類訪問我的窗口
Core window = new Core("GAME1", 0, 0, true, true);
但後來我決定使用的KeyListener,我創建了另一個類所謂Core_ControlsL: 我的問題是,在這裏:
else if(keyCode == 113)
{
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this.window);
}
我無法弄清楚如何這樣,當我按下F2它進入全屏再次訪問窗口。
import javax.swing.UnsupportedLookAndFeelException;
這是我main.java:
public class Main
{
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
{
Core window = new Core("GAME1", 0, 0, true, true);
}
}
這是Core.java:
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
public class Core extends JFrame implements ActionListener
{
private final String Game_Title;
private int Window_Width;
private int Window_Height;
private boolean isVisible;
private boolean isResizeable;
public Core(String Game_Title, int Window_Width, int Window_Height, boolean isVisible, boolean isResizeable) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
this.Game_Title = Game_Title;
this.Window_Width = Window_Height;
this.Window_Height = Window_Height;
this.isResizeable = isResizeable;
this.isVisible = isVisible;
//Create JFrame
JFrame window = new JFrame(Game_Title);
window.setSize(Window_Width, Window_Height);
window.setResizable(isResizeable);
window.setExtendedState(JFrame.MAXIMIZED_BOTH);
window.setVisible(isVisible);
window.addKeyListener(new Core_Controls());
window.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(window); // make window full screen
}
@Override
public void actionPerformed(ActionEvent e)
{
}
}
而且Core_Controls.java:
import java.awt.GraphicsEnvironment;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class Core_Controls implements KeyListener
{
@Override
public void keyTyped(KeyEvent e)
{
}
@Override
public void keyPressed(KeyEvent e)
{
int keyCode;
keyCode = e.getKeyCode();
System.out.println(keyCode); // LLLLLL
if(keyCode == 112)
{
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null);
}
else if(keyCode == 113)
{
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null);
}
}
@Override
public void keyReleased(KeyEvent e)
{
}
}
仍試圖找出這一個.... – 2014-10-07 21:12:23