marcoamorales marcoamorales - 1 year ago 84
Java Question

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.setVisible(true); }

How do I call to load the canvas from my program's other main method. Is this possible?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download