Solved

Drawing images on frames

Posted on 1997-11-15
4
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

705 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