• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Swing and Design Patterns

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there! I'm doing a small project for the University, where the idea is to do a game using Java Swing applying the corresponding design patterns (like facade, singleton, factory, composite, observer, proxy, template, etc.).
I've just started and have a couple of questions:
1. Regarding facade and detachement between the UI and my UsersSystem (gets in charge of validating the username/pass and has the users/admin/gamer classes).
There are two roles of users: admins and gamers. Their login screen is identical.

Package UI
Class FrameLogin
-UserRole loginUserRole //being the same login screen, I set this role when starting the Frame, so that I can pass it to the Facade

Package Facade
Class Facade
+User Login(User, UserRole)

Package UsersSystem
Class UsersSystem
+User FindUser(User, UserRole)
Enum UserRole

Is it ok for FrameLogin to have an user role just because the UI is the same for both?

2. This is my main now:



I have one package for the AdminUI, another for the GamerUI, and for now a CommonUI, where I have the login screen, since it's the same for both.
I think I should apply a factory pattern here, but I'm not sure on how to do it. I thought something like:



But I don't find it consistent. For example, in the FrameLogin, this is how I open another frame:



Any ideas? Thanks!
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

First don't think about design patterns or how patterns may apply to the project. But think of what entities/classes are needed, how are such entities interact, what purpose is the entity for etc.

About your user role thing, is there a file or database table storing user "John" is admin and "Jane" is gamer? That way the username will determine which screen to load.

Work on the design of each function/ section at a time.

During your design, you may recognize if design patterns are suitable for such and such function. At first you may not recognize it but sooner or later looking back, you in fact are using such and such pattern here and there.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic