dcsimg
having problems showing an image on a panel with canvas in awt
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Prasad_Thorat
Posted On:   Thursday, April 26, 2001 05:40 AM

i am using a frame for my application , which consists of a panel which is added to the frame. i want to display a image on the panel , so i used canvas and graphics paint method. i.e Frame.add(panel), panel.add(canvas) . when i run my class i get the canvas and panel properly but i dont see the image in the canvas, but when i try and resize it , maximize or minimise it the image appears . So can u please tell me how can i rectify the above problem , cause i am in no condition to maximize and minimize when i integrate it with other screens (resizable off), i tried validate and invalidate but still the problem persists. !!

Re: having problems showing an image on a panel with canvas in awt

Posted By:   rameswar_setigam  
Posted On:   Thursday, April 26, 2001 01:31 PM

Hi

write a class called MainPanel which extends JPanel

like:

class MainPanel extends JPanel{

MainPanel()
{
image= Toolkit.getDefaultToolkit().getImage("/images/Frame_Reports_ba
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image,0);
try{
tracker.waitForID(0);}
catch(InterruptedException e){}
}
public void paintComponent(Graphics g){
super.paintComponent(g);
Dimension size=getSize();
g.drawImage(image, 0, 0, size.width, size.height, this);
}
}

write a main class which extends JFarme

and add MainPanel on to it...

write public void updateComponent(Graphics g)

whenever you make operations on a frame

just call repaint() method..

I hope this will solve your problem..

bye

rameswar
About | Sitemap | Contact