Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Windows on the desktop are just one of many objects used in a graphical user int

ID: 3655318 • Letter: W

Question

Windows on the desktop are just one of many objects used in a graphical user interface (GUI)-- buttons, drop-down list boxes, pop-up menus, are just some of the many others. Regardless of their particular appearance, tasks, and structure, all such GUI components share some common functionality-- which is handled in a manner unique to the actual component. Define an interface, GUIComponent, with the following methods: - onClick-- void-returning and accepts a single integer parameter - onCursorFocus -- void-returning and accept no parameters - move -- 2 overloaded methods: both boolean-returning; one accepts a pair of integer parameters; the second a single parameter of type Position - resize-- 2 overloaded methods; both boolean-returning; one accepts a pair of integer parameters; the second a single parameter of type Dimension

Explanation / Answer

Mouse Event: =========== import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; // An AWT GUI program inherits the top-level container java.awt.Frame public class MouseEventDemo extends Frame implements MouseListener { // This class acts as MouseListener // To display the (x, y) coordinates of the mouse-clicked private TextField tfMouseClickX; private TextField tfMouseClickY; /** Constructor to setup the GUI */ public MouseEventDemo() { setLayout(new FlowLayout()); // "this" frame sets to FlowLayout add(new Label("X-Click: ")); // "this" frame adds an anonymous Label tfMouseClickX = new TextField(10); // allocate TextField tfMouseClickX.setEditable(false); // read-only add(tfMouseClickX); // "this" frame adds component add(new Label("Y-Click: ")); // "this" frame adds an anonymous Label tfMouseClickY = new TextField(10); // allocate TextField tfMouseClickY.setEditable(false); // read-only add(tfMouseClickY); // "this" frame adds component addMouseListener(this); // "this" frame fires the MouseEvent to all its registered MouseListener // "this" frame adds "this" object as a MouseListener setTitle("MouseEvent Demo"); // "this" Frame sets title setSize(350, 100); // "this" Frame sets initial size setVisible(true); // "this" Frame shows } /** The entry main() method */ public static void main(String[] args) { new MouseEventDemo(); // Let the constructor do the job } /** MouseEvent handlers */ // Called back when a mouse-button has been clicked @Override public void mouseClicked(MouseEvent e) { tfMouseClickX.setText(e.getX() + ""); tfMouseClickY.setText(e.getY() + ""); } // Not Used, but need to provide an empty body for compilation @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } } Window Event: =========== import java.awt.*; // using AWT containers and components import java.awt.event.*; // using AWT events and listener interfaces // An AWT GUI program inherits the top-level container java.awt.Frame public class WindowEventDemo extends Frame implements ActionListener, WindowListener { // This class acts as listener for ActionEvent and WindowEvent // Java support only single inheritance, where a class can extend // one superclass, but can implement multiple interfaces. private TextField tfCount; private int count = 0; // Counter's value /** Constructor to setup the GUI */ public WindowEventDemo () { setLayout(new FlowLayout()); // "this" Frame sets to FlowLayout add(new Label("Counter")); // "this" Frame adds an anonymous Label tfCount = new TextField("0", 10); // allocate TextField tfCount.setEditable(false); // read-only add(tfCount); // "this" Frame adds tfCount Button btnCount = new Button("Count"); // declare and allocate a Button add(btnCount); // "this" Frame adds btnCount btnCount.addActionListener(this); // btnCount fires ActionEvent to its registered ActionEvent listener // btnCount adds "this" object as an ActionEvent listener addWindowListener(this); // "this" Frame fires WindowEvent its registered WindowEvent listener // "this" Frame adds "this" object as a WindowEvent listener setTitle("WindowEvent Demo"); // "this" Frame sets title setSize(250, 100); // "this" Frame sets initial size setVisible(true); // "this" Frame shows } /** The entry main() method */ public static void main(String[] args) { new WindowEventDemo(); // Let the construct do the job } /** ActionEvent handler */ @Override public void actionPerformed(ActionEvent evt) { count++; tfCount.setText(count + ""); } /** WindowEvent handlers */ // Called back upon clicking close-window button @Override public void windowClosing(WindowEvent e) { System.exit(0); // terminate the program } // Not Used, but need to provide an empty body for compilation @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosed(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote