IITDU Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

java help

2 posters

Go down

java help Empty java help

Post by BIT0122-Amit Fri Dec 18, 2009 6:04 am

anyone knows how to insert a image in a frame using co ordinates?
like setBounds is used to set co ordinates + the size of components.. any way I can do that to images?
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

java help Empty Re: java help

Post by BIT0122-Amit Fri Dec 18, 2009 4:16 pm

And I thought it was hard..
Code:

ImageIcon ima = new ImageIcon("theaddress\\oftheimage\\with\\the\\imagename\\with. extension");
JLabel label= new JLabel(ima);
getContentPane().add(label);
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

java help Empty Re: java help

Post by BIT0112-Rokon Fri Dec 18, 2009 6:42 pm

I have never worked with image in Java, if I would certainly help you.. search Google, you will find tons of example there...   I just suggest you, use a JPanel, insert picture in JPanel, then, create instance in Frame, and then use setBounds  like-
instanceOfJpanel.setBounds(arg0, arg1, arg2, arg3);
and it will be the best, if you use it in the constructor of the Frame. and how to insert image in JPanel is like -
class importImage extend JPanel{
public Image image;

public importImage(){
setLayout(null);
try {
  image=ImageIO.read(new File("Image/stone1.jpg"));
   
} catch (IOException e) {
   
e.printStackTrace();
  }
image.setBounds(arg0, arg1, arg2, arg3);//here you'll set the image in the panel
add(image);}}

I'm afraid how it will work, you can try with this... but always remember, you've to initialize Layout,
I mean setLayout(null);


ok best of luck.. 
BIT0112-Rokon
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

java help Empty Re: java help

Post by BIT0122-Amit Fri Dec 18, 2009 9:31 pm

yeah, I thought about using JPanel. But was not sure whether the image becomes re sizable within the panel.
But main problem is :p I didn't use any panel previously, so was confused.

One problem with using images directly withing frame by creating labels is that you can't resize the image. (At least I didn't find any way to resize it.)

However, resize is an important issue here, and I will have to keep that JPanel advice in mind.

thanks a lot Rokon Smile
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

java help Empty Re: java help

Post by BIT0112-Rokon Fri Dec 18, 2009 10:53 pm

I don't know what u r actually going to do..? so I thought, you just wanted to know how can you use image in a Frame? anyway, If you would mention here, what you want to do actually, then I could try. Anyway, I couldn't understand your re-sizable issue. If it is possible, can you please explain what you are going to do..?  


Anyway, it is not good practice to do anything in Frame I think. Frame is simply a container where you can import lots of Panel, label whatever you want. I can use panel, so if you need any help about JPanel, you can ask me. 


Anyway, you can ask me anything about Java, whatever I can help you or not, at least I'll try to solve the problem.  OK best of luck. 
 


Last edited by bit0112-rokon on Mon Aug 02, 2010 7:14 am; edited 1 time in total
BIT0112-Rokon
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

java help Empty Re: java help

Post by BIT0122-Amit Fri Dec 18, 2009 11:11 pm

Hmm.. resize.. for example, say I want to use an image which's resolution is 300*400;
but I want to use it as a thumbnail, of size.. say 72*72. You see, I do not want to modify the picture, nor do I want to make a copy (at least in physical drive )of it and then use it, I simply want to use that image, resized (i.e. in my desired resolution).
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

java help Empty Re: java help

Post by BIT0112-Rokon Fri Dec 18, 2009 11:46 pm

I dont have much idea about image issue, but I'll try. May be you'll get the solution after the math exam. 
I've a question, why you are going to use image?will it be a background of your Frame..?or just as a Icon?Ok best of luck..? 
BIT0112-Rokon
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

java help Empty Re: java help

Post by BIT0122-Amit Sat Dec 19, 2009 12:10 am

no it will not be background.
I think the idea I am going to use is also required in your project. Know why?

How about inserting a picture of the user in your income tax calculator?
like in facebook.. no matter whatever the image's resolution we upload, it always resizes it to a specific resolution for profile picture.
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

java help Empty Re: java help

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum