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
Solved

Drawing images on frames

Posted on 1997-11-15
4
233 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 29
how to add new optional parameter to JSP 1 49
oracle 11g 23 107
Adding multiple JVM environments to RedHat 6 7 48
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

828 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