?
Solved

Drawing images on frames

Posted on 1997-11-15
4
Medium Priority
?
244 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 140 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 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