導航:首頁 > 編程語言 > 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實現連續點擊事件相關的資料

熱點內容
實名寶app哪個好 瀏覽:1
微雲單個文件可以傳多少 瀏覽:843
計算機連成網路的最重要優勢是 瀏覽:411
優盤打開後文件夾為空 瀏覽:495
實時數據寫入量大如何優化 瀏覽:76
哪裡能學程序編程 瀏覽:647
微信裡面的文件儲存在哪個目錄 瀏覽:745
高仿蘋果5s屏幕顯示清楚嗎 瀏覽:897
若有以下程序void 瀏覽:432
大數據主體有哪些 瀏覽:961
如何學習編程的優點 瀏覽:906
最新版本手機qq 瀏覽:463
簡述在word 瀏覽:528
qq怎麼清楚歷史記錄防止被盜 瀏覽:263
發送手機里的錄音文件在哪裡 瀏覽:866
js獲取下一個兄弟元素 瀏覽:293
js模板引擎原理 瀏覽:72
linuxo文件運行 瀏覽:713
什麼免費備份數據 瀏覽:342
測量大師導入底圖找不到文件 瀏覽:313

友情鏈接