• 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
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Am i making use of classes in the right way?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
Could you glance over my code and let me know if i'm made use of classes in the right way.
Much appreciated








 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried it? I would say not, or you would notice that it doesn't work as you expect it.

I suggest you (re?)read the Swing tutorial.
 
Mark Toddd
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Actually its works perfectly and as expected.

Could you be a little clearer as to why you think it is wrong.

Cheers
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you did a good job . I would change three things:

Put the code in rubyframe.myframe into the constructor of Rubyframe.
Put the code in main into a instance method of Mainprog and create in main an instance.
Create the actionslisteners in mainprog instead of in myframe and use them as parameters in the Rubyframe constructor.
 
Mark Toddd
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'll have to go and do some reading on constructor(s) now haha

Thanks for the tips.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and I have to give you kudos for not extending JFrame when you didn't have to.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pete stein wrote:... and I have to give you kudos for not extending JFrame when you didn't have to.



He follows advice. See here so that is good. ;)
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code confuses me in the way you have used Listeners and how you are executing listener methods in your Mainprog class. Could you explain what you think this program should do?
 
Mark Toddd
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gregg Bolinger wrote:The code confuses me in the way you have used Listeners and how you are executing listener methods in your Mainprog class. Could you explain what you think this program should do?



No worries, I'll try

Please keep in mind that i'm only learning what I can via the 'net and a couple of Java books. Not to mention that I've only been mucking about with Java for around two weeks now. Now that I have my noob justification for crappy code out of the way here goes.


Assuming each class is a blueprint of a particular (re)usable action that I would like the application to perform.

1. I created a class for my the application interface. (Rubyframe.java)
2. I created a class to hold a actionlistener for a quit JButton belonging to the interface.(Leave.java)
3. I created another class to hold a second actionlistener for a JOptionPanel popup message.(Message.java)
4. I presumed that methods for these classes should be placed in the main Java file. (Mainprog.java)

I presumed that when Mainprog.java was executed the methods contained within were made available, which when called upon called the associated class into action.


Hope that makes sense

Cheers
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic