当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent类代码示例

本文整理汇总了Java中java.awt.event.KeyEvent的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent类的具体用法?Java KeyEvent怎么用?Java KeyEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


KeyEvent类属于java.awt.event包,在下文中一共展示了KeyEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: keyPressed

import java.awt.event.KeyEvent; //导入依赖的package包/类
public void keyPressed(KeyEvent e) {
    if (e.getKeyChar() == ' ') {
        JTree tree = (JTree) e.getSource();
        TreePath path = tree.getSelectionPath();
        if( null == path )
            return;

        Node node = Visualizer.findNode( path.getLastPathComponent() );
        if( null == node )
            return;
        
        boolean isSelected = settings.isNodeVisible( node );
        settings.setNodeVisible( node, !isSelected );
        tree.repaint();
        
        e.consume();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:CheckListener.java

示例2: keyReleased

import java.awt.event.KeyEvent; //导入依赖的package包/类
public void keyReleased(KeyEvent e) {
	FlagTable t=(FlagTable)e.getSource();
    int id = e.getID();
    if(id == e.KEY_RELEASED && e.getKeyChar() == e.VK_BACK_SPACE)
    {
        if(t.getSelectedRow() != -1)
            for(int i:t.getSelectedRows()){
            	GeometryImage gl=((ComplexEditVDSVectorLayer)layer).getGeometriclayer();
            	Geometry geom=gl.getGeometries().get(i);
            	deleted.add(0,geom);
                attrDeleted.add(0,(gl).getAttributes(geom));
            	((GeometricInteractiveVDSLayerModel)t.getModel()).removeSelection(i);
            	glm.fireTableDataChanged();
            	if(gl.getGeometries().size()>0){
            		int sel=0;
            		if(i>0&&i<(gl.getGeometries().size()-1))
            			sel=i;
            		((GeometricInteractiveVDSLayerModel)t.getModel()).changeSelection(sel, display);
            		glm.changeSelection(sel, true);
            		((JTable)e.getSource()).setRowSelectionInterval(sel,sel);
            	}
            }
        this.repaint();
        ((GeometricInteractiveVDSLayerModel)t.getModel()).changeSelection(t.getSelectedRow(), display);
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:27,代码来源:GeometricInteractiveVDSLayerPanel.java

示例3: keyPressed

import java.awt.event.KeyEvent; //导入依赖的package包/类
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode()==KeyEvent.VK_ENTER){
        String sorgu = "SELECT * FROM passbox_db.users_tb where username=? and password=?;";
    try {
        pst=baglanti.prepareStatement(sorgu);
        pst.setString(1, username_txt.getText());
        pst.setString(2, password_txt.getText());
        gelenveri=pst.executeQuery();
        if(gelenveri.next()){
            JOptionPane.showMessageDialog(null,"Başarılı giriş!");
            this.setVisible(false);
            User_Control_Panel_Page frame = new User_Control_Panel_Page();
            frame.setVisible(true);
        }
        else{
        JOptionPane.showMessageDialog(null,"Başarısız giriş!");
        }
    } catch (SQLException ex) {
        JOptionPane.showConfirmDialog(null, "Sorgu da hata var!");
    }
    }
}
 
开发者ID:ismailtasdelen,项目名称:PassBox,代码行数:23,代码来源:Login_Page.java

示例4: CopySVGMenuItem

import java.awt.event.KeyEvent; //导入依赖的package包/类
public CopySVGMenuItem(final FlagFrame frame) {
	setText("Copy SVG");
	if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_S);
	setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputUtils.META_SHIFT_MASK));
	if (frame == null) {
		setEnabled(false);
	} else {
		addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SVGExporter s = new SVGExporter(frame.getFlagFile(), frame.getFlag());
				String svg = s.exportToString(frame.getViewerWidth(), frame.getViewerHeight(), frame.getGlaze());
				StringSelection ss = new StringSelection(svg);
				Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
				cb.setContents(ss, ss);
			}
		});
	}
}
 
开发者ID:kreativekorp,项目名称:vexillo,代码行数:19,代码来源:CopySVGMenuItem.java

示例5: valueTextFieldKeyPressed

import java.awt.event.KeyEvent; //导入依赖的package包/类
private void valueTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_valueTextFieldKeyPressed
        // key pressed in text field
        //        System.out.println("keyPressed evt "+evt);
