Class Communication/ Main Method
Hi all,
I have a main GUI class as seen here:
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:
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:
Code:
Exception in thread "main" java.lang.NoSuchMethodError: main
Thanks for any help!
Re: Class Communication/ Main Method
How are you trying to communicate? What are you trying to pass from one to the other?
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.
Re: Class Communication/ Main Method
Quote:
Originally Posted by
javaNewblet
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.
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!
Re: Class Communication/ Main Method
Is there a "thread solved" for this forum that I need to do? Thanks.