本文整理汇总了Java中java.awt.event.KeyAdapter类的典型用法代码示例。如果您正苦于以下问题:Java KeyAdapter类的具体用法?Java KeyAdapter怎么用?Java KeyAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyAdapter类属于java.awt.event包,在下文中一共展示了KeyAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateProviderOnSave
import java.awt.event.KeyAdapter; //导入依赖的package包/类
public KeyListener updateProviderOnSave() {
return new KeyAdapter() {
@Override
public void keyPressed(KeyEvent ke) {
if (isSave(ke)) {
onSave();
}
}
};
}
示例2: Presenter
import java.awt.event.KeyAdapter; //导入依赖的package包/类
public Presenter(final QueryUI queryUI) {
super();
setText(Bundle.OQLControllerUI_ControllerName());
setToolTipText(Bundle.OQLControllerUI_ControllerDescr());
setIcon(OQL_ICON);
addKeyListener(new KeyAdapter() {
public void keyTyped(final KeyEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
queryUI.requestFocus();
queryUI.addToQuery(e.getKeyChar());
}
});
}
});
}
示例3: DrawingPanel
import java.awt.event.KeyAdapter; //导入依赖的package包/类
public DrawingPanel(){
super();
setPreferredSize(new Dimension(SCREEN_WIDTH, SCREEN_HEIGHT));
Random ran = new Random();
ball = new Ball(300, 350, 10, 3, -5, Color.BLUE);
paddle = new Paddle((SCREEN_WIDTH/2) - (Paddle.PADDLE_WIDTH/2), SCREEN_HEIGHT - 20, 40);
Thread t = new Thread(new Repainter());
t.start();
setFocusable(true);
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
super.keyPressed(e);
int key = e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT ? e.getKeyCode() : 0;
if(key != 0){
paddle.move(key);
}
}
});
}
示例4: init
import java.awt.event.KeyAdapter; //导入依赖的package包/类
private void init() {
initTransferHandler();
filesTable.addKeyListener(new KeyAdapter() {
/** {@inheritDoc} */
@Override
public void keyPressed(KeyEvent event) {
final int keyCode = event.getKeyCode();
onKeyPressed(keyCode);
}
});
setBorder(EMPTY_BORDER);
setLayout(DcdUiHelper.createBorderLayout());
setOpaque(false);
add(getNorthPanel(), BorderLayout.NORTH);
add(getCenterPanel(), BorderLayout.CENTER);
}
示例5: listenToKeysListener
import java.awt.event.KeyAdapter; //导入依赖的package包/类
private KeyListener listenToKeysListener() {
final KeyAdapter adapter = new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
String word = nameField.getText();
if (word.length() < 18) {
hotelNameTitle.setText(word);
hotelNameTitle.repaint();
} else {
JOptionPane.showMessageDialog(modalFrame, "Hotel name maximum 18 charachter allowed!",
JOptionPane.MESSAGE_PROPERTY, JOptionPane.WARNING_MESSAGE);
}
super.keyTyped(e);
}
};
return adapter;
}
示例6: validatorListener
import java.awt.event.KeyAdapter; //导入依赖的package包/类
private KeyListener validatorListener() {
final KeyAdapter adapter = new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
final EmailValidator validator = new EmailValidator();
if(validator.validate(emailField.getText())) {
markerLbl.setVisible(false);
infoLabel.setText("");
isValid = true;
}
else {
markerLbl.setVisible(true);
infoLabel.setText("Invalid email format!");
}
}
};
return adapter;
}
示例7: getQueryField
import java.awt.event.KeyAdapter; //导入依赖的package包/类
/**
* Constructs and returns the query field.
* Also initialises {@link #queryEdit}.
*/
private JComboBox<String> getQueryField() {
if (this.queryField == null) {
this.queryField = new JComboBox<>(PREFS.get("queryHistory", "").split("\\n"));
this.queryField.setFont(EDIT_FONT);
this.queryField.setEditable(true);
this.queryField.setEnabled(true);
this.queryField.setPrototypeDisplayValue("groove+prolog");
this.queryEdit = (JTextComponent) this.queryField.getEditor().getEditorComponent();
this.queryEdit.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
executeQuery();
giveFocusToNextResultButton();
}
}
});
}
return this.queryField;
}
示例8: initListeners
import java.awt.event.KeyAdapter; //导入依赖的package包/类
protected void initListeners() {
// textView.addComponentListener(new ComponentAdapter(){
// public void componentResized(ComponentEvent e){
// try{
// scroller.getViewport().setViewPosition(
// textView.modelToView(0).getLocation());
// scroller.paintImmediately(textView.getBounds());
// }catch(BadLocationException ble){
// //ignore
// }
// }
// });
// stop control+H from deleting text and transfers the key to the
// parent
textView.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_H && e.isControlDown()) {
getGUI().dispatchEvent(e);
e.consume();
}
}
});
}
示例9: BusyGlassPane
import java.awt.event.KeyAdapter; //导入依赖的package包/类
/**
* GlassPane constructor comment.
*
* @param Container a
*/
protected BusyGlassPane(Component activeComponent, boolean stopClosing)
{
this.stopClosing = stopClosing;
// add adapters that do nothing for keyboard and mouse actions
addMouseListener(new MouseAdapter()
{
// We don't care about any events
});
addKeyListener(new KeyAdapter()
{
// We don't care about any events
});
setActiveComponent(activeComponent);
}
示例10: init
import java.awt.event.KeyAdapter; //导入依赖的package包/类
private void init() {
JScrollPane pane = new JScrollPane();
list = new JList(dataModel);
list.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_F5) {
try {
data = null;
loadImages();
} catch (IOException e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(null, e1
.getLocalizedMessage());
}
list.setModel(dataModel);
list.updateUI();
}
}
});
list.setCellRenderer(new IconRenderer());
pane.setViewportView(list);
for (int i = 0; i < data.size(); i++) {
}
this.add(pane, BorderLayout.CENTER);
}
示例11: GlobalSearchDialog
import java.awt.event.KeyAdapter; //导入依赖的package包/类
public GlobalSearchDialog(SearchFinishResult result) {
setContentPane(contentPane);
setModal(true);
setTitle("Android Source Search");
setSize(800, 500);
this.setLocationRelativeTo(null);
listView.setModel(dataSet);
listView.setFixedCellHeight(25);
listView.addListSelectionListener(this);
listView.addMouseListener(new ListDoubleClickEvent<String>(this));
searchBar.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
startSearch();
}
});
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.searchFinishResult = result;
}
示例12: startRename
import java.awt.event.KeyAdapter; //导入依赖的package包/类
private void startRename() {
// init the text box
final JTextField text = new JTextField();
text.setText(m_reference.getNamableName());
text.setPreferredSize(new Dimension(360, text.getPreferredSize().height));
text.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
switch (event.getKeyCode()) {
case KeyEvent.VK_ENTER:
finishRename(text, true);
break;
case KeyEvent.VK_ESCAPE:
finishRename(text, false);
break;
}
}
});
// find the label with the name and replace it with the text box
JPanel panel = (JPanel)m_infoPanel.getComponent(0);
panel.remove(panel.getComponentCount() - 1);
panel.add(text);
text.grabFocus();
text.selectAll();
redraw();
}
示例13: run
import java.awt.event.KeyAdapter; //导入依赖的package包/类
@Override
public void run() {
if (!streaming) {
addMouseListener(panel);
}
JFrame window = ShowImages.showWindow(panel, PlaySet.class.getSimpleName(),true);
window.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if (e.getKeyChar() == 'x' && previousSet != null) {
System.out.println("'Not a Set!'");
ImageSuppliers.WebcamSaverImageSupplier.save(image);
}
}
});
if (streaming) {
while (true) {
image = imageSupplier.get();
newImage(image);
}
}
}
示例14: DisplayChangeVITest
import java.awt.event.KeyAdapter; //导入依赖的package包/类
DisplayChangeVITest() {
selectDisplayModes();
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
synchronized (lock) {
done = true;
}
}
}
});
sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
sprite.getRaster().getDataBuffer();
Graphics g = sprite.getGraphics();
g.setColor(Color.yellow);
g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
}
示例15: createGui
import java.awt.event.KeyAdapter; //导入依赖的package包/类
private static void createGui() {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tree = new JTree();
frame.add(tree);
tree.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
tree.updateUI();
}
});
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}