Page 1 of 1

CD ON 16 1 import javax.swing.*; 2 import java.awt.*; 3 public class Locker extends JPanel { 4 JFrame f = new JFrame ("L

Posted: Sun May 15, 2022 2:06 pm
by answerhappygod
Cd On 16 1 Import Javax Swing 2 Import Java Awt 3 Public Class Locker Extends Jpanel 4 Jframe F New Jframe L 1
Cd On 16 1 Import Javax Swing 2 Import Java Awt 3 Public Class Locker Extends Jpanel 4 Jframe F New Jframe L 1 (304.87 KiB) Viewed 74 times
CD ON 16 1 import javax.swing.*; 2 import java.awt.*; 3 public class Locker extends JPanel { 4 JFrame f = new JFrame ("Locker"); 5 JPanel p = new JPanel(); JButton[] b = new JButton[12]; int h = 0; 8 Locker() { 9 this.setBackground (Color.black); 10 p.setLayout (new GridLayout(4,3)); 11 b[0] = new JButton(""); 12 b[10] = new JButton ("X"); 13 b[11] = new JButton ("Y"); 14 for(int i = 1; i<=9; i++) { 15 b = new JButton(""+i); p.add(b); 17 } 18 p.add(b[10]); 19 p.add(b[0]); 20 p.add(b[11]); 21 f.add(this); 22 f.add(p, BorderLayout . EAST); 23 f.setSize(500,300); 24 f.setVisible(true); 25 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ; 26 } 27 protected void paint Component (Graphics g) { 28 super.paintComponent (g); 29 g.setColor (new Color (50,100,50)); //Green 11 30 g.fillRect(5, 5, getWidth()-10, getHeight()-10-h); 31 g.setColor (new Color (50,150,50)); //Green #2 32 g.drawRect(5, 5, getWidth()-10, getHeight()-10); 33 g.setColor (Color.black); 34 g.filloval (getWidth()/2-15, getHeight()-80-h, 30, 30); g.fillRect (getWidth()/2-15, getHeight()-50-h, 30, 30); g.setColor (new Color (50,100,50)); 1/Green #1 37 g.fillArc (getWidth()/2-15, getHeight()-50-h, 38 30, 30, 360-15, 30); g.fillArc (getWidth()/2-15, getHeight()-50-h, 40 30, 30, 180-15, 30); 41 } 42 public static void main(String[] args) { 43 new Locker(); 44 } 45 } NNNNNNNNNNMmmmmmmmmm NOC 35 36 39 N 3.1 Sketch the output when the program is executed. In your sketch, you must provide all coordinates of the graphic comprehensively. (8 points) 3.2 When is the method paintComponent(Graphics g) called? (1 point) 3.3 Where does the Graphics object g come from? (Who creates it?) (1 point)