Thursday, August 7, 2008

InputVerifier problem.(javax.swing.InputVerifier)

Problem with showing Message Dialog in InputVerifier -
1. It goes in a recurring loop
2.Shows StackOverflowError
It results in showing error message dialog in a recurrsive loop, Here is the solution to avoid it.
Solution :
boolean verified = false;
public boolean verify(JComponent input){
if (verified) {
return false;
}
verified = true;
JTextField sampleT= (JTextField) input;
if(sampleT.getText().equals("Exit")){
verified = false;
return true;
}else{
JOptionPane.showMessageDialog(source,"Can't leave.", "Error Dialog", JOptionPane.ERROR_MESSAGE);
verified = false;
return false;
}
}

Sunday, July 20, 2008

Fun side

"If debugging is the process of removing bugs, then programming must be the process of putting them in." --- Edsger Dijkstra

"Any sufficiently advanced bug is indistinguishable from a feature." --- Bruce Brown

Tuesday, May 27, 2008

Exceptions :
1.
public static int returnTest(){
try{
return 1;
}
catch(Exception e){
return 2;
} finally{
return 3;
}
}
What will returntest method return???

Ans : is 3.

If we have finally block it will always get called .
If we remove the finally block if will print 1.


2.
public class Test6
{
public static void main(String args[]) throws Exception{
try{
throw new Exception();
} finally{
System.out.println("No Error");
} }}
Here it will print No Error followed by java.lang.Exception.