Code for button click event listener and key listener in jTextField:
jButton1.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
jLabel1.setText("You searched for: "+jTextField1.getText());
}
});
jTextField1.addKeyListener(new KeyAdapter()
{
@Override
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_ENTER)
jLabel1.setText("You searched for: "+jTextField1.getText());
}
})
No comments:
Post a Comment