Load a canvas from a main class - Java
I have a MyCanvas class that extends JComponent. On this canvas I have drawn a couple of things and has its own main method.
public static void main(String args[]) {
JFrame mainFrame = new JFrame("Graphics demo");
mainFrame.getContentPane().add(new开发者_如何学运维 Canvas0_1());
mainFrame.pack();
mainFrame.setVisible(true); }
How do I call to load the canvas from my program's other main method. Is this possible?
It is possible but probably not what you need. If you insist just try:
class OtherClass {
public static void main( String [] args ) {
MyCanvas.main( args );
}
}
And that's it.
I think it will be better if you create an instance of your canvas and add it to another component and not use it directly from main
精彩评论