如何在Java(GUI)中锁定框架

时间:2011-05-19 19:45:43

标签: java user-interface frameworks awt

我正在开始一个Java项目,需要一种方法来完全锁定一个框架。锁定我的意思是:

  • 用户无法关闭
  • 用户无法拖动它
  • 用户无法将其最小化
  • 它位于任务栏和其他所有内容之上(除非指定)

基本上,这是全屏收购。

2 个答案:

答案 0 :(得分:3)

尝试使用fullscreen exclusive mode并查看它是否适合您。

答案 1 :(得分:1)

您可以尝试以下内容:

import javax.swing.*;
import java.awt.*;

public class FullScreenTest extends JFrame {

    private GraphicsDevice device;
    private boolean isFullScreen = false;

    public FullScreenTest(GraphicsDevice device) {
        super(device.getDefaultConfiguration());
        this.device = device;
        setTitle("Display Mode Test");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    private void initComponents(Container c) {
        setContentPane(c);
        c.setBackground(Color.RED);
    }

    public void begin() {
        isFullScreen = device.isFullScreenSupported();
        setUndecorated(isFullScreen);
        setResizable(!isFullScreen);
        if (isFullScreen) {
            // Full-screen mode
            device.setFullScreenWindow(this);
            validate();
        } else {
            // Windowed mode
            pack();
            setVisible(true);
        }
    }

    public static void main(String[] args) {
        GraphicsEnvironment env = GraphicsEnvironment.
            getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = env.getScreenDevices();
        FullScreenTest test = new FullScreenTest(devices[0]);
        test.initComponents(test.getContentPane());
        test.begin();
    }
}