当前位置: 技术问答>java相关
如何屏蔽鼠标左键功能。谢谢。
来源: 互联网 发布时间:2015-03-25
本文导语: 我想写挖雷游戏,如何做到Jbutton插上小旗后,如何屏蔽鼠标左键单击谢谢。 | 重载mouseClick事件. | import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Frame1 extends...
我想写挖雷游戏,如何做到Jbutton插上小旗后,如何屏蔽鼠标左键单击谢谢。
|
重载mouseClick事件.
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends Frame {
public JButton b1 = new JButton(" b1 ");
public Frame1() {
this.setLayout(null);
b1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
b1_mouseClicked(e);
}
});
b1.setBounds(new Rectangle(100, 39, 55, 22));
this.add(b1);
}
void b1_mouseClicked(MouseEvent e)
{
if(!SwingUtilities.isRightMouseButton(e))
return;
//...do whatever you want
}
public static void main(String[] args) {
Frame1 frame = new Frame1();
frame.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(300, 400);
frame.setVisible(true);
}
}
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends Frame {
public JButton b1 = new JButton(" b1 ");
public Frame1() {
this.setLayout(null);
b1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
b1_mouseClicked(e);
}
});
b1.setBounds(new Rectangle(100, 39, 55, 22));
this.add(b1);
}
void b1_mouseClicked(MouseEvent e)
{
if(!SwingUtilities.isRightMouseButton(e))
return;
//...do whatever you want
}
public static void main(String[] args) {
Frame1 frame = new Frame1();
frame.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(300, 400);
frame.setVisible(true);
}
}
|
必须自己来实现一个新的jbutton。
|
/*
A basic extension of the java.applet.Applet class
*/
import java.awt.*;
import java.lang.*;
import java.applet.*;
public class DoubleClickApplet extends Applet
{
String mouseClickedString = "Mouse event : none";
String mouseClickedString2 = "Mouse double click : no";
long lastDownTime = 0;
final static long DOUBLE_CLICK_TIME = 500;
public boolean mouseDown(Event evt, int x, int y)
{
if((evt.when - lastDownTime)
A basic extension of the java.applet.Applet class
*/
import java.awt.*;
import java.lang.*;
import java.applet.*;
public class DoubleClickApplet extends Applet
{
String mouseClickedString = "Mouse event : none";
String mouseClickedString2 = "Mouse double click : no";
long lastDownTime = 0;
final static long DOUBLE_CLICK_TIME = 500;
public boolean mouseDown(Event evt, int x, int y)
{
if((evt.when - lastDownTime)