문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top