1 import java.awt.*; 2 import java.awt.event.*; 4 import javax.swing.*; 5 public class ShapeColorDraw extends JPanel { 6 //Setup the frame 7 8 public static void main(String[] args) { 9 10 JFrame window = new JFrame("ShapeColorDraw"); 11 12 window.setContentPane( new ShapeColorDraw() ); 13 14 window.setSize(1000,700); 15 L 16 window.setlocation(300,200); 17 18 window.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); 19 20 window.setVisible(true); 21 22 } 23 public void paint(Graphics g) { 24 //custom color String hexColor = new String("Ox45e5B"); g. setColor(Color.decode(hexColor)); String hexColor1 = new String("#ffc@d4"); g.setColor(Color.decode(hexColor1)); 29 25 26 27 28 String hexColor2 = new String("#003399"); g. setColor(Color.decode(hexColor2)); String hexColor3 = new String("#ff1493"); g.setColor(Color.decode(hexColor3)); 30 31 32 33 //Fill Rectangles with colors g.fillRect(70, 90, 450, 80); g. fillRect(300,300,300,300); g. fillRect(200,100,50,50); g.fillRect(400,200,100,50); 34 35 36 37 38 39 40 } 41 }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter14: Introduction To Swing Components
Section: Chapter Questions
Problem 15RQ
icon
Related questions
Question

Please, could you help me with my code? (I would like to attribute each color to one rectangle.)

.mport java.awt.*;
mport java.awt.event.*;
ShapeColorDraw
Transcribed Image Text:.mport java.awt.*; mport java.awt.event.*; ShapeColorDraw
s Window Help
1 import java.awt.*;
2 import java.awt.event.*;
3
4 import javax.swing.*;
5 public class ShapeColorDraw extends JPanel {
6 //Setup the frame
7
8 public static void main(String[] args) {
9.
10 JFrame window = new JFrame ("ShapeColorDraw");
11
12 window.setContentPane( new ShapeColorDraw() );
13
14 window.setSize(1000,700);
15 L
16 window.setLocation(300,200);
17
18 window.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE);
19
20 window.setVisible(true);
21
22 }
23 public void paint(Graphics g) {
24
//custom color
String hexColor = new String("Ox45e5B");
g. setColor (Color.decode (hexColor));
String hexColor1
g.setColor(Color.decode(hexColor1));
String hexColor2 = new String("#003399");
g.setColor(Color.decode(hexColor2));
String hexColor3 = new String("#ff1493");
g.setColor (Color.decode(hexColor3));
25
26
27
= new String("#ffc0d4");
28
29
30
31
32
33
//Fill Rectangles with colors
g.fillRect(70, 90, 450, 80);
g.fillRect(300,300,300,300);
g.fillRect(200,100,50,50);
g.fillRect(400, 200,100,50);
34
35
36
37
38
39
40 }
41 }
III
Transcribed Image Text:s Window Help 1 import java.awt.*; 2 import java.awt.event.*; 3 4 import javax.swing.*; 5 public class ShapeColorDraw extends JPanel { 6 //Setup the frame 7 8 public static void main(String[] args) { 9. 10 JFrame window = new JFrame ("ShapeColorDraw"); 11 12 window.setContentPane( new ShapeColorDraw() ); 13 14 window.setSize(1000,700); 15 L 16 window.setLocation(300,200); 17 18 window.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); 19 20 window.setVisible(true); 21 22 } 23 public void paint(Graphics g) { 24 //custom color String hexColor = new String("Ox45e5B"); g. setColor (Color.decode (hexColor)); String hexColor1 g.setColor(Color.decode(hexColor1)); String hexColor2 = new String("#003399"); g.setColor(Color.decode(hexColor2)); String hexColor3 = new String("#ff1493"); g.setColor (Color.decode(hexColor3)); 25 26 27 = new String("#ffc0d4"); 28 29 30 31 32 33 //Fill Rectangles with colors g.fillRect(70, 90, 450, 80); g.fillRect(300,300,300,300); g.fillRect(200,100,50,50); g.fillRect(400, 200,100,50); 34 35 36 37 38 39 40 } 41 } III
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT