aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Am i making use of classes in the right way? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Am i making use of classes in the right way?" Watch "Am i making use of classes in the right way?" New topic
Author

Am i making use of classes in the right way?

Mark Toddd
Greenhorn

Joined: Jan 05, 2010
Posts: 11
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










"What you talkin' bout Willis?"
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mark Toddd
Greenhorn

Joined: Jan 05, 2010
Posts: 11
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

Joined: Oct 25, 2008
Posts: 2700

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.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Mark Toddd
Greenhorn

Joined: Jan 05, 2010
Posts: 11

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

Thanks for the tips.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
... and I have to give you kudos for not extending JFrame when you didn't have to.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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. ;)


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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

Joined: Jan 05, 2010
Posts: 11
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Am i making use of classes in the right way?