my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Convert objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convert objects" Watch "Convert objects" New topic
Author

Convert objects

Emili Calonge
Ranch Hand

Joined: May 17, 2003
Posts: 84
I have 2 classes one named file and another named picture, picture extends file.

The class file, has a name and a size.
The class picture has a width and a height.

The program by default creates files, then when the user makes some actions I want the selected files to become pictures. What I want is some guidance because I don't think I'm doing it well. What I really want is that given a file, create a picture that has the files atributes.

So if a user has a file named "whatever" and its size is "50000", I want to create a picture from this file without losing the information.

What I need is something like


So that if someones asks for f.size gets 50000 and if someone asks for p.size gets 50000.

I think this is a quite basic object concept, but I'm really confused, any suggestions or explanations about this will be really helpful to me. Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38100
    
  22
Does it work? Have you tried it? If it doesn't work, what goes wrong?
Parth Bhatt
Ranch Hand

Joined: Oct 19, 2005
Posts: 58
hi !!
If I've understood your problem here's the solution.... There are 3 classes,

1. file
2. picture, which extends the file class.
3. Temp, any class that will have the statements

then if someones asks for f.size gets 50000 and if someone asks for p.size gets 50000...

Consider the code shown below

Store the file class in file.java
=================================


Store the picture class in picture.java
=======================================



Store the Temp class in Temp.java
=================================


If this is not the exact solution that you're looking for, just be a lil more clear and post over here, exactly what this solution lacks...!!
[ December 11, 2005: Message edited by: Parth Bhatt ]

If your new Big Idea doesn't scare the hell out of you, <br />it's probably not a "new Big Idea".
Emili Calonge
Ranch Hand

Joined: May 17, 2003
Posts: 84
Hi, thanks for the code, that is what I was talking about, and that's qhat I did yesterday and it works, no problem with that. What I'm concerned about is memory references, if I have a file, and I associate some things to it, like date or comments or whatever, and then I make picture of that file, will the new picture also have that date, comment, etc. ?? I need these references to be kept, now I'll try this with my program, and I'll post later what happens.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert objects
 
Similar Threads
Lazy Loading
Heelllpppp! I'm sooo lost
Mistake(I think) on K&B's 1.4 book
Multiple file Project
NX: GUI drafts (some layout probs)