|
-
October 28th, 2009, 03:27 PM
#1
[RESOLVED] Trap right-click + control using masks
How to trap right-click + control using masks? I tried but it doesn't work. If I replace BUTTON3_DOWN_MASK with BUTTON1_DOWN_MASK or BUTTON2_DOWN_MASK, it works. Why? I don't understand. @.@
Code:
public class FrameTest extends JFrame {
public FrameTest()
{
setSize(500, 500);
setLocation(300, 200);
setVisible(true);
setFocusable(true);
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e) {
int mask = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON3_DOWN_MASK;
if((e.getModifiersEx() & mask) == mask)
{
JOptionPane.showMessageDialog(null, "I'll be more polite");
}
}
});
}
public static void main(String[] args) {
FrameTest app = new FrameTest();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
I tried like this, it also didn't work. 
Code:
if(e.isControlDown() && e.isMetaDown())
{
JOptionPane.showMessageDialog(null, "I'll be more polite");
}
Thank you.
Last edited by Emerald214; October 28th, 2009 at 03:31 PM.
-
October 29th, 2009, 06:25 AM
#2
Re: Trap right-click + control using masks
 Originally Posted by Emerald214
How to trap right-click + control using masks? I tried but it doesn't work. If I replace BUTTON3_DOWN_MASK with BUTTON1_DOWN_MASK or BUTTON2_DOWN_MASK, it works. Why? I don't understand. @.@
The both versions you posted work fine here. Maybe your mouse has a non-standard configuration.
To arrive at the simple is difficult...
R. Elisha
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|