Question
can you fix my java project? (i dont know how to set the different height for the second row and third row) Rainbow.java import java.awt.Color;
can you fix my java project? (i dont know how to set the different height for the second row and third row)
Rainbow.java
import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JComponent; import java.awt.Rectangle;
public class Rainbow { private int x; private int y; public Rainbow(int x1, int y1){ x=x1; y=y1; } public Rainbow(){ x=0; y=0; } public void draw(Graphics2D g2){ Rectangle qBox = new Rectangle(x,y,100,20); g2.setColor(Color.RED); g2.fill(qBox); Rectangle wBox = new Rectangle(x,y+20,100,20); g2.setColor(Color.ORANGE); g2.fill(wBox); Rectangle eBox = new Rectangle(x,y+40,100,20); g2.setColor(Color.YELLOW); g2.fill(eBox); Rectangle rBox = new Rectangle(x,y+60,100,20); g2.setColor(Color.GREEN); g2.fill(rBox); Rectangle tBox = new Rectangle(x,y+80,100,20); g2.setColor(Color.BLUE); g2.fill(tBox); Rectangle uBox = new Rectangle(x,y+100,100,20); Color indigo = new Color(75,0,130); g2.setColor(indigo); g2.fill(uBox); Rectangle iBox = new Rectangle(x,y+120,100,20); Color violet = new Color(143,0,255); g2.setColor(violet); g2.fill(iBox); } }
RainbowComponent.java
import java.awt.Graphics; import java.awt.Graphics2D;
import javax.swing.JComponent;
public class RainbowComponent extends JComponent {
private static final long serialVersionUID = 1L; public void paintComponent(Graphics g) { // Recover Graphics2D Graphics2D g2 = (Graphics2D) g; Rainbow flight1 = new Rainbow(0,0); flight1.draw(g2); Rainbow flight2 = new Rainbow(100,180); flight2.draw(g2); Rainbow flight3 = new Rainbow(0,200); flight3.draw(g2); }
}
Upper left-hand corner at 0,0. Height of 20
Upper left-hand corner at 100, 180. Height of 10
Upper left-hand corner at 0, 200. Height of 5
ImageStep 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