Hello, I have a question about Java. I am working on the following code (shown below). For the mouseMoved event the coordinates must be displayed using black characters, and for the mouseDragged event, the coordinates must be displayed using red characters. How can I do that? I would really appreciate your help. Thanks in advance!

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Hello, I have a question about Java. I am working on the following code (shown below). For the mouseMoved event the coordinates must be displayed using black characters, and for the mouseDragged event, the coordinates must be displayed using red characters. How can I do that? I would really appreciate your help. Thanks in advance!

// Proj08 file
import java.awt.Frame;
public class Proj08 {
  public static void main(String[] args){
    Frame aFrame = new Proj08Runner();
  }//end main
}//end class Proj08
 
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

}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY