import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RecallStudy extends JFrame
implements KeyListener,
ActionListener
{
//CREATION OF ELEMENTS
JLabel recallLabel;
JTextField enterText;
String enterTex;
JTextField recieveText;
JPanel displayInfo;
GridBagConstraints constraints = new GridBagConstraints();
public static void main (String [] args) {
//MAKING THE WINDOW
JFrame frame = new JFrame("RecallStudy");
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setSize(500, 500);
frame.setLocation(200, 200);
frame.setContentPane(new RecallStudy());
frame.pack();
frame.setVisible(true);
}
//GRIDLAYOUT CONSTRUCTION
public RecallStudy() {
setLayout(new GridBagLayout());
constraints.weightx = 3.0;
constraints.weighty = 3.0;
constraints.fill = GridBagConstraints.BOTH;
int x, y; // for clarity
constraints.gridheight = 2; // span two rows
addGB(recieveText, x =2, y = 1);
constraints.gridheight = 2; // set it back
addGB(enterText, x = 0, y = 1);
constraints.gridwidth = 1; // span two columns
addGB(new JLabel("Recall"), x = 1, y = 0);
constraints.gridwidth = 2; // set it back
addGB(new JLabel(""), x = 0, y = 0);
constraints.gridwidth = 1;
addGB(new JLabel(""), x = 2, y =0);
constraints.gridwidth = 1;
addGB(new JLabel(""), x = 2, y = 2);
constraints.gridwidth = 1;
addGB (new JLabel(""), x = 0, y =2);
constraints.gridwidth = 1;
//Set the proper restrictions on the listeners
enterText.addKeyListener(this);
recieveText.setEditable(false);
}
void addGB(Component component, int x, int y) {
constraints.gridx = x;
constraints.gridy = y;
add(component, constraints);
}
public RecallStudy(String name) {
super (name);
}
public void keyTyped(KeyEvent e) {
displayInfo(e, "KEY TYPED: ");
}
/** Handle the key pressed event from the text field. */
public void keyPressed(KeyEvent e) {
displayInfo(e, "KEY PRESSED: ");
}
/** Handle the key released event from the text field. */
public void keyReleased(KeyEvent e) {
displayInfo(e, "KEY RELEASED: ");
}
/** Handle the button click. */
public void actionPerformed(ActionEvent e) {
//Clear the text components.
enterText.setText("");
recieveText.setText(enterTex);
//Return the focus to the typing area.
enterText.requestFocusInWindow();
}
private void displayInfo (KeyEvent e, String keyStatus) {
}
}
For some reason, this code is not running...I cannot understand why...can someone please explain? I do not get any errors on my code when I just have it down, but the second I try to run it it does not work. I am confused as to what components I am missing to make it run. I know that I have not finished the displayInfo section, but that does not seem to be the reason why it won't run. I am just really confused, I feel like I started this code the same way I do every other but this one just won't run.