This is a debug from any help would be awesome. I will award points upon complet
ID: 3547980 • Letter: T
Question
This is a debug from any help would be awesome. I will award points upon completion.
Debug 1
// Lets user type keys
// Displays key typed
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class DebugFifteen3 extends JFrame implements KeyListener
{
char key;
Container con = null;
GridLayout grid = new GridLayout(2, 1);
JLabel label = new JLabel("Key Typed:");
JTextArea textArea = new JTextArea(4, 25);
public DebugFifteen3()
{
setTitle("Debug Key Frame");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
con = this.getcontentPane();
con.setLayout(gridd);
con.add(textArea);
con.add(Label);
addKeyListener(this);
textArea.addKeyListener(this);
}
public void keyTyped(KeyEvent e)
{
char c = c.getKeyChar();
label.setText ("Key Typed: " + c);
}
public void keyReleased(KeyEvent e)
{
}
public static void main(String[] args)
{
DebugFifteen3 kFrame = new DebugFifteen3();
kFrame.setSize(300, 200);
kFrame.setVisible(true);
}
}
Explanation / Answer
I have debugged and pasted the correct working code...
please note : keyPressed(KeyEvent e) --> this method is required to be added....
Code :
//Lets user type keys
//Displays key typed
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class DebugFifteen3 extends JFrame implements KeyListener
{
char key;
Container con = null;
GridLayout grid = new GridLayout(2, 1);
JLabel label = new JLabel("Key Typed:");
JTextArea textArea = new JTextArea(4, 25);
public DebugFifteen3()
{
setTitle("Debug Key Frame");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
con = this.getContentPane();
con.setLayout(grid);
con.add(textArea);
con.add(label);
addKeyListener(this);
textArea.addKeyListener(this);
}
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
label.setText("Key Typed: " + c);
}
public void keyReleased(KeyEvent e)
{
}
@Override
public void keyPressed(KeyEvent e) {
}
public static void main(String[] args)
{
DebugFifteen3 kFrame = new DebugFifteen3();
kFrame.setSize(300, 200);
kFrame.setVisible(true);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.