Saturday, 10 August 2013

Controlling JComponents from other classes

Controlling JComponents from other classes

Is it possible to control instances like variables, jcomponents, timer in
other external classes?
For example this is my Class1
public class Class1 extends JFrame {
JLabel lbl = new JLabel("Hello");
public Class1() {
super("Class1");
Container c = getContentPane();
setLayout(null);
c.add(lbl);
lbl.setBounds(0,0,100,20);
Class2.process();
setSize(200,100);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String var[]) {
new Class1();
}
}
You can see there's Class2.process(); Here's the other class externally
but in the same folder
public class Class2 {
public static void process() {
// I want to control lbl from Class1 class inside this method like
// lbl.setVisible(false);
}
public static void main(String args[]) {
//
}
}
Is it possible? Sorry. I can't find answers on other website.

No comments:

Post a Comment