This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Communication between jFrames  RSS feed

 
jim dimitriou
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a small program in Java to simulate a shopping cart. A shopping cart has an array og objects Item.
As a console application, my program runs.
But, in the GUI version, I have some issues.
In class MainMenu I create a ShoppingCart object, named "cart"(line 103)
In class AddItemMenu I create an Item object, and I want to add it in my ShoppingCart object "cart".
BUT, AddItemMenu cannot "see" variable "cart".
How can I solve this problem?

 
K. Tsang
Bartender
Posts: 3620
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First why is there a main method in both MainMenu and AddItemMenu? There should only be one entry point.

From the look of your code, your AddItemMenu class shows the form for users to "add items", right?

Another question to ponder is which comes first, the shopping cart or item? Shopping cart can have many items so where should the shopping cart instance be created? Also shopping cart belong to the user/member. How do you plan to implement this in GUI? Because if it were web, shopping cart in session will solve this.

Some kind of tracking mechanism is needed.
 
jim dimitriou
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:First why is there a main method in both MainMenu and AddItemMenu? There should only be one entry point.

From the look of your code, your AddItemMenu class shows the form for users to "add items", right?

Another question to ponder is which comes first, the shopping cart or item? Shopping cart can have many items so where should the shopping cart instance be created? Also shopping cart belong to the user/member. How do you plan to implement this in GUI? Because if it were web, shopping cart in session will solve this.

Some kind of tracking mechanism is needed.

thanks for the answer...
of course, the user creates the shopping cart and the items.
If we have one entry point, what changes should I do to my code?
I would be grateful, If you could fix my code...

Jim
 
Campbell Ritchie
Sheriff
Posts: 53721
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually you can have multiple main methods. Some people do that so as to test each class in development. The way to get to the correct starting point is to instruct users to start it with java MyClassWithMainMethod. You can also do that by specifying it in an executable .jar file.
Why are you trying to communicate between frames? You should have one frame per application and use different components for everything else. If you want separate windows to appear, you are probably better using dialog windows for them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!