Question: Using/in Java Swing create an application that allows the user to drag a geometric shape (2D ellipse) with the mouse and move it around with

Using/in Java Swing create an application that allows the user to drag a geometric shape (2D ellipse) with the mouse and move it around with the keyboard Must use JPanel, JFrame , geometric 2D, and Mouse Listeners the program react to a mouse or keyboard event by printing a message to the console when this event occurs

public class Panel extends javax.swing.JPanel

{

private final int INIT_X = 75;

private final int INIT_Y = 75;

private final int DIAMETER = 60;

private SmartEllipse _sunny;

public Panel()

{

super();

this.setBackground(java.awt.Color.white);

_sunny = new SmartEllipse(java.awt.Color.red);

_sunny.setLocation(INIT_X, INIT_Y);

_sunny.setSize(DIAMETER, DIAMETER);

// The panel needs to add a new MouseListener, KeyListener, and

// MouseMotionListener in its constructor. To receive key events, it must also

// be focusable.

}

public void paintComponent(java.awt.Graphics aBrush)

{

super.paintComponent(aBrush);

java.awt.Graphics2D betterBrush = (java.awt.Graphics2D) aBrush;

_sunny.fill(betterBrush);

}

// You can create one or more private listener classes here. These classes must

// implement MouseListener, KeyListener, and MouseMotionListener (you can make

// one class for all three, a separate class for each, or have the Panel

// implement them instead). Make sure they're working on printing a message in

// the mousePressed, keyPressed, and mouseDragged methods.

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!