Solved

Drawing images on frames

Posted on 1997-11-15
4
227 Views
Last Modified: 2010-04-16
Hi,
My program is an applet which calls a frame. This frame has a menu bar. Once a menu item is selected, another frame appears and an image should be drawn on this new frame.
The image is located on the server site.
When I use getDocumentBase() or getCodeBase() methods from the frame class body to get the URL of the image, I get an error saying that these two methods are not found in the frame class.
If I don't use them, I get security exception about the image file.
Are there any ways to draw an image on a frame?.

Any suggestions?..... I really, need help.

Regards.
0
Comment
Question by:nazar66
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
eugenem earned 70 total points
ID: 1230679
Make a member for your applet in the frame class and call these methods by this member.

class YourFrame
{
   private Applet yourApplet;

   public YourFrame( Applet applet )
   {
      yourApplet = applet;
   }

   public void smth()
   {
      applet.getDocumentBase();
      etc...
   }
}
0
 

Author Comment

by:nazar66
ID: 1230680
Thanks for the answer.
I couldn't implement what you have suggested. It will be very helpful if you can show me a very simple example of drawing an image on a frame. I couldn't find any such example anywhere.

Regards.
0
 
LVL 3

Expert Comment

by:eugenem
ID: 1230681
You cannot draw image on the frame itself. You should create Canvas component and paint your Image on it.

class YourCanvas extends Canvas
{
   Image image;

   public YourCanvas( Image image )
   {
      this.image = image;
   }

   public void paint( Graphics g )
   {
      g.drawImage( image, 0, 0, this );
   }
}
0
 
LVL 4

Expert Comment

by:rembo
ID: 1230682

Actually, you can draw directly onto the Frame.  
You were having problems with the getCodeBase() and
getDocumentBase().  When you create your frame, pass
in the applet class to the constructor.  So, instead of
new Frame() do this:

public myFrame extends Frame
{
  Applet myapplet;

  public myFrame(String name, Applet myapplet)
  {
    super(name);
    this.myapplet = myapplet;
  }

  public URL getCodeBase()
  {
    return myapplet.getCodeBase();
  }

  public URL getDocumentBase()
  {
    return myapplet.getDocumentBase();
  }
}

If you use this frame instead of the regular frame class,
you can call getCodeBase and getDocumentBase and they
will work just fine.

Hope that helps,

-Tony

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now