How to display image in an application
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sabu_vs
Posted On:   Thursday, October 25, 2001 01:34 AM

Hi



Could you pls tell me how can I display an image in my application.


My application is in d:/project and my image is in d:/project/image directory.


Could you pls tell me how can I set an onMouseOver event to my image.



Also pls tell me how can I set an icon to the title bar.

could you pls include a sample code




thanks in advance


sabu

Re: How to display image in an application

Posted By:   Sarbjot_Singh  
Posted On:   Thursday, November 8, 2001 12:52 AM

hi its Sarbjot....

abt ur I questin ..try doing this in ur application...



JLabel l=new JLabel(new ImageIcon("./project/image/ima.gif"));

getContentPane().add(l);


i used Swing 2 in the above example...



now 2nd question...man heres the code..



//MAIN METHOD OF APPLICATION

public static void main(String args[])

{

JFrame frame1=new JFrame();

frame1.show();



Image ii=Toolkit.getDefaultToolkit().getImage("image.gif");

MediaTracker track=new MediaTracker(frame1);

track.addImage(ii,0);

try{track.waitForID(0);}

catch(Exception e){System.out.println(e.getMessage());}

frame1.setIconImage(ii);

}



i used JAVA 2 and worked out this example in Windows NT 4 Enviroment


Hope u find this code working for u......gd luck...


u can mail me back at sarbjots@rediffmail.com


bye :-)SARBJOT
About | Sitemap | Contact