package Program1;
import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Scanner;
public class Demo extends Applet{
static int i=0;
public static void test(){
i=50;
System.out.println("This is my static method");
}
public void paint (Graphics g) {
test();
g.drawOval (60, 20, i, i);
}
}
I have two method paint and test. I want to execute test method only once which is going to initialize the value of i and that i am going to use in paint method. But the problem is when I am executing the program it is calling text method once and when I am re-sizing the Applet window it is calling that test method again and again.
For my program the text method do lot of computation so calling test method just to assign the value again and again is not a good choice. How to call that Demo class only once ?
Using constructor class I can call this test method once.
package Program1;
import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Scanner;
public class Demo extends Applet{
static int i=0;
public static void test(){
i=50;
System.out.println("This is my static method");
}
public Demo(){
test();
}
public void paint (Graphics g) {
g.drawOval (60, 20, i, i);
}
}