• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Am i making use of classes in the right way?

 
Mark Toddd
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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








 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator

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

Thanks for the tips.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and I have to give you kudos for not extending JFrame when you didn't have to.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic