• Post Reply Bookmark Topic Watch Topic
  • New Topic

Working with Swing

 
Greg Hatt
Greenhorn
Posts: 14
Java Linux Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've removed my post simply because I wouldn't want code as sloppy as that appearing next to my name if someone did a Google search on me. Essentially the question was about how to separate GUI logic from Class logic.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Swing please, not JSwing.
You don't program with Swing. What you want is a “console application” which has a public interface which you can pass messages to. You can also get the results returned from getXXX or similar methods and you can use those for your display. Don't even think of writing a GUI until you have the underlying app working. So you should have a raiseSalary() method or similar. Once you have got that working and tested, you can consider a button with an action listener like this:-You will obviously want to change that to match your description.

Don't call a Panel contentPane; that might cause confusion with the content pane of the Frame.
 
Ben Allen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was actually wondering the same thing as the OP. I have been nervous that console programs I write will be a nightmare to convert to GUI programs later on. Glad to see it won't be that bad.
 
Greg Hatt
Greenhorn
Posts: 14
Java Linux Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After talking with some fellow students we've come up with a rough rule of thumb. You should always design your programs in such a way that you could replace the GUI without fundamentally changing your classes. Your GUI classes should not be performing logical operations.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's known as the MVC (Model-View-Controller) pattern: the M (data and business logic, more or less) should be largely unaffected by whether the V is a CLI, or a desktop GUI, or a web GUI.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume CLI means command line interface?

Don't delete posts like that; it can make the replies look like nonsense.
 
Greg Hatt
Greenhorn
Posts: 14
Java Linux Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that. As soon as I did I realized that no matter how poorly written or confused my question was it still might benefit someone since you were kind enough to provide an answer.
 
Greg Hatt
Greenhorn
Posts: 14
Java Linux Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Additionally Ulf Dittmer, that's exactly what I was looking for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!