2012-10-19 41 views
2

现在是否有人能够实现“安全桌面模式”(效果),例如从Windows Vista/7 UAC同意块获得?Java应用程序的安全桌面模式效果

我认为这是一个函数,它会去除像素(并可能灰化它们),然后最终将其绘制到屏幕上...我想将它应用于我的应用程序以防止用户干扰任何东西,直到另一个用户连接到系统(但这是除了点)

我真的很感激的建议。

亲切的问候

一个

编辑:我真的只是寻找这个

 graphicsFX.setColor(new Color(0, 0, 0, 0.8f)); 
     graphicsFX.fillRect(0, 0, 800, 600); 

输入我可以做的相当不错的defering ...

感谢所有...

+3

尝试玻璃平面 http://stackoverflow.com/questions/3886264/non-blocking -modal-swing-progress-dialog –

+0

@ j-mcnally:请发表您的评论作为答案,以便我可以接受 - 从该链接的链接给了我主意......荣誉 –

+0

我不能在技术上你的问题是有点一个副本。只是以不同的方式问。我会建议删除你的问题,并只是upvoting重复。 –

回答

5

我们使用JXLayer这个确切的目的...

enter image description hereenter image description here

这是非常有用的,因为它将用户锁定在给定容器之外,而不会像那样锁定应用程序解决方案。这就像集装箱玻璃板;)

我偷了基本思路为here

public class JXLayerTest { 

     public static void main(String[] args) { 
      new JXLayerTest(); 
     } 

     public JXLayerTest() { 
      EventQueue.invokeLater(new Runnable() { 
       @Override 
       public void run() { 
        try { 
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
        } catch (ClassNotFoundException ex) { 
        } catch (InstantiationException ex) { 
        } catch (IllegalAccessException ex) { 
        } catch (UnsupportedLookAndFeelException ex) { 
        } 

        final LockableUI ui = new LockableUI(); 
        JPanel panel = new JPanel(new GridBagLayout()); 
        buildUI(panel); 

        // This stolen directly from the JXLayer lockable blog       
        JXLayer layer = new JXLayer(panel, ui); 

        // Java2D grayScale BufferedImageOp 
        ColorConvertOp grayScale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); 
        // wrap it with the jxlayer's BufferedImageOpEffect 
        BufferedImageOpEffect effect = new BufferedImageOpEffect(grayScale); 
        // set it as the locked effect   
        ui.setLockedEffects(effect); 
        ui.setLocked(false); 

        JFrame frame = new JFrame(); 
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        frame.setLayout(new BorderLayout()); 
        frame.add(layer); 

        JPanel panelButtons = new JPanel(new GridBagLayout()); 

        final JButton lock = new JButton("Lock"); 
        lock.addActionListener(new ActionListener() { 
          @Override 
          public void actionPerformed(ActionEvent e) { 
           boolean locked = !ui.isLocked(); 
           ui.setLocked(locked); 
           lock.setText(locked ? "Unlock" : "Lock"); 

          } 
        }); 

        panelButtons.add(lock); 
        frame.add(panelButtons, BorderLayout.SOUTH); 

        frame.pack(); 
        frame.setLocationRelativeTo(null); 
        frame.setVisible(true); 
       } 

       protected void buildUI(JPanel panel) { 
        GridBagConstraints gbc = new GridBagConstraints(); 
        gbc.gridx = 0; 
        gbc.gridy = 0; 

        JLabel label = new JLabel(); 
        try { 
          BufferedImage image = ImageIO.read(new File("megatokyo.png")); 
          label.setIcon(new ImageIcon(image)); 
        } catch (IOException ex) { 
          label.setText("Nothing to see here"); 
        } 

        panel.add(label, gbc); 

        JButton button = new JButton("Clickl me"); 
        button.addActionListener(new ActionListener() { 
          @Override 
          public void actionPerformed(ActionEvent e) { 
           JOptionPane.showMessageDialog(null, "Clicked"); 
          } 
        }); 

        gbc.gridy++; 
        panel.add(button, gbc); 

       } 
      }); 
     } 
} 
+0

+1喜欢这个例子和JXLayer :) –

+1

@DavidKroukamp当我第一次开始设置它时,它始终保持着我的头脑,将面板包裹在图层和图层中:P - 一旦我得到它安装,这真棒 – MadProgrammer

+0

+1伟大的例子! :) – tenorsax

3

而不是重新发明轮使用setEnabled(false)上的组件将其禁用,并在连接到系统时调用setEnabled(true)以再次启用组件。

this例如更多其显示了灰色/非点击JButton

enter image description here

+1

这实际上并不是我的意思 - 但我真的很喜欢这个效果,所以我打算用这种方法拒绝输入 –

+0

@AidenStrydom + 1很高兴帮助:) –