Related questions
Execute the following Java 2D Scene and explain what it does. Also, generate the image it produces:
import java.awt.*;
import java.awt.font.TextLayout;
import javax.swing.*;
import javafx.scene.effect.Shadow;
import java.awt.geom.*;
public class Scene2D extends JPanel
{
private GeneralPath hills;
private GeneralPath wind_fan;
private float pixelSize = (float) .01;;
private AffineTransform transformer;
public Scene2D() {
// hills
hills = new GeneralPath();
hills.moveTo(0,-.8);
hills.lineTo(0,1);
hills.curveTo(5,1.8F,4,2.2F,5,2.2F);
hills.curveTo(6,2.2F,6,2,7,2);
hills.lineTo(7,-.8);
hills.closePath();
wind_fan = new GeneralPath();
wind_fan.moveTo(0,0);
wind_fan.lineTo(1F,0.1F);
wind_fan.lineTo(1F,-0.1F);
wind_fan.closePath();
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setColor(Colors.BLACK.getValue());
Font f1 = new Font("Lucida Bright",Font.BOLD,10);
g2.setFont(f1);
TextLayout layout = new TextLayout("WIND ENERGY", f1, g2.getFontRenderContext());
g2.setPaint(new Color(150, 150, 150));
layout.draw(g2, 300 + 3, 455 + 3);
g2.setPaint(Color.BLACK);
layout.draw(g2, 300, 455);
Image theImage;
theImage = new javax.swing.ImageIcon("logo.png").getImage();
g2.drawImage(theImage,270,440,null);
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
setCoordinates(g2, getWidth(), getHeight());
// plot sky
g2.setColor(Colors.SKY.getValue());
g2.fillRect(0,0,7,4);
// hills
g2.setColor(Colors.HILLS.getValue());
g2.fill(hills);
// road
g2.setColor(Colors.ROAD.getValue());
g2.fill(new Rectangle2D.Double(0,-0.4,7,0.8));
// dashed lines on road
g2.setStroke( new BasicStroke(0.1F, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0,new float[] { 0.3F, 0.1F }, 1) );
g2.setColor(Color.WHITE);
g2.drawLine(0,0,7,0);
g2.setStroke( new BasicStroke(pixelSize) );
g2.setStroke( new BasicStroke(0.1F));
g2.setColor(Colors.ROADSIDE.getValue());
g2.draw(new Line2D.Double(0,.35,7,.35));
g2.draw(new Line2D.Double(0,-.35,7,-.35));
g2.setStroke( new BasicStroke(pixelSize) );
transformer = g2.getTransform();
// sun
g2.translate(5,3.3);
drawSun(g2);
g2.setTransform(transformer);
// wind energy
g2.translate(0.75,1);
g2.scale(0.6,0.6);
drawWind(g2);
g2.setTransform(transformer);
g2.translate(2.2,1.2);
g2.scale(0.4,0.4);
drawWind(g2);
g2.setTransform(transformer);
g2.translate(3.7,0.8);
g2.scale(1.0,1.0);
drawWind(g2);
g2.setTransform(transformer);
}
private void setCoordinates(Graphics2D g2, int width, int height)
{
double[] scaleRange = new double[] {0,7,4,-1};
g2.scale( width / (scaleRange[1]-scaleRange[0]), height / (scaleRange[3]-scaleRange[2]) );
g2.translate( -scaleRange[0], -scaleRange[2] );
}
private void drawSun(Graphics2D g2)
{
g2.setColor(Colors.YELLOW.getValue());
// plot rays with sun
for (int i = 0; i < 10; i++)
{
g2.rotate(degtorad(18)*2);
g2.drawLine(0,0,0,1);
}
float x = 0f;
float y = 0f;
float r = 1.35f;
x = (float) x-(r/2);
y = (float) y-(r/2);
g2.fill( new Ellipse2D.Float(x,y,r,r));
}
private void drawWind(Graphics2D g2)
{
// plot pole
g2.setColor(Colors.POLE1.getValue());
g2.fill(new Rectangle2D.Double(-0.05,0,0.1,1));
g2.setColor(Colors.POLE2.getValue());
g2.fill(new Rectangle2D.Double(-0.05,1,0.1,2));
g2.translate(0,3);
g2.setColor(Colors.WHITE.getValue());
float x = 0f;
float y = 0f;
float r = .25f;
x = (float) x-(r/2);
y = (float) y-(r/2);
g2.fill( new Ellipse2D.Float(x,y,r,r));
// plot winds
for (int i = 0; i < 6; i++)
{
g2.rotate(degtorad(60));
g2.fill(wind_fan);
}
}
private double degtorad(int angle)
{
return angle*Math.PI/180;
}
}
Colors.java
import java.awt.Color;
public enum Colors {
LIGHT_GRAY(Color.GRAY),DARK_GRAY(Color.DARK_GRAY),WHITE(Color.WHITE),GREEN(Color.GREEN),YELLOW(Color.YELLOW),SKY(new Color(150,150,255)),ROAD(new Color(100,100,150)),
WIND(new Color(100,100,200)),POLE1(new Color(255, 255, 102)),POLE2(new Color(200,200,225)),ROADSIDE(new Color(255, 255, 51)), BLACK(Color.BLACK),HILLS(new Color(0,150,30));
private final Color value;
private Colors(Color value) {
this.value = value;
}
public Color getValue() {
return value;
}
}
Driver.java
import java.awt.Dimension;
import javax.swing.JFrame;
public class Driver {
public static void main(String[] args) {
Scene2D scene = new Scene2D();
JFrame frame = new JFrame("Wind Energy");
frame.setPreferredSize( new Dimension(700,500));
frame.setContentPane( scene );
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps
- Create a UML class diagram of the application illustrating class hierarchy, collaboration, and the content of each class. There is only one class. There is a main method that calls four methods. I am not sure if I made the UML Class diagram correct. import java.util.Random; // import Random packageimport java.util.Scanner; // import Scanner Package public class SortArray{ // class name public static void main(String[] args) { //main method Scanner scanner = new Scanner(System.in); // creates object of the Scanner classint[] array = initializeArray(scanner); System.out.print("Array of randomly generated values: ");displayArray(array); // Prints unsorted array sortDescending(array); // sort the array in descending orderSystem.out.print("Values in desending order: ");displayArray(array); // prints the sorted array, should be in descending ordersortAscending(array); // sort the array in ascending orderSystem.out.print("Values in asending order: ");displayArray(array); // prints the...arrow_forwardplease code in java..refer the 2 codes BankAccount and AccountTest.. BankAccount source code is given below and AccountTest source code is added in image Question is to add code to be able to lock the account. for example if someone withdraws a certain amount of money the accounts locks, etc /** The BankAccount class simulates a bank account.*/ public class BankAccount{ private double balance; // Account balance /** This constructor sets the starting balance at 0.0. */ public BankAccount() { balance = 0.0; } /** This constructor sets the starting balance to the value passed as an argument. @param startBalance The starting balance. */ public BankAccount(double startBalance) { balance = startBalance; } /** This constructor sets the starting balance to the value in the String argument. @param str The starting balance, as a String. */ public BankAccount(String str) { balance =...arrow_forwardPlease help me create a matching game using java and 2D arrays. Create a reset button and titlearrow_forward
- Implement the following in the .NET Console App. Write the Bus class. A Bus has a length, a color, and a number of wheels. a. Implement data fields using auto-implemented Properies b. Include 3 constructors: default, the one that receives the Bus length, color and a number of wheels as input (utilize the Properties) and the Constructor that takes the Bus number (an integer) as input.arrow_forwardPlease help me fix the errors in the java program below. There are two class AnimatedBall and BouncingBall import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class AnimatedBall extends JFrame implements ActionListener{private Button btnBounce; // declare a button to playprivate TextField txtSpeed; // declare a text field to enterprivate Label lblDelay;private Panel controls; // generic panel for controlsprivate BouncingBall display; // drawing panel for ballContainer frame;public AnimatedBall (){// Set up the controls on the appletframe = getContentPane();btnBounce = new Button ("Bounce Ball");//create the objectstxtSpeed = new TextField("10000", 10);lblDelay = new Label("Enter Delay");display = new BouncingBall();//create the panel objectscontrols = new Panel();setLayout(new BorderLayout()); // set the frame layoutcontrols.add (btnBounce); // add controls to panelcontrols.add (lblDelay);controls.add...arrow_forwardimport javafx.application.Application; import javafx.geometry.*; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.event.*; import javafx.scene.text.*; public class SweepstakesJavaFX extends Application { private TextField first = new TextField(); private TextField last = new TextField(); private TextField phone = new TextField(); private TextField email = new TextField(); private TextField luckyNum = new TextField(); private TextField dob = new TextField(); public Label error = new Label(); public Label title = new Label("Sweepstakes Entry Form\nPlease complete the fields below"); public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { VBox labels = new VBox(); GridPane pane = new GridPane(); pane.setAlignment(Pos.CENTER); labels.setAlignment(Pos.CENTER);...arrow_forward
- Please help me with this using java. A starters code is provided (I created a starters code). For more info refer to the image provided. Please ensure tge code works Starter code:import javax.swing.*; import java.applet.*; import java.awt.event.*; import java.awt.*;public class halloween extends Applet implements ActionListener{ int hallow[] [] = ? int rows = 4; int cols = 3; JButton pics[] = new JButton [rows * cols]; public void init () { Panel grid = new Panel (new GridLayout (rows, cols)); int m = 0; for (int i = 0 ; i < rows ; i++) { for (int j = 0 ; j < cols ; j++) { pics [m] = new JButton (createImageIcon ("back.png")); pics [m].addActionListener (this); pics [m].setActionCommand (m + ""); pics [m].setPreferredSize (new Dimension (128, 128)); grid.add (pics [m]); } }m++; }}add (grid); }public void actionPerformed (ActionEvent...arrow_forwardI need help With this problem for JAVAFX. if possible can it work in eclipse. GeometricObjects code public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } /** Return color */ public String getColor() { return color; } /** Set a new color */ public void setColor(String color) { this.color = color; } /** Return filled. Since filled is boolean, * the get method is named isFilled */ public boolean isFilled() { return filled; } /** Set a new filled */ public void setFilled(boolean filled) { this.filled = filled; } /** Get dateCreated */ public java.util.Date getDateCreated() { return dateCreated; }...arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education