java.awt.JFrame中有一个方法setUndecorated(boolean),能够设置窗口是否设置边框。
下面的程序能够实现全屏:
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
public class FullScreen extends JFrame {
public FullScreen() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); //获取屏幕大小
setUndecorated(true);
setSize(screenSize.width, screenSize.height);
this.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { //按下ESC时退出程序
System.exit(0);
}
}
});
}
public static void main(String[] args) { JFrame f = new FullScreen(); f.setDefaultCloseOperation(EXIT_ON_CLOSE); f.setVisible(true); }}