movX = me.getX();
movY = me.getY();
msg = "*";
// Handle mouse moved.
public void mouseMoved(MouseEvent me) {
// save coordinates
movX = me.getX();
movY = me.getY();
repaint(0, 0, 100, 20);
// Display msg in applet window.
public void paint(Graphics g) {
g.drawString(msg, mouseX, mouseY);
g.drawString("Mouse at " + movX + ", " + movY, 0, 10);
Sample output from this program is shown here:
Creating a Windowed Program
Although creating applets is a common use for Java's AWT, it is also possible to create
stand-alone AWT-based applications. To do this, simply create an instance of the window
or windows you need inside main( ). For example, the following program creates a frame
window that responds to mouse clicks and keystrokes:
// Create an AWT-based application.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
// Create a frame window.
public class AppWindow extends Frame {
String keymsg = "This is a test.";
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks