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

熱點內容
想^_^香港看啪啪視頻 瀏覽:496
qq群贊賞照片不見了 瀏覽:187
不要錢免費看電影網站 瀏覽:425
u盤刪除文件可以恢復嗎 瀏覽:138
在森林槍戰的國產電影 瀏覽:133
食人癖女孩的電影 瀏覽:19
iphone5藍牙聽歌 瀏覽:802
al創世者電影完整版免費2023 瀏覽:303
小說電影免費網站有哪些 瀏覽:567
應城市網站到期怎麼續費 瀏覽:772
360擴展器固件在哪升級 瀏覽:103
青春愛情激情電影 瀏覽:209
韓國電影 女主角在療養院工作 瀏覽:926
javascriptsidebar 瀏覽:769
義烏用什麼app坐公交 瀏覽:14
矩陣縱橫cad文件下載 瀏覽:832
四個字的動畫片 瀏覽:461
js最新皮膚2017 瀏覽:587
恐怖電影無限流小說 瀏覽:178
主人公葉天的小說 瀏覽:834

友情鏈接