I have a frame showing some textfields and a couple of buttons, the classical "Ok" and "Reset" buttons, which are supposed to confirm the values of the textfields (closing the frame) and reset them respectively.
I think I thoroughly followed the "delegation method procedure" for managing event, that is , create the button object, define a listener class (implementing the ActionListener interface) , and add the listener class to the button using the "addActionListener" method . But there's no way to make the whole thing works.
No exception. Only when I click the button the "actionPerformed" method of the listener is simply ignored, as if it didn't exist.
What is the problem ?
Here is the code :
public FrameViewAddEstrazione (String ExtrPath)
{
try
{
FilePath = ExtrPath;
F = new JFrame ();
PP = new JPanel();
PD = new JPanel();
PE = new JPanel();
PX = new JPanel();
F.setLayout (new BoxLayout(F.getContentPane(), BoxLayout.Y_AXIS));
F.add(PP); F.add(PD); F.add(PE); F.add(PX);
JLabel LP = new JLabel ();
TP = new JTextField (ExtrPath);
TP.setColumns(40);
PP.add (LP); PP.add(TP);
JLabel LYear = new JLabel ("Year"); TYear = new JTextField("",4) ;
JLabel LMonth = new JLabel ("Month"); TMonth = new JTextField("",2) ;
JLabel LDay = new JLabel ("Day"); TDay = new JTextField("",2) ;
PD.add(LYear); PD.add(TYear); PD.add(LMonth); PD.add(TMonth); PD.add(LDay); PD.add(TDay);
JLabel EL = new JLabel("Estrazioni");
E1 = new JTextField ("",2);
E2 = new JTextField ("",2);
E3 = new JTextField ("",2);
E4 = new JTextField ("",2);
E5 = new JTextField ("",2);
E6 = new JTextField ("",2);
PE.add(EL); PE.add (E1); PE.add(E2); PE.add(E3); PE.add(E4); PE.add(E5); PE.add(E6);
BOK = new JButton ("Ok");
BReset = new JButton ("Reset");
PX.add (BOK); PX.add(BReset);
BOK.addActionListener (this);
BReset.addActionListener(this);
F.setSize(400, 200);
F.setVisible(true);
}
catch (Exception E)
{
E = E;
}
}
public void actionPerformed(ActionEvent e)
{
try
{
String Cmd = e.getActionCommand();
String File ="", chunk;
BufferedReader S = new BufferedReader (new FileReader (FilePath));
chunk = S.readLine();
while (chunk != "")
{
File += chunk;
chunk = S.readLine();
}
if (Cmd == "OK")
{
F.setVisible(false);
}
if (Cmd =="Reset")
{
TP.setText(FilePath);
TYear.setText(""); TMonth.setText(""); TDay.setText("");
E1.setText("");
E2.setText("");
E3.setText("");
E4.setText("");
E5.setText("");
E6.setText("");
}
}
catch (Exception E)
{
E=E ;
}
}