Page 1 of 1

9 1 import java.awt.*; 2 import javax.swing.*; 3 4 =public class Stickman extends JPanel { 5 JFrame f = new JFrame(); 6

Posted: Sun May 15, 2022 2:06 pm
by answerhappygod
9 1 Import Java Awt 2 Import Javax Swing 3 4 Public Class Stickman Extends Jpanel 5 Jframe F New Jframe 6 1
9 1 Import Java Awt 2 Import Javax Swing 3 4 Public Class Stickman Extends Jpanel 5 Jframe F New Jframe 6 1 (276.37 KiB) Viewed 53 times
9 1 import java.awt.*; 2 import javax.swing.*; 3 4 =public class Stickman extends JPanel { 5 JFrame f = new JFrame(); 6 Stickman (String t) { setBackground (Color.black); 8 f.setTitle(t); f.add(this); 10 f.setSize(400,400); 11 f.setVisible(true); 12 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ; 13 } 14 protected void paintComponent (Graphics g) { 15 super.paint Component (g); 16 g.setColor (Color.white); 17 g.drawLine(0, 300, getWidth(), 300); 18 g.fillRect (getWidth()/2, 250, 19 getWidth()/2, 50); 20 g.fillRect (getWidth()/2+50, 200, 21 getWidth()/2-50, 100); 22 g.fillRect (getWidth()/2+100, 150, 23 getWidth()/2-100, 150); 24 position1 (g); 25 } 26 void position1 (Graphics g) 27 int[] x = {153, 193, 213, 223); 28 int[] y = {300, 230, 210, 250); g.drawoval (173, 150, 40, 40); 30 g.drawLine (193, 190, 193, 230); 31 g.drawPolyline (x, y, 4); 32 g.drawLine (153, 210, 223, 190); 33 ) 34 public static void main(String[] args) { 35 Stickman robert = new Stickman ("Stickman"); System.out.println(robert.getWidth()); 37 } 38 } 0 HHHHHHHHNNNNNNNNNNmmmmmmmmm DOWNOOOOOWNoLCOWE 29 36 4.1 Given that the output of the statement System.out.println(robert.getWidth() is 386, sketch the output when the program is executed. You must provide all coordinates comprehensively. (5 points) 4.2 Write a new method, named position2(Graphics g), that draws a stickman standing at the top of the stair. And sketch your designed position with coordinates. (4 points) 4.3 Modify the class Stickman by adding another stickman standing at the top of the stair after the program is executed. (1 point)