• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Good tutorial for oop in Swing

 
Greenhorn
Posts: 4
Mac Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ladies and gent,

I've been trying for a while to use swing (not a huge fan though, why does it have to be so complicated...)
After having lost a few hair on the esthetic of my gui, i am now trying to use oop for taking care of events (all of this in a MVC app of course)
I still don't understand how to update a view when the user makes an insertion in the db (sqlite with jdbc here) but that's another topic.
For now, (i hope i'm quite clear) i want to be able to encapsulate event functions in other words i wan't to avoid things like that:

I'd rather have a function that could for example take a JButton or in my case a JComboBox and a JLabel as a parameter and get selected item from this combo and use it to put the result of the db request from the selected item of the comboBox into the JLabel. (still here?)
Also i'm still not sure i really get how to use action listener and stuff (i mean how to filter events to know which event has been done and when...)


I tried something in a separate class:


I also tried soemthing like this (which is not working)


In brief what i'm asking here is:
- good tutos that uses swing with oop and/or mvc
- if you have any ideas about my specific problem here (or references that could help)
- is the pattern observer and observable useful for my (nut)case (and easy too) ?
- anything...

Thank you for reading my post and thank you advance for your answers.
If you need anything to better understand my such as the source code or something let me know i could add some copy paste or stuff
 
Marshal
Posts: 5362
325
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Gabrielle, welcome to the Ranch!

Are you learning Swing because you have to? For a job, or to support a Swing application?

If you are learning because you want to learn how to create GUI's in Java, then I would recommend you learn JavaFX instead of Swing. Swing is quite old now, and JavaFX is the newer technology to replace it. JavaFX is part of the core JDK now so you don't need anything else to get started.
 
Gabrielle Gabriel
Greenhorn
Posts: 4
Mac Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Tim!

Well it's part of a training for my job.
Is javaFx easier than swing? it could be good to know for another project. So thanks for the tip^^
I still wish to finish this project with swing because i got really far with swing and used lots of time on it.
 
Tim Cooke
Marshal
Posts: 5362
325
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately (for you, not me) I haven't done any Swing development since way back in 2007 so am not going to be much help to you. I just wanted to let you know about JavaFX.
 
Gabrielle Gabriel
Greenhorn
Posts: 4
Mac Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lol ok thank you anyway for your answer and tip^^
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic