导航:首页 > 编程语言 > java实现连续点击事件

java实现连续点击事件

发布时间:2022-11-27 17:10:23

A. 怎么样用java实现鼠标的多次点击事件

int
getClickCount()
Returns the number of mouse clicks associated with this event.

B. JAVA 怎么实现多次点击一个按钮触发不同的事件

可以设置计数器,每点击一次计数然后根据点击的次数判断所要执行的操作

C. java的div的click多个事件怎么写,想要的效果是点击div,从左边跳到右边,来回五次。求大神指导!

<!DOCTYPEhtml>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8">

<title>RunJS演示代码</title>
<style>
body{
overflow-x:hidden;
}
#content{
text-align:center;
line-height:100px;
background-color:red;
width:100px;
height:100px;
position:absolute;
left:0;
}
</style>
<script>
varinter=null,count=0,dir=1,gap=30;
vargo=function(){
inter=setInterval(function(){
varle=parseFloat(content.style.left)||content.offsetLeft;
varb=document.documentElement.clientWidth||document.body.clientWidth;
varmax_width=b-content.offsetWidth;
le+=gap*dir;
if(le>=max_width){
dir=-1;
count++;
le=max_width;
}
elseif(le<=0){
dir=1;
count++;
le=0;
}
content.style.left=le+"px";
if(count==5){
clearInterval(inter);
}
},30);
}
</script>
</head>
<body>
<inputtype="button"value="GO"onclick="go()"/>
<divid='content'>
content
</div>
</body>
</html>

D. JAVA 怎么实现多次点击一个按钮触发不同的事件

直接构建一个actionevent,然后调用另一个按钮的fireevent方法

E. 用Java编写实现程序,在窗口North上布置三个按钮,并完成按钮点击事件

代码如下:

importjava.awt.BorderLayout;
importjava.awt.Color;
importjava.awt.FlowLayout;
importjava.awt.Graphics;
importjava.awt.Polygon;

importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JPanel;

publicclassAppextendsJFrame{

publicApp(){

this.setSize(300,300);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPaneltopBar=newJPanel();
topBar.setLayout(newFlowLayout());
this.add(topBar,BorderLayout.NORTH);

JPanelcanvas=newJPanel();
this.add(canvas,BorderLayout.CENTER);

JButtonbtnTriangle=newJButton("三角形");
btnTriangle.addActionListener(e->{

Graphicsg=canvas.getGraphics();

g.setColor(Color.RED);

Polygonpolygon=newPolygon();
polygon.addPoint(10,10);
polygon.addPoint(10,50);
polygon.addPoint(100,50);

g.fillPolygon(polygon);
});
topBar.add(btnTriangle);

JButtonbtnRectangle=newJButton("矩形");
btnRectangle.addActionListener(e->{

Graphicsg=canvas.getGraphics();

g.setColor(Color.RED);

g.fillRect(150,10,100,50);
});
topBar.add(btnRectangle);

JButtonbtnCircle=newJButton("椭圆");
btnCircle.addActionListener(e->{

Graphicsg=canvas.getGraphics();

g.setColor(Color.GREEN);

g.fillOval(10,100,250,90);
});
topBar.add(btnCircle);
}

publicstaticvoidmain(String[]args){
newApp().setVisible(true);
}
}

运行结果:

F. JAVA编程中如何自动调用按钮的点击事件

直接创建一个SelectionEvent类型的对象,然后直接调用监听器里面的方法,比如
SelectionEvent se=new SelectionEvent(...); //...为构造函数的参数,内具体内容就得参考API文档容了。
SelectionListener sl=new SelectionListener();
sl.widgetSelected(se);
就这样。

G. Java 程序实现鼠标点击 键盘等事件

用 Robot 类的如下方法:
void keyPress(int keycode)
按下给定的键。
void keyRelease(int keycode)
释放给定的键。
void mouseMove(int x, int y)
将鼠标指版针移动到给定屏幕坐权标。
void mousePress(int buttons)
按下一个或多个鼠标按钮。
void mouseRelease(int buttons)
释放一个或多个鼠标按钮。
void mouseWheel(int wheelAmt)
在配有滚轮的鼠标上旋转滚轮。

