• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Swing and Design Patterns  RSS feed

R. Canrol
Posts: 1
  • Mark post as helpful
  • send pies
  • 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!
K. Tsang
Posts: 3648
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!