So I have a class that extends JFrame and has a main method in it.
Main looks like this:
public static void main( String args[] ) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new MyJFrame().setVisible(true);
}
});
}
The problem is, I want to pass the arguments that main receives to the MyJFrame constructor, but it won't work since I can't access the main() variables inside an "inner class" (according to netbeans). I admit that I don't know exactly how that code I just posted works, since it's an example that is everywhere and works.
Anyway, I belive that doing "new Runnable()" is like declaring a class that implements Runnable, and public void run() is just the implementation of the only method that is in the Runnable interface.
But it won't let me pass arguments to it, and I don't know if should make the class MyJFrame to implement Runnable. I don't even know how that would work out anyway.
I think that it will only let me pass final static arguments.
Any ideas on how I can pass those arguments that main receives to the MyJFrame constructor inside run() ?
Question
Julius Caro
So I have a class that extends JFrame and has a main method in it.
Main looks like this:
The problem is, I want to pass the arguments that main receives to the MyJFrame constructor, but it won't work since I can't access the main() variables inside an "inner class" (according to netbeans). I admit that I don't know exactly how that code I just posted works, since it's an example that is everywhere and works.
Anyway, I belive that doing "new Runnable()" is like declaring a class that implements Runnable, and public void run() is just the implementation of the only method that is in the Runnable interface.
But it won't let me pass arguments to it, and I don't know if should make the class MyJFrame to implement Runnable. I don't even know how that would work out anyway.
I think that it will only let me pass final static arguments.
Any ideas on how I can pass those arguments that main receives to the MyJFrame constructor inside run() ?
Link to comment
Share on other sites
1 answer to this question
Recommended Posts