H. JAVA中如何设置多次点击一个按钮但有不同的事件响应,类似于一般安装软件时“下一步”按钮

将按钮上边绑定的事件换掉,或者在同一个事件响应方法中加参数辨别也行.

I. java鼠标点击事件

给你一个例子,太难讲了
我自己写的
package guidemo;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
* <p>Title: 图形用户界面</p>
*
* <p>Description: 简单的图形界面编程</p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author vic
* @version 1.0
*/
public class ColorFrame extends Frame implements MouseListener {
Label L; //标签
TextField T; //文本域
Button B1, B2; //按钮
public ColorFrame() {
this.setLayout(null); //想要手动指定各组件的的位置
L = new Label("输入学号:"); //设定标签L内容
L.setBounds(60, 50, 50, 25); //设定标签L外观
this.add(L); //将标签L添加到窗口中
T = new TextField("请在这里输入"); //设定文本域T的内容
T.setBounds(125, 50, 90, 25); //设定文本域T的外观
this.add(T); //将文本域T添加到窗口中
B1 = new Button("变红!"); //设定按钮B1的内容
B1.setBounds(25, 90, 90, 25); //设定按钮B1的外观
B1.addMouseListener(this);//在B1上注册鼠标监听器
this.add(B1); //将按钮B1添加到窗口中
B2 = new Button("变绿!");
B2.setBounds(125, 90, 90, 25);
B2.addMouseListener(this);
this.add(B2);
WindowDestroyer Listener = new WindowDestroyer(); //创建关闭窗口监听器
this.addWindowListener(Listener); //将监听器添加到窗口中
this.setBackground(Color.yellow); //设定窗口背景颜色
this.setTitle("This is Frame!"); //设定窗口标题文字
this.setBounds(0, 0, 250, 220); //设定窗口位置和大小
this.setVisible(true); //显示窗口
}

public void mouseClicked(MouseEvent e) {
if (e.getComponent() == B1) {//getComponent返回按钮上面的字符串
this.setBackground(Color.red);
}
if (e.getComponent() == B2) {
this.setBackground(Color.green);
}
}

public void mouseExited(MouseEvent e) {}

public void mouseEntered(MouseEvent e) {}

public void mouseReleased(MouseEvent e) {}

public void mousePressed(MouseEvent e) {}

public static void main(String[] args) {
new ColorFrame();
}
}
希望能解决您的问题。

J. 用java在文本框实现鼠标点击事件,一点文本框直接跳出新对话框

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JTextField;

public class Exec1 extends JFrame {

public Exec1() {
JTextField txt = new JTextField();
txt.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
new A().setVisible(true);
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
});
add(txt);
setSize(100, 65);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String [] args) {
new Exec1().setVisible(true);
}
}

class A extends JFrame {
public A() {
setSize(400, 400);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}

阅读全文

与java实现连续点击事件相关的资料

热点内容
网络中常用的传输介质 浏览:518
文件如何使用 浏览:322
同步推密码找回 浏览:865
乐高怎么才能用电脑编程序 浏览:65
本机qq文件为什么找不到 浏览:264
安卓qq空间免升级 浏览:490
linux如何删除模块驱动程序 浏览:193
at89c51c程序 浏览:329
怎么创建word大纲文件 浏览:622
袅袅朗诵文件生成器 浏览:626
1054件文件是多少gb 浏览:371
高州禁养区内能养猪多少头的文件 浏览:927
win8ico文件 浏览:949
仁和数控怎么编程 浏览:381
项目文件夹图片 浏览:87
怎么在东芝电视安装app 浏览:954
plc显示数字怎么编程 浏览:439
如何辨别假网站 浏览:711
宽带用别人的账号密码 浏览:556
新app如何占有市场 浏览:42

友情链接