Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using this code, answer following problems: package graphichal2; import java.awt.Color; import java.awt.Graphics; import java.util.Random; import javax.swing.JFrame; import javax.swing.JPanel; public class ModernArtGenerator extends JPanel { private

Using this code, answer following problems:

package graphichal2; import java.awt.Color; import java.awt.Graphics; import java.util.Random; import javax.swing.JFrame; import javax.swing.JPanel; public class ModernArtGenerator extends JPanel { private static final long serialVersionUID = 1L;

public ModernArtGenerator() { setBackground(Color.WHITE);

}

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

int x,y,width,height;

Random rand = new Random();

for(int i=0;i<50;i++){

//set random color and opacities

g.setColor(new Color(rand.nextInt(255), rand.nextInt(255), rand.nextInt(255),rand.nextInt(255)));

//set random x and y position

width = rand.nextInt(91)+10;

height = rand.nextInt(91)+10;

x = rand.nextInt(600-width);

y = rand.nextInt(300-height);

//get random width and height

g.fillRect(x, y, width,height);

}

}

public static void main(String[] args) {

JFrame jFrame = new JFrame();

jFrame.setSize(600, 300);

jFrame.add(new ModernArtGenerator());

jFrame.setVisible(true);

jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

Problem 1: In this program, you are required to improve the features of the Modern Art program that you developed in Assignment 3 Problem 2. In the enhanced feature version of the Modern Art generator, you will include the following new elements:

a) A combo box with the elements Circle and Rectangle. The selected item from the combo box will trigger the handler, and will either use circles or rectangles, based on the choice of the user, to generate the Modern Art. The default selection will be Circle.

Note: Write a new function to generate a circle with a random radius.

b) A text field (along with a label for it) for the total number of objects to be used in the Modern Art. The number of objects will be applied for both circles and rectangles. You will need to include a handler for the text field, which will be triggered when the user hit the Enter key on the keyboard. The handler will redraw the Modern Art with the current value of the number of objects in the text field. The default value should be 50.

c) A text field (along with a label for it) for the maximum size objects to be used in the Modern Art. The size of objects will be applied for both circles and rectangles. The max size of circles will define the radius, and the max size for rectangles will define the maximum length and width. You will need to include a handler for the text field, which will be triggered when the user hit the Enter key on the keyboard. The handler will redraw the Modern Art with the current size of objects in the text field. The default value should be 100.

d) You will include a Draw button to refresh the displayed Modern Art. The draw button will update the combo box selection, object count, and the maximum size, and then redraw the Modern Art.

Use the basic Pane class to place the circles/rectangles so that absolute object placement is allowed for the random objects in the artwork, and call this pane the artworkPane. Use an HBox pane to place the newly added fields and button, and call it the drawingBarPane. Next, use a BorderPane, and place the artworkPane in the center cell, and the drawingBarPane in the bottom cell.

Problem 2: In this program, you will continue to improve the features of the Modern Art program. In the enhanced feature version 2 of the Modern Art generator, you will include the following new elements:

a) Add an animation feature to the modern art generator. Use a Timeline animation, and call the handler to update the artworkPane by adding random circles/rectangles to the modern art. The choice of shape (circles/rectangles) will be based on the selected item by the user in the combo box.

b) Add a button to control the animation. The handler for the button will toggle the label between Play and Pause to play/pause the animation.

c) Add a label and a slider to control the speed of the animation. Use property binding to bind the value property of the slider to the rate property of the timeline animation. Set the min of the slider to 10, and the max to 100.

Include two rows of controls in the bottom cell of the Border Pane. Add the animation label, the play/pause button, and the slider in an HBox, and call this pane animationlPane. Place drawingBarPane (from Problem 1) and animationPane in a VBox, and call it controlBarPane. Place the controlBarPane in the bottom cell of the BorderPane.

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

List some popular analytical tools.

Answered: 1 week ago