• 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

How to refresh View in MVC architecture.

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ranchers need some help.

I am given a project in MVC with Swings.

I should develop a system's front end where the user is asked for his username and password. When he enters them correctly then he's asked a random question from a database which if he answers correctly will be logged in.

I have already done them using Swings but without MVC.( I hide the 1. Login page when the username and password and display 2. Random Question Page)

1. Login Page



2. Random Question




As I have started converting it to MVC I created a View, Controller and Model files for the login page.

I have created a second View file for the Random Question page and am planning to use the same controller and model file.( I dont know if its ok do it)

My questions are ,
a. Can I some how refresh the 1. Login Page and display 2. Random Question in the same window or do I have to use second View file?
b. How to add actionlisteners for radio buttons in MVC?
c. How to call the second view file and from where?

Code
View file:


Controller:


Model:


The program is not complete, but when I run I am displayed 1. Login page when I enter the correct username and password, it hides view1 but a NULL pointer error is shown and wont display 2. Random question view.

Any help/suggestion is welcome.
Thanks in advance!
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some suggestions, but first a warning: please note that I am not a professional and I cannot say that these suggestions are the best way or the professional way to do what you want but rather can say that it has worked well for me.

That being said, my suggestions:
  • First off, you may want to avoid having your view extend JFrame as that is not necessary and can limit what you can do with your view to a degree. Rather I would have my views subclass JPanel (or perhaps even better, not subclass anything at all, but rather be able to produce a JPanel with the appropriate behavior -- use composition rather than inheritance to build your code).
  • Next, I'd have either my main view's JPanel or a JPanel held by the main view use a CardLayout for its layout. This will allow this container to hold and display a JPanel and then swap it for other JPanels (really, it can swap any component) on your command. I'd give the main view a public method to allow the model to swap views by using public constant Strings (example below).
  • Next consider having your model's database-calling code done on a background thread such as a SwingWorker. This will help prevent your GUI from appearing locked when the slower database lookups are being done.
  • Next, consider removing @SuppressWarnings("deprecation") and along with this, avoid using deprecated methods. It is rarely necessary to use deprecated methods and almost always not desired.


  • A very short example of some stuff mentioned above. Any corrections or improvements are MUCH appreciated!


    Much luck and hope this helps!
     
    Anudeep Pat
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It helped thanks a lot
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic