|
|
Исходный текст программы MouseMonitor.java
|
Оглавление |
Назад
// ==========================================
// MouseMonitor.java
//(C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// ==========================================
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
// =======================================
// Class MouseMonitor
// =======================================
public class MouseMonitor
{
// =======================================
// main
// =======================================
public static void main(String args[])
{
FrameWindow frame;
frame = new FrameWindow("Mouse monitor");
frame.init();
frame.show();
}
}
// =======================================
// Class FrameWindow
// =======================================
class FrameWindow extends Frame
implements MouseListener, WindowListener
{
// ============================================
// FrameWindow
// ============================================
public FrameWindow(String szTitle)
{
super(szTitle);
setSize(200, 200);
setBackground(Color.yellow);
setForeground(Color.black);
}
// ============================================
// init
// ============================================
public void init()
{
this.addMouseListener(this);
this.addWindowListener(this);
}
// ============================================
// paint
// ============================================
public void paint(Graphics g)
{
super.paint(g);
}
// ============================================
// mousePressed
// ============================================
public void mousePressed(MouseEvent e)
{
Graphics g = getGraphics();
String s="";
s = "[" + e.getX() + "," + e.getY() + "]";
int m = e.getModifiers();
switch(m)
{
case MouseEvent.BUTTON1_MASK:
{
s += " left";
break;
}
case MouseEvent.BUTTON2_MASK:
{
s += " middle";
break;
}
case MouseEvent.BUTTON3_MASK:
{
s += " right";
break;
}
}
int clicks = e. getClickCount();
if(clicks > 1)
{
repaint();
return;
}
g.drawString(s, e.getX(), e.getY());
}
// ============================================
// mouseReleased
// ============================================
public void mouseReleased(MouseEvent e)
{
}
// ============================================
// mouseClicked
// ============================================
public void mouseClicked(MouseEvent e)
{
}
// ============================================
// mouseMoved
// ============================================
public void mouseMoved(MouseEvent e)
{
}
// ============================================
// mouseDragged
// ============================================
public void mouseDragged(MouseEvent e)
{
}
// ============================================
// mouseEntered
// ============================================
public void mouseEntered(MouseEvent e)
{
}
// ============================================
// mouseExited
// ============================================
public void mouseExited(MouseEvent e)
{
}
// ============================================
// windowClosing
// ============================================
public void windowClosing(WindowEvent e)
{
setVisible(false);
System.exit(0);
}
public void windowOpened(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
}
|
|
|