|
-
October 2nd, 1999, 01:44 PM
#1
Overlapping an Image with Graphic object methods
Hi,
Is it possible to overlap an Image with methods like g.drawLine()?
I have subclassed an ImagePanel class (provided by Symantec) and implemented it's paint method to draw a line that has to overlap on top of an image.
Any suggestions in general, for overlapping an image, not necessarily using the ImagePanel,
will be great!
Thanks,
Uma.
The code for the Applet class is as follows:
import java.awt.*;
import java.applet.*;
import symantec.itools.awt.ImagePanel;
import java.net.*;
public class TestImage extends Applet
{
myImagePanel mp = new myImagePanel();
ImagePanel ip = new ImagePanel();
public void init()
{
setLayout(null);
setSize(426,266);
//Add an ImagePanel that has paint method implemented
mp.setLayout(null);
mp.setBounds(0,0,426,266);
//Add an Image
try {
ip.setImageURL( new java.net.URL(this.getDocumentBase(),"Test.jpg") );
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
try {
ip.setStyle(myImagePanel.IMAGE_CENTERED);
}
catch(java.beans.PropertyVetoException e) { }
ip.setLayout(null);
ip.setBounds(40,40,100,100);
mp.add(ip);
add(mp);
}
}
And the code for the myImagePanel Class is:
import java.awt.*;
import symantec.itools.awt.ImagePanel;
public class myImagePanel extends ImagePanel
{
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.drawLine(50, 40, 30, 20);
}
}
-
October 2nd, 1999, 04:31 PM
#2
Re: Overlapping an Image with Graphic object methods
class MyImagePanel extends ImagePanel{
public void paint( Graphics g ){
super.paint(g); // Call base class's paint() which will draw the
// Image first
g.drawLine( 0, 0 , 300 , 300 );
}
}
Poochi..
-
October 2nd, 1999, 05:17 PM
#3
Re: Overlapping an Image with Graphic object methods
Hi Uma,
I dont know why you are creating two ImagePanels ..
myImagePanel mp = new myImagePanel();
ImagePanel ip = new ImagePanel();
I modified your code .. Here it is..
import java.awt.*;
import java.applet.*;
import symantec.itools.awt.ImagePanel;
import java.net.*;
public class TestImage extends Applet{
myImagePanel mp = new myImagePanel();
// ImagePanel ip = new ImagePanel();
public void init() {
setLayout(null);
setSize(426,266);
//Add an ImagePanel that has paint method implemented
mp.setLayout(null);
mp.setBounds(0,0,426,266);
//Add an Image
try {
mp.setImageURL( new java.net.URL(this.getDocumentBase(),"Test.jpg") );
}catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
try {
mp.setStyle(myImagePanel.IMAGE_CENTERED);
}catch(java.beans.PropertyVetoException e) { }
// ip.setLayout(null);
// ip.setBounds(40,40,100,100);
// mp.add(ip);
add(mp);
}
}
And the code for the myImagePanel Class is:
import java.awt.*;import symantec.itools.awt.ImagePanel;
public class myImagePanel extends ImagePanel{
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.blue);
g.drawLine(50, 40, 30, 20);
}
}
-
October 3rd, 1999, 05:29 PM
#4
Re: Overlapping an Image with Graphic object methods
Hey,
Thanks again!
I had to add many table components within the Image Panel and was therefore using another Image Panel Component for the .jpg image.
That way, I was not getting any overlap of the tables. But I was having the problem when I was drawing a line to the component.
But I tried using one Image Panel object and using the super.paint(g) call and it worked. I could also add all the tables.
Another Vote!
Uma.
-
October 3rd, 1999, 07:41 PM
#5
Re: Overlapping an Image with Graphic object methods
Thanks for the vote :-)))))
You are welcome...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|