-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.3.0
-
x86
-
windows_nt
Name: sl110371 Date: 07/24/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
The actionPerformed() method is not getting fired, when Enter(Return) key is
pressed on a JButton, which has been focussed. The code used to work with Java
1.1.3, but fails to fire the actionPerformed event with java 1.3.
The modified source code, that could be used to reproduce the problem is given
here.
********************************************************************************
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MainPortfolio extends JFrame implements ActionListener
{
protected Container MainRootPane;
protected JLabel StatusLabel, UserLabel;
protected JTextField NameField;
String UserName;
protected JButton SelectButton;
protected JButton UpdateButton;
protected JButton ExitButton;
protected JPanel PanelNorth;
protected JPanel PanelSouth;
protected JPanel PanelCenter;
protected JPanel OptionPanel;
protected JLabel ImgLabel;
public MainPortfolio()
{
super("Main Portfolio Frame");
MainRootPane = getContentPane();
PanelNorth = new JPanel();
PanelSouth = new JPanel();
PanelCenter = new JPanel(new GridLayout(1,2,5,5));
OptionPanel = new JPanel(new GridLayout(3,1,5,5));
UserLabel = new JLabel("Enter the User name and select Option");
NameField = new JTextField(15);
PanelNorth.setBackground(Color.orange);
UserLabel.setForeground(Color.blue);
PanelNorth.add(UserLabel);
PanelNorth.add(NameField);
StatusLabel = new JLabel("Main Portfolio Frame");
PanelSouth.setBackground(Color.orange);
StatusLabel.setForeground(Color.blue);
PanelSouth.add(StatusLabel);
ImgLabel = new JLabel("Portfolio");
SelectButton = new JButton("Select Portfolio");
UpdateButton = new JButton("Update Portfolio");
ExitButton = new JButton("Exit");
addCompToCenterPanel();
MainRootPane.add(PanelNorth, BorderLayout.NORTH);
MainRootPane.add(PanelSouth, BorderLayout.SOUTH);
MainRootPane.add(PanelCenter, BorderLayout.CENTER);
setSize(600, 500);
}
public void addCompToCenterPanel()
{
PanelCenter.add(ImgLabel);
addBtnToOptionPanel();
PanelCenter.add(OptionPanel);
}
public void addBtnToOptionPanel()
{
OptionPanel.setBackground(Color.magenta);
SelectButton.setBackground(Color.blue);
SelectButton.setForeground(Color.yellow);
OptionPanel.add(SelectButton);
SelectButton.addActionListener(this);
UpdateButton.setBackground(Color.blue);
UpdateButton.setForeground(Color.yellow);
OptionPanel.add(UpdateButton);
UpdateButton.addActionListener(this);
ExitButton.setBackground(Color.blue);
ExitButton.setForeground(Color.yellow);
OptionPanel.add(ExitButton);
ExitButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
UserName = NameField.getText();
if (e.getSource() == SelectButton)
{
StatusLabel.setText(" Select Button Pressed by " + UserName);
}
else if(e.getSource() == UpdateButton)
{
StatusLabel.setText(" Update Button Pressed by " + UserName);
}
else if(e.getSource() == ExitButton)
{
System.exit(0);
}
}
public static void main(String xxx[])
{
MainPortfolio MP = new MainPortfolio();
MP.setVisible(true);
MP.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
(Review ID: 107427)
======================================================================
- duplicates
-
JDK-4224702 JButton doesn't handle return key event
-
- Resolved
-