下面列出了java.awt.Toolkit#addAWTEventListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
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);
}
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;
}
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;
}
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;
}
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 );
}
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;
}
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;
}
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();
}
});
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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);
}
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);
}
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);
}
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);
}