Response processing of mouse events in the Java applet (including right-click, double click, etc.)

zhaozj2021-02-08  282

Javaduke is originally available on www.dukejava.com homepage with a large number of Java programming skills

How to implement a mouse response in a small program?

Public class hello extends applet imports mouselistener {

Public void init () {

AddMouseListener (this);

}

Public void mouseentered (mouseevent e) {

au.play ();

SetBackground (color.blue);

}

Public void mouseexited (mouseevent e) {

SetBackground ;; Color.Black;

}

Public void mousepressed (mouseevent e) {}

Public void mouseeleased (mouseevent e) {}

Public void mouseclicked (mouseevent e) {}

}

First implement an event listener in a small program, and then realize the mouse user interface

How to deal with the mouse double, three hits in the applet?

Component.addmouselistener

NEW mymouselistener ());

Public class mymouselistener extends mouseadapter {

Public void mouseclicked (mouseevent evt) {

IF (est.getclickcount () == 3) {

// Treat mouse three hits

} else if (evt.getclickcount () == 2) {

// Test the mouse double click

}

}

}

Right click on the mouse button

Public mouseclicked (mouseevent e) {

IF (E.IsMetadown ()) {// Test your mouse right click

}

How to handle mouse intermediate keys in a small program?

NEW mymouselistener ());

Public class mymouselistener extends mouseadapter {

Public void mouseclicked (mouseevent evt) {

IF ((EVT.GETMODIFIERS () &?

INPUTEVENT.BUTTON1_MASK)! = 0) {

ProcessLeft (est.getpoint ());

// Test the left mouse button

}

IF ((EVT.GETMODIFIERS () &?

INPUTEVENT.BUTTON2_MASK)! = 0) {

ProcessMiddle (est.getpoint ());

// Test the mouse intermediate button Click

}

IF ((EVT.GETMODIFIERS () &?

INPUTEVENT.BUTTON3_MASK)! = 0) {

Processright (est.getpoint ());

// Test a mouse right click

}

}

}

转载请注明原文地址:https://www.9cbs.com/read-1717.html

New Post(0)