Java Code Examples for java.awt.Toolkit#addAWTEventListener()

The following examples show how to use java.awt.Toolkit#addAWTEventListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainWindow.java    From jadx with Apache License 2.0 6 votes vote down vote up
private void registerMouseNavigationButtons() {
	Toolkit toolkit = Toolkit.getDefaultToolkit();
	toolkit.addAWTEventListener(event -> {
		if (event instanceof MouseEvent) {
			MouseEvent mouseEvent = (MouseEvent) event;
			if (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED) {
				int rawButton = mouseEvent.getButton();
				if (rawButton <= 3) {
					return;
				}
				int button = remapMouseButton(rawButton);
				switch (button) {
					case 4:
						tabbedPane.navBack();
						break;
					case 5:
						tabbedPane.navForward();
						break;
				}
			}
		}
	}, AWTEvent.MOUSE_EVENT_MASK);
}
 
Example 2
Source File: ScreenSizeChangeTest.java    From haxademic with MIT License 6 votes vote down vote up
protected void firstFrame() {
	GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	screenSize = ge.getMaximumWindowBounds();

	Toolkit toolkit = Toolkit.getDefaultToolkit();
	toolkit.addAWTEventListener(new AWTEventListener() {

		@Override
		public void eventDispatched(AWTEvent event) {
			// take a look at http://stackoverflow.com/questions/10123735/get-effective-screen-size-from-java
			
			Rectangle newSize = ge.getMaximumWindowBounds();
			if (newSize.width != screenSize.width || newSize.height != screenSize.height) {
				screenSize.setSize(newSize.width, newSize.height);
				resize();
			}
		}
	}, AWTEvent.PAINT_EVENT_MASK);

}
 
Example 3
Source File: RemoteControlFrame.java    From oim-fx with MIT License 5 votes vote down vote up
private void initEvent() {

		class AWTEventListenerImpl implements AWTEventListener {
			@Override
			public void eventDispatched(AWTEvent event) {
				if (event.getClass() == KeyEvent.class) {
					// 被处理的事件是键盘事件.
					KeyEvent keyEvent = (KeyEvent) event;
					if (keyEvent.getID() == KeyEvent.KEY_PRESSED) {
						// 按下时你要做的事情
						keyPressed(keyEvent);
					} else if (keyEvent.getID() == KeyEvent.KEY_RELEASED) {
						// 放开时你要做的事情
						keyReleased(keyEvent);
					}
				}
			}

		}

		Toolkit tk = Toolkit.getDefaultToolkit();  
        tk.addAWTEventListener(new AWTEventListenerImpl(), AWTEvent.KEY_EVENT_MASK);  
        label.addMouseListener(new MouseAdapter() {
        	 public void mouseClicked(MouseEvent e) {
        		 panel.requestFocus();
        	 }
		});
	}
 
Example 4
Source File: BasicLookAndFeel.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 5
Source File: BasicLookAndFeel.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 6
Source File: BasicLookAndFeel.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 7
Source File: BasicLookAndFeel.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 8
Source File: BasicLookAndFeel.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 9
Source File: BasicLookAndFeel.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 10
Source File: BasicLookAndFeel.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 11
Source File: BasicLookAndFeel.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 12
Source File: BasicLookAndFeel.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 13
Source File: BasicLookAndFeel.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 14
Source File: DockingWindowsContextSensitiveHelpListener.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private DockingWindowsContextSensitiveHelpListener() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    AWTEventListener listener = new AWTEventListener() {            
        public void eventDispatched( AWTEvent event ) {
            DockingWindowManager.setMouseOverObject( event.getSource() );
        }
    }; 
    toolkit.addAWTEventListener( listener, AWTEvent.MOUSE_MOTION_EVENT_MASK );
}
 
Example 15
Source File: BasicLookAndFeel.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 16
Source File: BasicLookAndFeel.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Object run() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    if(invocator == null) {
        tk.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK);
    } else {
        tk.removeAWTEventListener(invocator);
    }
    // Return value not used.
    return null;
}
 
Example 17
Source File: PinPadPanelImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public PinPadPanelImpl() {
   this.setLayout((LayoutManager)null);
   Toolkit toolkit = this.getToolkit();
   toolkit.addAWTEventListener(new PinPadPanelImpl.KeyBoardAWTEventListener(null), 8L);
   Font fntButton = new Font("Arial", 1, 35);
   Font fntLabel = new Font("Arial", 1, 12);
   Font fntField = new Font("Arial", 1, 35);
   Color clrGreen = new Color(128, 175, 60);
   Color clrRed = Color.red;
   Insets marginButton = new Insets(0, 0, 0, 0);
   this.add(this.createButton("1", fntButton, marginButton, new Rectangle(22, 126, 75, 50)));
   this.add(this.createButton("2", fntButton, marginButton, new Rectangle(104, 126, 75, 50)));
   this.add(this.createButton("3", fntButton, marginButton, new Rectangle(192, 126, 75, 50)));
   this.add(this.createButton("4", fntButton, marginButton, new Rectangle(22, 187, 75, 50)));
   this.add(this.createButton("5", fntButton, marginButton, new Rectangle(104, 187, 75, 50)));
   this.add(this.createButton("6", fntButton, marginButton, new Rectangle(192, 187, 75, 50)));
   this.add(this.createButton("7", fntButton, marginButton, new Rectangle(22, 250, 75, 50)));
   this.add(this.createButton("8", fntButton, marginButton, new Rectangle(104, 250, 75, 50)));
   this.add(this.createButton("9", fntButton, marginButton, new Rectangle(192, 250, 75, 50)));
   this.add(this.createButton("0", fntButton, marginButton, new Rectangle(22, 311, 75, 50)));
   this.add(this.createButton("<", fntButton, marginButton, new Rectangle(104, 311, 75, 50), new ActionListener() {
      public void actionPerformed(ActionEvent e) {
         PinPadPanelImpl.this.processBackspace();
      }
   }));
   this.btnGo = new JButton("GO");
   this.btnGo.setForeground(clrGreen);
   this.btnGo.setMargin(marginButton);
   this.btnGo.setFont(fntButton);
   this.btnGo.setBounds(192, 311, 75, 50);
   this.btnGo.setEnabled(false);
   this.add(this.btnGo);
   this.txtPassWord = new JPasswordField();
   this.txtPassWord.setHorizontalAlignment(0);
   this.txtPassWord.setFocusable(false);
   this.txtPassWord.setFont(fntField);
   this.txtPassWord.setText("");
   this.txtPassWord.setBorder(new LineBorder(Color.GRAY, 1, true));
   this.txtPassWord.setBounds(22, 65, 245, 50);
   this.add(this.txtPassWord);
   JLabel lblPinCode = new JLabel("Please enter your pincode to authenticate yourself.");
   lblPinCode.setFont(fntLabel);
   lblPinCode.setBounds(22, 40, 245, 14);
   this.add(lblPinCode);
   this.setFocusable(true);
   this.lblRetriesleft = new JLabel("Retries left: ");
   this.lblRetriesleft.setFont(fntLabel);
   this.lblRetriesleft.setForeground(clrRed);
   this.lblRetriesleft.setBounds(22, 15, 245, 14);
   this.lblRetriesleft.setVisible(false);
   this.add(this.lblRetriesleft);
}
 
