简体   繁体   English

Java 应用程序的安全桌面模式效果

[英]Secure Desktop Mode effect for java application

Does anyone now how to achieve a "Secure-Desktop Mode" (effect) such as one gets from the Windows Vista/7 UAC consent-blocks?现在有没有人如何实现“安全桌面模式”(效果),例如从 Windows Vista/7 UAC 同意块中获得的?

I assume it is some function which will remove pixels here-and-there (and possibly graying them) and then finally drawing that to screen.我假设这是一些函数,它会在这里和那里删除像素(并可能使它们变灰),然后最终将其绘制到屏幕上。 I would like to apply it to my application to keep the user from doing anything until another user connects to the system (but that is beside the point).我想将它应用于我的应用程序,以防止用户在另一个用户连接到系统之前做任何事情(但这不是重点)。

I would really appreciate the advice.我真的很感激你的建议。

Kind regards,亲切的问候,
A.一种。

EDIT: I was really only looking for this编辑:我真的只是在寻找这个

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

The deferring of input I can do quite well.输入的延迟我可以做得很好。

Thanks to all.谢谢大家。

We use JXLayer for this exact purpose...我们将JXLayer用于这个确切的目的......

在此处输入图像描述在此处输入图像描述

This is really useful as it locks the user out of the given container without locking the out of the application like a GlassPane solution does.这非常有用,因为它可以将用户锁定在给定容器之外,而不会像GlassPane解决方案那样锁定应用程序。 It's like a glass pane for containers;)它就像容器的玻璃板;)

I stole the basic idea for 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);

                }
           });
      }
 }

Instead of re-inventing the wheel try using setEnabled(false) on component to disable it and when connection to system is made call setEnabled(true) to enable component again.不要重新发明轮子,而是尝试在组件上使用setEnabled(false)来禁用它,并在连接到系统时调用setEnabled(true)再次启用组件。

See this example for more which shows a greyed out/un-clickable JButton :有关更多信息,请参见此示例,其中显示了一个灰色/不可点击的JButton

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM