导航:首页 > 编程语言 > 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按钮的事件监听相关的资料

热点内容
西安iPhone6升级内存 浏览:84
小学生的编程的课是学什么的 浏览:114
就业下载什么app 浏览:191
个人配置文件重定向到D盘 浏览:22
js屏幕宽度 浏览:312
sql查找某列重复数据库 浏览:48
智行火车票用微信支付 浏览:262
网络定价过程哪些内容发生变化 浏览:200
dubbo服务提供者的配置文件 浏览:182
win8系统如何压缩文件 浏览:875
网站怎么上传代码 浏览:4
java日志的好处 浏览:103
武汉奇米网络怎么样 浏览:689
笔记本如何恢复原来数据 浏览:76
charles怎么抓取js 浏览:580
网络智豹破解版 浏览:424
pdf文件一键转蓝 浏览:563
2014yy钓鱼网站源码 浏览:835
华为p9应用程序在哪里 浏览:106
36记app叫什么 浏览:360

友情链接