1 import javax.swing.*; 2 import java.awt.event. 3 import java.awt.*; 4 6 8 9 5 public class KeyDetection extends JPanel
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
1 import javax.swing.*; 2 import java.awt.event. 3 import java.awt.*; 4 6 8 9 5 public class KeyDetection extends JPanel
1 import javax.swing.*; 2 import java.awt.event. 3 import java.awt.*; 4 6 8 9 5 public class KeyDetection extends JPanel implements KeyListenert JLabel 11 = new JLabel("PRESS ANY KEY", SwingConstants.CENTER); 7 JLabel 12 = new JLabel("", SwingConstants.CENTER); KeyDetection () { set Layout (new Border Layout()); 10 11. setFont (new Font ("Verdana", Font.PLAIN, 16)); 11 12. setFont (new Font ("Verdana", Font.BOLD, 50)); 12 add (11, BorderLayout. NORTH); 13 add (12); 14 addKeyListener(this); 15 setFocusable(true); } public void keyPressed (KeyEvent e) {} 18 public void keyTyped (KeyEvent e) { 19 12.setText (Character.toString(e.getKeychar())); 20 } 21 public static void main(String[] args) { 22 JFrame f = new JFrame ("Press a key"); 23 f.add(new KeyDetection()); 24 f.setLocation (40,150); 25 f.setSize(350,125); 26 f.setVisible(true); 27 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ; 28 29 ) 0 000 16 17 NNNNNNNNNNEEEEEEE DoN 8.1 What is the purpose of the statement setFocusable(true) at line 15? (2 points) 8.2 When you run this class, you will get an error. Why do you get the error? Fix it and explain how to fix it comprehensively. (3 points) 8.3 Sketch the location and size of the frame relative to the computer screen. (1 point) 8.4 What is the purpose of the method toString at line 19? (1 point)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!