//        System.out.println("value field key pressed");
        endEdit();
//        String s = evt.getKeyText(evt.getKeyCode());
        int code = evt.getKeyCode();
        boolean shift = evt.isShiftDown();
        float byRatio = 1.1f;
        if (shift) {
            byRatio = 10f;
        }
        if (code == KeyEvent.VK_UP) {
            startEdit();
            pot.changeByRatio(byRatio);
            endEdit();
        } else if (code == KeyEvent.VK_DOWN) {
            startEdit();
            pot.changeByRatio(1f / byRatio);
            endEdit();
        }
    }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:23,代码来源:IPotSliderTextControl.java

示例6: testCancel

import java.awt.event.KeyEvent; //导入依赖的package包/类
public void testCancel() {
    Node pn = new ProjectsTabOperator().getProjectRootNode(TEST_PROJECT_NAME);
    pn.select();
    
    Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString(
            "org.netbeans.modules.java.j2seproject.Bundle",
            "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|"
            +TEST_CLASS_NAME);
    n.select();
    new OpenAction().perform();
    EditorOperator editor = new EditorOperator(TEST_CLASS_NAME);
    try {
        editor.insert("List m;\n", 46, 1);
        Utilities.takeANap(100);
        MainWindowOperator.getDefault().pushKey(KeyEvent.VK_I,
                KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK);            
        FixAllImports fio = new FixAllImports();
        fio.cancel();
        assertFalse("Import is added",editor.getText().contains("import java.util.List;"));
    } finally {
        editor.close(false);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:FixImportsTest.java

示例7: keyPressed

import java.awt.event.KeyEvent; //导入依赖的package包/类
@Override
public void keyPressed(KeyEvent e) {
    switch (e.getKeyCode()) {
        case KeyEvent.VK_UP:
            int up = targetList.getSelectedIndex() - 1;
            if (up < 0) {
                up = 0;
            }
            targetList.setSelectedIndex(up);
            break;
        case KeyEvent.VK_DOWN:
            int listSize = targetList.getModel().getSize();
            int down = targetList.getSelectedIndex() + 1;
            if (down >= listSize) {
                down = listSize - 1;
            }
            targetList.setSelectedIndex(down);
            break;
        default:
            break;
    }
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:23,代码来源:FontChooser.java

示例8: keyPressed

import java.awt.event.KeyEvent; //导入依赖的package包/类
@Override
public void keyPressed(KeyEvent e) {
	if(e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB){
		try {
			((JSpinner)editorComponent).commitEdit();
			
		} catch (ParseException e1) {
			DefaultEditor de = (DefaultEditor) ((JSpinner)editorComponent).getEditor();
			String text = de.getTextField().getText();
			if(text.matches("^\\d+(\\.\\d*)?")){
				((JSpinner)editorComponent).setValue(Float.parseFloat(text));
			}else{
				System.err.println("Invalid input - ignoring");
			}
		}
	}
	super.keyPressed(e);
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:19,代码来源:TableCellSpinnerEditor4FloatObject.java

示例9: keyTyped

import java.awt.event.KeyEvent; //导入依赖的package包/类
@Override
public void keyTyped(InstanceState state, KeyEvent e) {
	char c = e.getKeyChar();
	int val = Character.digit(e.getKeyChar(), 16);
	MemState data = (MemState) state.getData();
	if (val >= 0) {
		curValue = curValue * 16 + val;
		data.getContents().set(data.getCursor(), curValue);
		state.fireInvalidated();
	} else if (c == ' ' || c == '\t') {
		moveTo(data, data.getCursor() + 1);
	} else if (c == '\r' || c == '\n') {
		moveTo(data, data.getCursor() + data.getColumns());
	} else if (c == '\u0008' || c == '\u007f') {
		moveTo(data, data.getCursor() - 1);
	}
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:18,代码来源:MemPoker.java

示例10: main

import java.awt.event.KeyEvent; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");

    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            fileChooser = new JFileChooser();
            fileChooser.showOpenDialog(null);
        }
    });

    robot.waitForIdle();

    if (OSInfo.OSType.MACOSX.equals(OSInfo.getOSType())) {
        Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_L);
    } else {
        Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_L);
    }
    checkFocus();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:bug4524490.java

示例11: RunsTable

