⑴ java中如何設置快捷鍵為enter鍵
button不能設置alt以外的快捷鍵,menuitem可以: menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_MASK));
⑵ 在java中qq界面中怎麼按enter鍵發送消息
方法一:
importjava.awt.*;
importjavax.swing.*;
importjava.awt.event.*;
{
privateJButtonb1=newJButton("Click");
publicButtonTest(){
this.getContentPane().add(b1);
b1.addKeyListener(this);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.pack();
}
publicvoidkeyReleased(KeyEventke){
}
publicvoidkeyPressed(KeyEventke){
if(ke.getKeyChar()==ke.VK_ENTER){
System.out.println("ok................");
}
}
publicvoidkeyTyped(KeyEventke){
}
publicstaticvoidmain(String[]args){
newButtonTest().show();
}
}
方法二:
importjava.awt.*;
importjavax.swing.*;
importjava.awt.event.*;
{
privateJButtonb1=newJButton("Click");
publicButtonTest(){
this.getContentPane().add(b1);
b1.addKeyListener(newKeyAdapter(){
publicvoidkeyPressed(KeyEventke){
if(ke.getKeyChar()==ke.VK_ENTER){
System.out.println("ok..............");
}
}
}
);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.pack();
}
publicstaticvoidmain(String[]args){
newButtonTest().show();
}
}
⑶ 能否用java代碼實現enter鍵的功能
可以,你給frame添加一個addKeyListener()方法,實現keyPressed()方法時捕獲keyCode,查一下enter鍵的值,如果和你捕獲的相等,就執行你要執行的代碼
⑷ java中,用回車鍵表示確定的方法是什麼,在哪個類中
請問你是說的java web中的回車確認,還是java應用程序呢?java web中:
比如在注冊頁面,填完需要填的必填信息後。這時候不管游標在哪裡,點擊回車就直接相當於按下確認或者提交按鈕的話。可以在頁面通過javascript腳本添加一個監聽事件,js方法代碼如下,
document.onkeydown=function(e){
if((e.keyCode || e.which) ==13){
doSomething(); //這里調用你要執行的方法,像提交請求……
}
}
該方法是在當前頁面添加一個按鍵按下的事件。這個判斷的意思是,當按下的是13(回車的keycode,鍵盤上的每個按鍵都對應有個keycode)也就是回車鍵時。觸發下面的事件即可。應用程序中也可以有類似設置不過不用寫代碼來控制。
⑸ java中如何判斷按下的是回車鍵
你可以嘗試一下使用ASCII碼判斷輸入的字元是否為回車,回車鍵CR (carriage return) 十進制 的值為:13
⑹ Java中怎麼把一個回車鍵當做字元輸入
java中可以使用buffereader類來獲得控制台輸入的回車鍵,示例如下:
importjava.io.BufferedReader;
importjava.io.InputStreamReader;
publicclassTest{
publicstaticvoidmain(Stringargs[])throwsException{
System.out.println("輸入:");
BufferedReaderbf=newBufferedReader(newInputStreamReader(System.in));
Stringstr="";
do{
str=bf.readLine();
if(str.length()==0){//如果輸入的字元串為空,則說明只輸入了一個回車
System.out.println("輸入的是回車!");
}else{
System.out.println("輸入內容是:"+str);
}
}while(str.length()!=0);
}
}
這樣可以在輸入回車後提示「輸入的是回車!」並結束程序
⑺ java中如何實現按鍵盤上的回車鍵進行登錄
if (event.keyCode==13){ //回車鍵的鍵值為13
alert("回車!");
document.getElementById("login").click(); //調用登錄按鈕的登錄事件
}
⑻ java中如何表示一個回車符
可以使用Java中\n和\r的換行,不過也是有區別的,如下:
1.\r 叫回車 Carriage Return
2.\n 叫新行 New Line
但是都會造成換行,使用System.getProperty("line.separator")來獲取當前OS的換行符
java 代碼
1. String userInputString = userInput;
2. userInputString = userInputString.replaceAll ( "\r", "" );
3. userInputString = userInputString.replaceAll ( "\n", "\\\\"+System.getPropert("line.separator"));
⑼ java中怎麼判斷是否按下了回車鍵
web程序嗎?
直接在js判斷就行了
function setNextFocus(obj){
if(event.keyCode==13){ // 按下回車
obj.focus();
}
如果是java類中。就是樓上的這樣
KeyEvent e
e.getKeyCode()==KeyEvent.VK_ENTER;