使 Java 应用程序对用户不可见

2024-03-02

我正在尝试找出一种方法使 Java 应用程序对用户不可见。

基本上只是想删除this http://screensnapr.com/e/atyZkF.png

task bar icon <- Image

如何才能做到这一点?

public class TransparentWindow extends JFrame {

public TransparentWindow() {
    initComponents();
}

@SuppressWarnings("unchecked")
private void initComponents() {
    setExtendedState(Frame.MAXIMIZED_BOTH);
    setResizable(false);
    setUndecorated(true);
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    setAlwaysOnTop(true);
    System.setProperty("sun.java2d.noddraw", "true");
    WindowUtils.setWindowTransparent(this, true);
    WindowUtils.setWindowAlpha(this, 0.6f);
}

public static void main(String[] args) {
    new TransparentWindow().setVisible(true);
}
}

我似乎找到了答案,只需输入该行setVisible(false);进入注释,您将看到实际的程序,取消注释该行以查看没有留下任何痕迹,据我所知,Java 程序正在某处运行,直到您不手动将图标添加到系统托盘中。此外,如何从任务管理器中删除您的应用程序,这个问题仍然存在,尽管您可以删除所述图标,正如您在问题中指出的那样。

import javax.swing.*;

public class TransparentWindow extends JFrame 
{
    public TransparentWindow() 
    {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    private void initComponents() 
    {
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        setResizable(false);
        setUndecorated(true);
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        setAlwaysOnTop(true);
        setOpacity(0.8f);
        setSize(200, 200);
        //System.setProperty("sun.java2d.noddraw", "true");
        //WindowUtils.setWindowTransparent(this, true);
        //WindowUtils.setWindowAlpha(this, 0.6f);
        setVisible(true);
        setVisible(false);

        JOptionPane.showMessageDialog(this, "It is working!", "Guess : ", JOptionPane.INFORMATION_MESSAGE); 
    }

    public static void main(String[] args) 
    {
        TransparentWindow tw = new TransparentWindow();
    }
}

这是运行该程序时我的桌面快照,请参阅任务栏

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使 Java 应用程序对用户不可见 的相关文章

随机推荐