當前位置: 首頁>>代碼示例>>Java>>正文


Java KeyAdapter類代碼示例

本文整理匯總了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();
            }
        }
    };
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:11,代碼來源:StyledEditor.java

示例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());
                }
            });
        }
    });
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:OQLControllerUI.java

示例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);
            }
        }
    });
}
 
開發者ID:vramdhanie,項目名稱:pong,代碼行數:21,代碼來源:DrawingPanel.java

示例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);
}
 
開發者ID:evernat,項目名稱:dead-code-detector,代碼行數:21,代碼來源:ParametersPanel.java

示例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;
}
 
開發者ID:Coder-ACJHP,項目名稱:Hotel-Properties-Management-System,代碼行數:18,代碼來源:HotelPropertiesWindow.java

示例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;
}
 
開發者ID:Coder-ACJHP,項目名稱:Hotel-Properties-Management-System,代碼行數:19,代碼來源:AddUserWindow.java

示例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;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:25,代碼來源:PrologDisplay.java

示例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();
      }
    }
  });
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:26,代碼來源:TextualDocumentView.java

示例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);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:BusyGlassPane.java

示例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);
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:27,代碼來源:IconPreviewPanel.java

示例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;
}
 
開發者ID:pengwei1024,項目名稱:AndroidSourceViewer,代碼行數:20,代碼來源:GlobalSearchDialog.java

示例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();
}
 
開發者ID:cccssw,項目名稱:enigma-vk,代碼行數:31,代碼來源:Gui.java

示例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);
        }
    }
}
 
開發者ID:tomwhite,項目名稱:set-game,代碼行數:24,代碼來源:PlaySet.java

示例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());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:DisplayChangeVITest.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:bug6578666.java


注:本文中的java.awt.event.KeyAdapter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。