import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* The Class <code>FrameKeyListenerTest</code>.
*/
public class FrameKeyListenerTest extends JFrame implements KeyListener {
/** The subject text field. */
private JTextField textSubject;
/**
* Create a new instance of <code>FrameKeyListenerTest</code>.
*/
public FrameKeyListenerTest() {
super();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
final JLabel labelSubject = new JLabel("Betreff:");
textSubject = new JTextField(10);
textSubject.addKeyListener(this);
final JPanel panelSubject = new JPanel();
panelSubject.add(labelSubject);
panelSubject.add(textSubject);
getContentPane().add(panelSubject, BorderLayout.NORTH);
}
/** {@inheritDoc} */
public void keyReleased(KeyEvent e) {
if (e.getSource() == textSubject) {
setTitle(textSubject.getText());
}
}
/** {@inheritDoc} */
public void keyTyped(KeyEvent e) {
}
/** {@inheritDoc} */
public void keyPressed(KeyEvent e) {
}
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
final JFrame frame = new FrameKeyListenerTest();
final Dimension frameSize = new Dimension(600, 400);
frame.setSize(frameSize);
final Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
final int frameX = (screenSize.width - frameSize.width) / 2;
final int frameY = (screenSize.height - frameSize.height) / 2;
frame.setLocation(frameX, frameY);
frame.setVisible(true);
}
}