CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Posts
    25

    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);
    }

    }








  2. #2
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    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..


  3. #3
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    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);
    }
    }











  4. #4
    Join Date
    Apr 1999
    Posts
    25

    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.







  5. #5
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    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
  •  





Click Here to Expand Forum to Full Width

Featured