Example 18
Source File: PinPadPanelImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public PinPadPanelImpl() {
   this.setLayout((LayoutManager)null);
   Toolkit toolkit = this.getToolkit();
   toolkit.addAWTEventListener(new PinPadPanelImpl.KeyBoardAWTEventListener(null), 8L);
   Font fntButton = new Font("Arial", 1, 35);
   Font fntLabel = new Font("Arial", 1, 12);
   Font fntField = new Font("Arial", 1, 35);
   Color clrGreen = new Color(128, 175, 60);
   Color clrRed = Color.red;
   Insets marginButton = new Insets(0, 0, 0, 0);
   this.add(this.createButton("1", fntButton, marginButton, new Rectangle(22, 126, 75, 50)));
   this.add(this.createButton("2", fntButton, marginButton, new Rectangle(104, 126, 75, 50)));
   this.add(this.createButton("3", fntButton, marginButton, new Rectangle(192, 126, 75, 50)));
   this.add(this.createButton("4", fntButton, marginButton, new Rectangle(22, 187, 75, 50)));
   this.add(this.createButton("5", fntButton, marginButton, new Rectangle(104, 187, 75, 50)));
   this.add(this.createButton("6", fntButton, marginButton, new Rectangle(192, 187, 75, 50)));
   this.add(this.createButton("7", fntButton, marginButton, new Rectangle(22, 250, 75, 50)));
   this.add(this.createButton("8", fntButton, marginButton, new Rectangle(104, 250, 75, 50)));
   this.add(this.createButton("9", fntButton, marginButton, new Rectangle(192, 250, 75, 50)));
   this.add(this.createButton("0", fntButton, marginButton, new Rectangle(22, 311, 75, 50)));
   this.add(this.createButton("<", fntButton, marginButton, new Rectangle(104, 311, 75, 50), new ActionListener() {
      public void actionPerformed(ActionEvent e) {
         PinPadPanelImpl.this.processBackspace();
      }
   }));
   this.btnGo = new JButton("GO");
   this.btnGo.setForeground(clrGreen);
   this.btnGo.setMargin(marginButton);
   this.btnGo.setFont(fntButton);
   this.btnGo.setBounds(192, 311, 75, 50);
   this.btnGo.setEnabled(false);
   this.add(this.btnGo);
   this.txtPassWord = new JPasswordField();
   this.txtPassWord.setHorizontalAlignment(0);
   this.txtPassWord.setFocusable(false);
   this.txtPassWord.setFont(fntField);
   this.txtPassWord.setText("");
   this.txtPassWord.setBorder(new LineBorder(Color.GRAY, 1, true));
   this.txtPassWord.setBounds(22, 65, 245, 50);
   this.add(this.txtPassWord);
   JLabel lblPinCode = new JLabel("Please enter your pincode to authenticate yourself.");
   lblPinCode.setFont(fntLabel);
   lblPinCode.setBounds(22, 40, 245, 14);
   this.add(lblPinCode);
   this.setFocusable(true);
   this.lblRetriesleft = new JLabel("Retries left: ");
   this.lblRetriesleft.setFont(fntLabel);
   this.lblRetriesleft.setForeground(clrRed);
   this.lblRetriesleft.setBounds(22, 15, 245, 14);
   this.lblRetriesleft.setVisible(false);
   this.add(this.lblRetriesleft);
}
 
Example 19
Source File: PinPadPanelImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public PinPadPanelImpl() {
   this.setLayout((LayoutManager)null);
   Toolkit toolkit = this.getToolkit();
   toolkit.addAWTEventListener(new PinPadPanelImpl.KeyBoardAWTEventListener(), 8L);
   Font fntButton = new Font("Arial", 1, 35);
   Font fntLabel = new Font("Arial", 1, 12);
   Font fntField = new Font("Arial", 1, 35);
   Color clrGreen = new Color(128, 175, 60);
   Color clrRed = Color.red;
   Insets marginButton = new Insets(0, 0, 0, 0);
   this.add(this.createButton("1", fntButton, marginButton, new Rectangle(22, 126, 75, 50)));
   this.add(this.createButton("2", fntButton, marginButton, new Rectangle(104, 126, 75, 50)));
   this.add(this.createButton("3", fntButton, marginButton, new Rectangle(192, 126, 75, 50)));
   this.add(this.createButton("4", fntButton, marginButton, new Rectangle(22, 187, 75, 50)));
   this.add(this.createButton("5", fntButton, marginButton, new Rectangle(104, 187, 75, 50)));
   this.add(this.createButton("6", fntButton, marginButton, new Rectangle(192, 187, 75, 50)));
   this.add(this.createButton("7", fntButton, marginButton, new Rectangle(22, 250, 75, 50)));
   this.add(this.createButton("8", fntButton, marginButton, new Rectangle(104, 250, 75, 50)));
   this.add(this.createButton("9", fntButton, marginButton, new Rectangle(192, 250, 75, 50)));
   this.add(this.createButton("0", fntButton, marginButton, new Rectangle(22, 311, 75, 50)));
   this.add(this.createButton("<", fntButton, marginButton, new Rectangle(104, 311, 75, 50), new ActionListener() {
      public void actionPerformed(ActionEvent e) {
         PinPadPanelImpl.this.processBackspace();
      }
   }));
   this.btnGo = new JButton("GO");
   this.btnGo.setForeground(clrGreen);
   this.btnGo.setMargin(marginButton);
   this.btnGo.setFont(fntButton);
   this.btnGo.setBounds(192, 311, 75, 50);
   this.btnGo.setEnabled(false);
   this.add(this.btnGo);
   this.txtPassWord = new JPasswordField();
   this.txtPassWord.setHorizontalAlignment(0);
   this.txtPassWord.setFocusable(false);
   this.txtPassWord.setFont(fntField);
   this.txtPassWord.setText("");
   this.txtPassWord.setBorder(new LineBorder(Color.GRAY, 1, true));
   this.txtPassWord.setBounds(22, 65, 245, 50);
   this.add(this.txtPassWord);
   JLabel lblPinCode = new JLabel("Please enter your pincode to authenticate yourself.");
   lblPinCode.setFont(fntLabel);
   lblPinCode.setBounds(22, 40, 245, 14);
   this.add(lblPinCode);
   this.setFocusable(true);
   this.lblRetriesleft = new JLabel("Retries left: ");
   this.lblRetriesleft.setFont(fntLabel);
   this.lblRetriesleft.setForeground(clrRed);
   this.lblRetriesleft.setBounds(22, 15, 245, 14);
   this.lblRetriesleft.setVisible(false);
   this.add(this.lblRetriesleft);
}
 