import java.awt.event.KeyEvent; //导入依赖的package包/类
public RunsTable(EntryModel m)
{
	super(m, new TimeRenderer(), new RunsTransferHandler(), 2, Integer.MAX_VALUE);
	
	InputMap im = getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
	im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "cut"); // delete is same as Ctl+X
	im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter Time");
	
	registerKeyboardAction(
		this,
		"Enter Time",
		KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
		JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
	);
	
	Messenger.register(MT.TIME_ENTERED, this);
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:18,代码来源:RunsTable.java

示例12: biasTextFieldKeyPressed

import java.awt.event.KeyEvent; //导入依赖的package包/类
private void biasTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_biasTextFieldKeyPressed
        int code = evt.getKeyCode();
        boolean shifted = evt.isShiftDown();
        final float byRatio = 1.02f;
        if (code == KeyEvent.VK_UP) {
            startEdit();
            if (shifted) {
                pot.setBitValue(pot.getBitValue() + 1);
            } else {
                pot.changeByRatio(byRatio);
            }
            endEdit();
        } else if (code == KeyEvent.VK_DOWN) {
            startEdit();
            if (shifted) {
                pot.setBitValue(pot.getBitValue() - 1);
            } else {
                pot.changeByRatio(1f / byRatio);
            }
            endEdit();
        }
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:23,代码来源:ConfigurableIPotGUIControl.java

示例13: keyStrokeToString

import java.awt.event.KeyEvent; //导入依赖的package包/类
/**
 * Creates nice textual representation of KeyStroke.
 * Modifiers and an actual key label are concated by plus signs
 * @param the KeyStroke to get description of
 * @return String describing the KeyStroke
 */
public static String keyStrokeToString( KeyStroke stroke ) {
    String modifText = KeyEvent.getKeyModifiersText( stroke.getModifiers() );
    String keyText = (stroke.getKeyCode() == KeyEvent.VK_UNDEFINED) ? 
        String.valueOf(stroke.getKeyChar()) : getKeyText(stroke.getKeyCode());
    if( modifText.length() > 0 ) return modifText + '+' + keyText;
    else return keyText;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:Utilities.java

示例14: getKeys

import java.awt.event.KeyEvent; //导入依赖的package包/类
@Override
public NavigationKey[] getKeys(ComponentOperator oper) {
    boolean multiString = oper instanceof TextAreaOperator;
    NavigationKey[] result = new NavigationKey[multiString ? 4 : 2];
    result[0] = new UpKey(KeyEvent.VK_LEFT, 0);
    result[1] = new DownKey(KeyEvent.VK_RIGHT, 0);
    ((UpKey) result[0]).setDownKey((DownKey) result[1]);
    ((DownKey) result[1]).setUpKey((UpKey) result[0]);
    if (multiString) {
        result[2] = new UpKey(KeyEvent.VK_UP, 0);
        result[3] = new DownKey(KeyEvent.VK_DOWN, 0);
        ((UpKey) result[2]).setDownKey((DownKey) result[3]);
        ((DownKey) result[3]).setUpKey((UpKey) result[2]);
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:AWTTextKeyboardDriver.java

示例15: testNotFound

import java.awt.event.KeyEvent; //导入依赖的package包/类
public void testNotFound() {
    openDefaultProject();
    openFile("Source Packages|org.netbeans.test.editor.search.IncrementalSearchTest", "match.txt");
    EditorOperator editor = new EditorOperator("match.txt");
    editor.setCaretPosition(3, 1);
    SearchBarOperator barOperator = SearchBarOperator.invoke(editor);
    JTextComponentOperator t = barOperator.findCombo();
    try {            
        t.clearText();
        new EventTool().waitNoEvent(100);
        t.requestFocus();
        t.typeText("XYZ");        
        t.pushKey(KeyEvent.VK_ENTER);                        
        new EventTool().waitNoEvent(100);            
        MainWindowOperator mwo =  MainWindowOperator.getDefault();
        assertEquals("'XYZ' not found",mwo.getStatusText());                        
        JTextComponentOperator filed = barOperator.findCombo();
        assertEquals(new Color(178, 0, 0), filed.getForeground());                
    } finally {
        barOperator.closeButton().doClick();                              
    }
    new EventTool().waitNoEvent(200);
    assertFalse("ToolBar not closed",barOperator.isVisible());
    editor.closeDiscard();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:IncrementalSearchTest.java


注:本文中的java.awt.event.KeyEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。