导航:首页 > 编程语言 > java按钮的事件监听

java按钮的事件监听

发布时间:2023-07-26 10:06:10

A. java中回车键监听按钮事件

document.onkeydown=function(){

if (event.keyCode == 13){ //盯慧回凯凯答车

}
if (event.keyCode == 32){ //孙哗空格

}
}

B. java 鼠标左键 加 ctrl 选中是什么监听事件

事件源。
java的事件监听机制包含三个组件事件源事件监听器事件对象,当事件源上发生操作,时它将会调用事件监听器的一个方法,并且会传递一个事件对象过来,事件监听器由开发人员编写,开发人员在事件监听器中,可以拿到事件源,从而对事件源上的操作进行处理。

C. java键盘事件,如何监听连续按两次按键


importjava.awt.BorderLayout;
importjava.awt.Dimension;
importjava.awt.event.*;
importjavax.swing.*;
,ActionListener{
JTextAreadisplayArea;
JTextFieldtypingArea;
publicstaticvoidmain(String[]args){
javax.swing.SwingUtilities.invokeLater(newRunnable(){
publicvoidrun(){
createAndShowGUI();
}
});
}
/**
*CreatetheGUIandshowit.Forthreadsafety,thismethodshouldbe
*invokedfromtheevent-dispatchingthread.
*/
(){
//Createandsetupthewindow.
KeyEventDemoframe=newKeyEventDemo("KeyEventDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Setupthecontentpane.
frame.addComponentsToPane();
//Displaythewindow.
frame.pack();
frame.setVisible(true);
}
(){
JButtonbutton=newJButton("Clear");
button.addActionListener(this);
typingArea=newJTextField(20);
typingArea.addKeyListener(this);
displayArea=newJTextArea();
displayArea.setEditable(false);
JScrollPanescrollPane=newJScrollPane(displayArea);
scrollPane.setPreferredSize(newDimension(375,125));
getContentPane().add(typingArea,BorderLayout.PAGE_START);
getContentPane().add(scrollPane,BorderLayout.CENTER);
getContentPane().add(button,BorderLayout.PAGE_END);
}
publicKeyEventDemo(Stringname){
super(name);
}
longtime=System.currentTimeMillis();
longtimeInterval=300;
/**.*/
publicvoidkeyTyped(KeyEvente){
//displayInfo(e,"KEYTYPED:");
}
/**.*/
publicvoidkeyPressed(KeyEvente){
System.out.println(System.currentTimeMillis()-time);
if(System.currentTimeMillis()-time<timeInterval)
displayArea.setText("Doubleclicked");
else
displayArea.setText("Singleclicked");
time=System.currentTimeMillis();
//displayInfo(e,"KEYPRESSED:");
}
/**.*/
publicvoidkeyReleased(KeyEvente){
//displayInfo(e,"KEYRELEASED:");
}
/**Handlethebuttonclick.*/
publicvoidactionPerformed(ActionEvente){
//Clearthetextcomponents.
displayArea.setText("");
typingArea.setText("");
//Returnthefocustothetypingarea.
typingArea.requestFocusInWindow();
}
}

D. Java按钮监听

importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.math.BigDecimal;
importjava.util.Scanner;
importjavax.swing.JFrame;
importjava.awt.Button;
importjava.awt.Label;
importjava.awt.TextField;
importjava.awt.Frame;
importjava.awt.Panel;
importjava.awt.Color;
importjava.awt.*;

publicclassPanelTest{
publicstaticvoidmain(Stringargs[]){
/*Scannersc=newScanner(System.in);doublepi=3.14,s;doubler;r=sc.nextDouble();s=pi*r*r;System.out.println("s等于"+s);*/
EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
CricleFrameframe=newCricleFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}

classCricleFrameextendsJFrame{

Panelp=newPanel();
TextFieldt=newTextField();
Buttonb=newButton("确定");
Labela=newLabel("请在此输入半径");
TextFieldresult=newTextField();

publicCricleFrame(){
add(a);
add(t);
add(b);
add(result);
add(p);
setVisible(true);
p.setBackground(Color.black);
a.setBackground(Color.yellow);
t.setBackground(Color.white);
result.setBackground(Color.white);
b.setBackground(Color.cyan);
setSize(300,300);
setTitle("圆的面积");
a.setBounds(105,45,90,25);
t.setBounds(100,80,100,25);
result.setBounds(100,180,100,25);
b.setBounds(111,120,80,40);

b.addActionListener(newActionListener(){//按钮点击事件监听
publicvoidactionPerformed(ActionEventevent){
Doubler=0.0;
try{
r=Double.parseDouble(t.getText());
}catch(Exceptione){
System.out.println(e.getMessage());
}
BigDecimaltmp=newBigDecimal(r*r*Math.PI);
Doublearea=tmp.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();//保留2位小数
result.setText(""+area);
}
});
}
}

在你的基础上改了一下,界面什么的没有改

E. java中怎样为多个按钮设置监听

for(inti=0;i<9;i++){
JButtonbtn=null;
if(i%2==0){
btn=newJButton("+");
f.add(btn);
}
else{
btn=newJButton("-");
f.add(btn);
}
btn.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
if(e.getActionCommand.equals("+")){
btn.setText("-");
}
else{
btn.setText("+");
}
}
});
}

F. java怎么实现对另一个类中的按钮监听

你只有一个窗体,

你想要的就是在一个“窗体类”中,监听一个“监听事件类”的意思吗

只要把监听事件类写在窗体类中,不就行了吗?

class GameState_Begin extends Frame
{
//构造器
public GameState_Begin()
{
Button btn1=new Button("开始游戏");
super.add(btn1);

btn1.addActionListener(new ButtonListen());
}

//●●●●●内部类:按钮事件监听
class ButtonListen implements ActionListener
{
public void actionPerformed(ActionEvent arg0) {

//改变panel布局的代码

}

}
}

阅读全文

与java按钮的事件监听相关的资料

热点内容
xml文件注释快捷键 浏览:878
extjs的配置文件怎么配置重定向 浏览:740
access数据库查看aspx 浏览:154
数控编程如何减少时间 浏览:779
苹果FLAC属性 浏览:642
硬盘评分工具 浏览:734
为什么e福州app登不上 浏览:963
jsfoutputlink 浏览:472
哪个网站可以听南音 浏览:264
苹果装系统装win7驱动 浏览:686
php判断file是否有文件 浏览:979
和平精英使用什么编程开发 浏览:102
f3文件 浏览:523
快手3d环绕音乐用什么app 浏览:376
linux新增一个文件 浏览:440
消失的手机图片在哪个文件夹里 浏览:610
word2010表格外框双线内框单线 浏览:56
powermill如何提高编程速度 浏览:465
遥感30号卫星数据存在哪里 浏览:846
请领导看文件应该用什么词 浏览:273

友情链接