Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Good tutorial for oop in Swing  RSS feed

 
Gabrielle Gabriel
Greenhorn
Posts: 4
Linux Mac Windows
  • Mark post as helpful
  • send pies
  • 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
 
Tim Cooke
Marshal
Posts: 3636
184
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Linux Mac Windows
  • Mark post as helpful
  • send pies
  • 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: 3636
184
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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
Linux Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lol ok thank you anyway for your answer and tip^^
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!