Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+what kinds of policies and practices should be developed?

Answered: 1 week ago

Question

=+ Of the HR issues mentioned in the case,

Answered: 1 week ago