Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a user specified integer number N, draw a set of (N + 1) line segments in a JPanel according to the following pattern: Each

Given a user specified integer number N, draw a set of (N + 1) line segments in a JPanel according to the following pattern: Each line segment has its first endpoint positioned at the center of the left side of the JPanel while its second endpoint is positioned along the right side of the JPanel such that all these second endpoints are evenly spread along the right side. The second endpoints are spread from the upper right corner to the lower right corner and are vertically apart from each other by height of JPanel divided by N. The JPanel should draw "nicely" when the window is resized. A window is resized when the user clicks on the (blue) JFrame and drags the mouse while pressed and then releases the mouse. Here, "nicely" means that the four lines should remain attached to the edges of the JPanel. Don't forget to put your JPanel in a JFrame (see figures 4.18 and 4.19 in the "Simple 2D Drawings" companion handout). The number N is specified by prompting the user with a Swing Dialog Box using JOptionPane.showInputDialog( ) (see companion handout "Simple Swing Dialogs"). o Add to your DrawPanel class an instance variable named numLines and a constructor that takes an argument N and initializes numLines by the value of N. o Add to your DrawPanelTest class code that prompts the user to specify N, the number of lines to draw: JOptionPane.showInputDialog("Enter number of lines between 2 and 100") o Validate that N is a positive integer between 2 and 100. If invalid, keep prompting the user (in a loop) until the user gives a valid response. o From DrawPanelTest construct a DrawPanel instance using your newly added constructor.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Heres an example implementation that meets the requirements described java impor... 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

Recommended Textbook for

Matlab An Introduction with Applications

Authors: Amos Gilat

5th edition

1118629868, 978-1118801802, 1118801806, 978-1118629864

More Books

Students also viewed these Programming questions