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 }
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 }
Chapter14: Introduction To Swing Components
Section: Chapter Questions
Problem 15RQ
Related questions
Question
Please, could you help me with my code? (I would like to attribute each color to one rectangle.)
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
Knowledge Booster
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.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT