File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convert objects" Watch "Convert objects" New topic

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

Joined: Oct 13, 2005
Posts: 46349
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

Store the picture class in

Store the Temp class in

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:
subject: Convert objects
It's not a secret anymore!