Example 20
Source File: PinPadPanelImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public PinPadPanelImpl() {
   this.setLayout((LayoutManager)null);
   Toolkit toolkit = this.getToolkit();
   toolkit.addAWTEventListener(new PinPadPanelImpl.KeyBoardAWTEventListener(), 8L);
   Font fntButton = new Font("Arial", 1, 35);
   Font fntLabel = new Font("Arial", 1, 12);
   Font fntField = new Font("Arial", 1, 35);
   Color clrGreen = new Color(128, 175, 60);
   Color clrRed = Color.red;
   Insets marginButton = new Insets(0, 0, 0, 0);
   this.add(this.createButton("1", fntButton, marginButton, new Rectangle(22, 126, 75, 50)));
   this.add(this.createButton("2", fntButton, marginButton, new Rectangle(104, 126, 75, 50)));
   this.add(this.createButton("3", fntButton, marginButton, new Rectangle(192, 126, 75, 50)));
   this.add(this.createButton("4", fntButton, marginButton, new Rectangle(22, 187, 75, 50)));
   this.add(this.createButton("5", fntButton, marginButton, new Rectangle(104, 187, 75, 50)));
   this.add(this.createButton("6", fntButton, marginButton, new Rectangle(192, 187, 75, 50)));
   this.add(this.createButton("7", fntButton, marginButton, new Rectangle(22, 250, 75, 50)));
   this.add(this.createButton("8", fntButton, marginButton, new Rectangle(104, 250, 75, 50)));
   this.add(this.createButton("9", fntButton, marginButton, new Rectangle(192, 250, 75, 50)));
   this.add(this.createButton("0", fntButton, marginButton, new Rectangle(22, 311, 75, 50)));
   this.add(this.createButton("<", fntButton, marginButton, new Rectangle(104, 311, 75, 50), new ActionListener() {
      public void actionPerformed(ActionEvent e) {
         PinPadPanelImpl.this.processBackspace();
      }
   }));
   this.btnGo = new JButton("GO");
   this.btnGo.setForeground(clrGreen);
   this.btnGo.setMargin(marginButton);
   this.btnGo.setFont(fntButton);
   this.btnGo.setBounds(192, 311, 75, 50);
   this.btnGo.setEnabled(false);
   this.add(this.btnGo);
   this.txtPassWord = new JPasswordField();
   this.txtPassWord.setHorizontalAlignment(0);
   this.txtPassWord.setFocusable(false);
   this.txtPassWord.setFont(fntField);
   this.txtPassWord.setText("");
   this.txtPassWord.setBorder(new LineBorder(Color.GRAY, 1, true));
   this.txtPassWord.setBounds(22, 65, 245, 50);
   this.add(this.txtPassWord);
   JLabel lblPinCode = new JLabel("Please enter your pincode to authenticate yourself.");
   lblPinCode.setFont(fntLabel);
   lblPinCode.setBounds(22, 40, 245, 14);
   this.add(lblPinCode);
   this.setFocusable(true);
   this.lblRetriesleft = new JLabel("Retries left: ");
   this.lblRetriesleft.setFont(fntLabel);
   this.lblRetriesleft.setForeground(clrRed);
   this.lblRetriesleft.setBounds(22, 15, 245, 14);
   this.lblRetriesleft.setVisible(false);
   this.add(this.lblRetriesleft);
}