paulbradley
Programmer
Hi,
I have 3 very similar FocusListeners and have been trying to find a way of having one and the labels and accesors & mutators accessed chaning depending on who triggered the listener.
There are 3 textFields (tN, tP and tK) and 3 mutators and accessors (getN(), getP() and getK())
The currect code is as follows, how can I have just one of the following and get these little bits of code to relate to where the listener came from, many thanks in advance.
tN.addFocusListener(new FocusListener()
{
public void focusLost(FocusEvent fe)
{
try{
if( (Integer.parseInt(tN.getText())>=0)
&& ( (thedata.getP()!=0) || (thedata.getK()!=0)) ){
thedata.setN(Integer.parseInt(tN.getText()));
}else{
throw new IllegalArgumentException();
}
}catch(IllegalArgumentException e){
tN.setText(""+thedata.getN());
}
}
public void focusGained(FocusEvent fe){}
});
tP.addFocusListener(new FocusListener()
{
public void focusLost(FocusEvent fe)
{
try{
if( (Integer.parseInt(tP.getText())>=0)
&& ( (thedata.getN()!=0) || (thedata.getK()!=0)) ){
thedata.setP(Integer.parseInt(tP.getText()));
}else{
throw new IllegalArgumentException();
}
}catch(IllegalArgumentException e){
tP.setText(""+thedata.getP());
}
}
public void focusGained(FocusEvent fe){}
});
tK.addFocusListener(new FocusListener()
{
public void focusLost(FocusEvent fe)
{
try{
if( (Integer.parseInt(tK.getText())>=0)
&& ( (thedata.getP()!=0) || (thedata.getN()!=0)) ){
thedata.setK(Integer.parseInt(tK.getText()));
}else{
throw new IllegalArgumentException();
}
}catch(IllegalArgumentException e){
tK.setText(""+thedata.getK());
}
}
public void focusGained(FocusEvent fe){}
});
I have 3 very similar FocusListeners and have been trying to find a way of having one and the labels and accesors & mutators accessed chaning depending on who triggered the listener.
There are 3 textFields (tN, tP and tK) and 3 mutators and accessors (getN(), getP() and getK())
The currect code is as follows, how can I have just one of the following and get these little bits of code to relate to where the listener came from, many thanks in advance.
tN.addFocusListener(new FocusListener()
{
public void focusLost(FocusEvent fe)
{
try{
if( (Integer.parseInt(tN.getText())>=0)
&& ( (thedata.getP()!=0) || (thedata.getK()!=0)) ){
thedata.setN(Integer.parseInt(tN.getText()));
}else{
throw new IllegalArgumentException();
}
}catch(IllegalArgumentException e){
tN.setText(""+thedata.getN());
}
}
public void focusGained(FocusEvent fe){}
});
tP.addFocusListener(new FocusListener()
{
public void focusLost(FocusEvent fe)
{
try{
if( (Integer.parseInt(tP.getText())>=0)
&& ( (thedata.getN()!=0) || (thedata.getK()!=0)) ){
thedata.setP(Integer.parseInt(tP.getText()));
}else{
throw new IllegalArgumentException();
}
}catch(IllegalArgumentException e){
tP.setText(""+thedata.getP());
}
}
public void focusGained(FocusEvent fe){}
});
tK.addFocusListener(new FocusListener()
{
public void focusLost(FocusEvent fe)
{
try{
if( (Integer.parseInt(tK.getText())>=0)
&& ( (thedata.getP()!=0) || (thedata.getN()!=0)) ){
thedata.setK(Integer.parseInt(tK.getText()));
}else{
throw new IllegalArgumentException();
}
}catch(IllegalArgumentException e){
tK.setText(""+thedata.getK());
}
}
public void focusGained(FocusEvent fe){}
});