• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using swing(GUI) in oop

 
F Merchant
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on creating a loan calculator in Java and using Swing.
I have previously used Java swing to create GUI. And my general approach has been to use one JFrame per screen and perform all functionalities in that class itself.
But this time I want to use oop and separate the GUI classes from the main class.(unlike previously where everything is jumbled into one class)
But I'm confused on how to proceed. Like what will be my main class.....the main menu UI or another class?
The project wil have three screens:ask user for input,display a table with the monthly installments and remaining balance, and a graph of months vs payment.

If someone could please give me an overview on how to proceed, it would be great!
Thanks!!
 
F Merchant
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I've come up with so far.
Main class
main()
{
initialise main menu screen
}

Calculate
calcMonthlyPayment()
calcNoOfPayments()
calcTotalPayment()

CalcTable
calcPayment()

CalcGraph
calcMPayment()

MainMenuScreen
Table button clicked-->TableScreen
Graph button clicked-->GraphScreen

TableScreen
Take inputs from MainMenuScreen
Send to CalcTable.calcPayment()
Get values
Create JTable

GraphScreen
Take inputs from MainMenuScreen
Send to CalcGraph.calcMPayment()
Get values
Draw Graph


I've tried to separate the GUI from the calculations and conform to OOP principles.
Please let me know if I'm on the right track.
Thanks!
 
K. Tsang
Bartender
Posts: 3521
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact you can split the classes or should I say redesign/refactor your classes by a) functions or use cases, b) component or layout (tables, panels, menubar, action etc)

From the look of your app, using a component-design is probably better. One down-side I can think of is your main window/frame will still need those necessary components such that if needed different panels can interact with. Eg if a graph gets updated when the table data is selected ... then you need the table's selected data or the table itself in your graph class.

This approach may make the number of classes in your app grow depending on how small a component each class is.
 
F Merchant
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm...but for right now I'll just try and build a basic system and keep the communication between screens to a minimum.
Main Menu Screen asks user for Principal,rate and term.
It has two buttons:chart and graph.
On clicking chart button, a table is generated(Payment No, Monthly interest, Monthly payment, Remaining balance)
On clicking graph button, a graph of months vs amount is displayed.

Let me work on this, then I'll try and expand the scope of the project.
One more question....I have to validate the values entered by the user, so will Validation be a separate class?

Thanks!
 
Steve Myers
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
F Merchant wrote:Hmmm...but for right now I'll just try and build a basic system and keep the communication between screens to a minimum.

Let me work on this, then I'll try and expand the scope of the project.
One more question....I have to validate the values entered by the user, so will Validation be a separate class?

Thanks!


You can validate the input in the listeners for the components, as nested classes or anonymous classes in the class where you're drawing the parent container
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic