对Java应用程序的安全桌面模式效果 [英] Secure Desktop Mode effect for java application

查看:142
本文介绍了对Java应用程序的安全桌面模式效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我现在有没有人知道如何实现安全桌面模式(效果),例如从Windows Vista / 7 UAC同意块中获得?假设它是一些函数,它将会在这里去掉像素(并可能灰化它们),然后最终将其绘制到屏幕上...我想将它应用到我的应用程序中,以防止用户执行任何操作,直到另一个用户连接到系统(但除此之外)



我真的很感激这个建议。



问候



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

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

延迟输入我可以做得很好...

感谢所有人。

我们使用

  public class JXLayerTest {

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

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

LockableUI ui = new LockableUI();
JPanel panel = new JPanel(new GridBagLayout());
buildUI(面板);

//直接从JXLayer可锁博客中盗取
JXLayer图层= new JXLayer(panel,ui);

// Java2D grayScale BufferedImageOp
ColorConvertOp grayScale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY),null);
//使用jxlayer的BufferedImageOpEffect
包装它BufferedImageOpEffect effect = new BufferedImageOpEffect(grayScale);
//将其设为锁定效果
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();
尝试{
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);

}
});
}
}


Does anyone now how to achieve a "Secure-Desktop Mode" (effect) such as one gets from the Windows Vista/7 UAC consent-blocks?

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 the another user connects to the system (but that is besides the point)

I would really appreciate the advise.

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 defering of input i can do quite well...

Thanks for all....

解决方案

We use JXLayer for this exact purpose...

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. 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);

                }
           });
      }
 }

这篇关于对Java应用程序的安全桌面模式效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