Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Change the following application such that a SceneShape object in selected state is drawn with a dashed blue rectangle around it, with small blue squares
Change the following application such that a SceneShape object in selected state is drawn with a dashed blue rectangle around it, with small blue squares (side size=6 pixels) marking the corners.
Hints: You may use method GeneralPath.getBounds2D() to get the enclosing rectangle. Use method Graphics2D.setStroke(Stroke s) with a BasicStroke parameter
It should look as follows
import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import javax.swing.*; /** A program that allows users to edit a scene composed of items. */ public class SceneEditor { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final SceneComponent scene = new SceneComponent(); JButton houseButton = new JButton("House"); houseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { scene.add(new HouseShape(20, 20, 50)); } }); JButton carButton = new JButton("Car"); carButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { scene.add(new CarShape(20, 20, 50)); } }); JButton removeButton = new JButton("Remove"); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { scene.removeSelected(); } }); JPanel buttons = new JPanel(); buttons.add(houseButton); buttons.add(carButton); buttons.add(removeButton); frame.add(scene, BorderLayout.CENTER); frame.add(buttons, BorderLayout.NORTH); frame.setSize(300, 300); frame.setVisible(true); } }House Car Remove House Car Remove
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started