Results 1 to 6 of 6
  1. #1
    javaNewblet is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default Class Communication/ Main Method

    Hi all,

    I have a main GUI class as seen here:

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    
    /*
     * Class is to communicate with various other classes in the program to
     * create a roster for user based on their selection on GUI.
     */
    public class MainGUI extends JFrame
    {
    	private static final long serialVersionUID = 1L;
    	//declares window width and height for program
    	final int WINDOW_WIDTH = 1000;
    	final int WINDOW_HEIGHT= 1000;
    	
    	private PlatoonPanel pp;
    	private SquadPanel sp;
    	private ManualPanel mp;
    	private ActionButtons ab;
    	private static Container pane;
    
    	public MainGUI()
    	{
    		//sets title
    		setTitle("Roster Generator Version 0.0.1");
    		//sets window width and height
    		setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    		//sets default close operation
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		pane = getContentPane();
    		
    		//creates new class objects
    		pp = new PlatoonPanel();
    		sp = new SquadPanel();
    		mp = new ManualPanel();
    		ab = new ActionButtons();
    		
    		//calls buildGUI() method
    		buildGUI();
    		//sets visible to true
    		setVisible(true);
    	}
    	
    	//method that combines all the other panels from other classes and
    	//combines them into one
    	public void buildGUI(){
    		//sets border layout for main panel
    		pane.setLayout(new BorderLayout());
    		//adds other panels to this main panel
    		pane.add(pp.getPlatoonRosterPanel(), BorderLayout.WEST);
    		pane.add(sp.getSquadRosterPanel(), BorderLayout.CENTER);
    		pane.add(mp.getManualRosterPanel(), BorderLayout.EAST);
    		pane.add(ab.getButtonPanel(), BorderLayout.SOUTH);
    		
    		}
    }
    And trying to have a driver class here for the main method:


    Java Code:
    /*
     * Driver Class for program
     */
    public class MainDriver {
    
    	public static void main(String[] args) {
    		
    		MainGUI mg = new MainGUI();
    
    	}
    
    }
    How can I communicate between these classes so that I do not receive this error:

    Java Code:
    Exception in thread "main" java.lang.NoSuchMethodError: main
    Thanks for any help!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Class Communication/ Main Method

    How are you trying to communicate? What are you trying to pass from one to the other?

  3. #3
    javaNewblet is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default Re: Class Communication/ Main Method

    I am trying to pass panels from 3 other classes to the MainGUI class, so I can add them to one panel, I want the MainDriver class to contain the main method.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Class Communication/ Main Method

    Quote Originally Posted by javaNewblet View Post
    I am trying to pass panels from 3 other classes to the MainGUI class, so I can add them to one panel, I want the MainDriver class to contain the main method.
    Then give the MainGui class an addPanel(JPanel p) method and in the method provide code that allows the JPanel to be placed where you want to place it.

  5. #5
    javaNewblet is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default Re: Class Communication/ Main Method

    I am not sure what the deal was, because I've never had to do it before. But I had to right click the project in the project explorer and follow a couple of screens to build a correct path(in Eclipse). In the past the path must have already been automatically correct. This solved the problem and now my class MainDriver has a functioning main method for the whole program. Thanks for all the replies and other advice you offered!

  6. #6
    javaNewblet is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default Re: Class Communication/ Main Method

    Is there a "thread solved" for this forum that I need to do? Thanks.

Similar Threads

  1. Main Method Can't Find It's Parent Class
    By Slinkie45 in forum New To Java
    Replies: 11
    Last Post: 05-09-2011, 02:37 AM
  2. access method of main class (android)
    By Stamoulohta in forum New To Java
    Replies: 8
    Last Post: 03-21-2011, 12:42 PM
  3. main method not found in class
    By eLancaster in forum New To Java
    Replies: 5
    Last Post: 02-09-2011, 08:48 AM
  4. Running main method class from another main class
    By tlrocketman in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 08:30 AM
  5. executing a method in main class
    By rangers27 in forum New To Java
    Replies: 3
    Last Post: 07-19-2008, 05:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •