when you refer this
within the anonymous class, it refers to the anonymous class instance itself. Since you are creating a Runnable
anonymous instance, this refers to that Runnable
instance.
JOptionPane.showMessageDialog(..)
does't accept Runnable
, so you might want to do something like this
private void connectivityChecker() {
Runnable r = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000);
}catch(Exception exc) {
System.out.println("Thread Interrupted !");
}
boolean isConnected = Internet.isConnected();
if(!isConnected) {
showErrorMessage("You have lost connectivity to the server", "Connection Error" );
}
}
};
new Thread(r,"Connectivity Checker - UserGUI").start();
}
private void showErrorMessage(String message, String header) {
JOptionPane.showMessageDialog(this, message, header, JOptionPane.ERROR_MESSAGE);
}
In above, since this
is called from showMessage()
, it refers to the instance of the main class in which showMessage()
is defined