I’m trying to repaint() from another class. I know one way to do this:
//FromClass.java:
SomeClass whatever = new SomeClass(this);
//SomeClass.java:
FromClass f;
public SomeClass(FromClass from){ //constructor
f = from;
}
//after a long part of code
f.repaint();
Is there any other way to do this, without any parameters in class constructor?
And sorry for my technical English, still learning.
There are numerous ways to share information between classes. I believe that the method you demonstrated is the most effective. Here are some other options:
Make
SomeClassa subclass ofFromClassso that it inherits all of the methods defined inFromClass. Then create an instance ofFromClassand call methods on the variable. Your class declaration would look like this:Make
FromClassan interface and implement it:Just some other alternatives. 🙂