import java.awt.*;
import java.awt.event.*;
// Proj08Runner file
class Proj08Runner extends Frame {
GUI gui = new GUI();
class MyFrame extends Frame {
int xCoor;
int yCoor;
MyFrame() {//constructor
this.setTitle("Gretchen Suarez");
this.setSize(300,100);
} //end constructor
public void paint(Graphics g) {
//display coordinate information on the Frame
g.drawString("" + xCoor + ", " + yCoor, xCoor, yCoor);
}//end paint()
}//end class MyFrame
class GUI {
public GUI() {//constructor
//Create a visual object of type MyFrame named Frame1
MyFrame myFrame = new MyFrame();
myFrame.setVisible(true);
//Instantiate and register Listener object which will
// terminate the program when the user closes
// the Frame.
WProc1 winProcCmd1 = new WProc1();
myFrame.addWindowListener(winProcCmd1);
//Instantiate and register Listener object which will
// process mouseMoved events to display coordinate
// information on the Frame object named myFrame1.
MyMouseMotionProcessor mouseMotionProc =
new MyMouseMotionProcessor(myFrame);
myFrame.addMouseMotionListener(mouseMotionProc);
}//end constructor
}//end class GUI definition
//This listener class monitors for mouseMove events and
// displays the coordinates of the mouse pointer when the
// mouse is moved inside the client area of the Frame.
class MyMouseMotionProcessor extends MouseMotionAdapter {
MyFrame refToFrame; //save references to the Frame
//Constructor
MyMouseMotionProcessor(MyFrame inFrame) {
//save incoming object reference
refToFrame = inFrame;
}// end constructor
public void mouseMoved(MouseEvent e) {
//Get X and Y coordinates of mouse pointer and store
// in instance variables of the Frame object
refToFrame.xCoor = e.getX();
refToFrame.yCoor = e.getY();
//Force a repaint to display the coordinate information
refToFrame.repaint();
}//end mouseMoved()
public void mouseDragged(MouseEvent e) {
//Get X and Y coordinates of mouse pointer and store
// in instance variables of the Frame object
refToFrame.xCoor = e.getX();
refToFrame.yCoor = e.getY();
//Force a repaint to display the coordinate information
refToFrame.repaint();
}//end mouseMoved()
}//end class MyMouseMotionProcessor
//The following listener is used to terminate the program
// when the user closes the frame object.
class WProc1 extends WindowAdapter {
public void windowOpened(WindowEvent e) {
System.out.println("\nI certify that this program is my own work" +
"\nand is not the work of others. I agree not" +
"\nto share my solution with others." +
"\nGretchen Suarez\n");
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}//end windowClosing()
}//end class WProc1
}