Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java 1410 Getting Started: Download labBuilding.zip from Canvas and unzip it. Im

ID: 3663352 • Letter: J

Question

java 1410

Getting Started:

Download labBuilding.zip from Canvas and unzip it.

Import the extracted ( unzipped ) code files into Eclipse:

Right-click the src folder that should include the new package > Import ..
Select General > File System and click Next the Import from directory dialog opens Use the Browse button to navigate to the folder labBuilding and click OK
Select the checkbox next to the folder labBuilding
IMPORTANT: Select the checkbox next to Create to-level folder
Click Finish

Run the application to make sure that the file import worked as expected. Description:

Implement the overridden method paintComponent so that it paints a tall building with multiple rows of windows.

Requirements:

Use for loops to draw the windows.

Use random colors (every time the building is repainted some of the colors change randomly.

Which of the areas change is up to you.

***************************************

// building class
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class Building extends JPanel {
  
   @Override
   protected void paintComponent(Graphics g) {
super.paintComponent(g);

// TODO: write code to draw the building

   }

}

*********************************************

// buildingApp class

package labBuilding;

import javax.swing.JFrame;

@SuppressWarnings("serial")
public class BuildingApp extends JFrame {

   public static void main(String[] args) {
new BuildingApp().run();
   }
  
   public void run() {
setBounds(100, 10, 400, 500);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
add(new Building());
   setVisible(true);
   }

}

Explanation / Answer

Then create a random generator:

As colours are separated into red green and blue, you can create a new random colour by creating random primary colours:

Then to finally create the colour, pass the primary colours into the constructor:

You can also create different random effects using this method, such as creating random colours with more emphasis on certain colours ... pass in less green and blue to produce a "pinker" random colour.

Or to ensure that only "light" colours are generated, you can generate colours that are always > 0.5 of each colour element:

There are various other colour functions that can be used with the Color class, such as making the colour brighter: