Solved

Graphics in separate Frames

Posted on 1998-08-25
7
209 Views
Last Modified: 2010-03-30
Hi

I've created a Java Applet with VJ++ 1.1 and all works fine. It's an little
application with database connection and I made a form in a separate frame.
I can add Graphics (lines, rectangles ...) in the main Applet but I can't
add it to my separate frame.

I think it must be possible to do it ... but how?

Thanx for your help. Regards,

    Joel
0
Comment
Question by:gautschi
  • 4
  • 3
7 Comments
 
LVL 8

Accepted Solution

by:
diakov earned 150 total points
ID: 1222549
- May be you should reconsider your vision of the whole picture. Actually the applet is an object, embeded in the main HTML body.
- Let's have a look again in the HTML content of the page.
There you have <FRAMESET> tag that defines several frames and links each of them to another HTML which will appear in the frame. Apparently, your applet object is embedded in the body of one of this HTMLs. This means it is in a frame. Unfortunatelly, the applet cannot access area outside its own, which usually is a part of the frame with dimensions you specified in the Applet tag of the HTML (or the MSJ did for you).
- What you can do from your applet is to call JavaScript statements and this way alter the content of the other frames which usually resembles to changes in the html link of the frames. Btw, Javascript is scripting language which is enclosed in <SCRIPT> tag of the HTML.

For javascript, there is a guide on the web:
http://home.netscape.com/eng/mozilla/3.0/handbook/javascript/index.html
This is netscape site, so nay be some incompliances with MSIE could occur while using the javascript knowledge there.

0
 

Author Comment

by:gautschi
ID: 1222550
>This means it is in a frame. Unfortunatelly, the applet cannot
> access area outside its own, which usually is a part of the frame with dimensions you > specified in the Applet tag of the HTML (or the MSJ did for
> you).
perhaps you don't understand what i mean.
I open (in _java_) another frame (browser starts a new applet window). I guess it should be possible to paint in this new opened frame because I opened it with java -> java is allowed to paint in selfopened frames (because I _can_ put choises, checkboxes, labels etc. in this frame with java). perhaps I'm wrong but then you have to tell me why I can to everything else... but not painting?
if you want I can send you some source.
0
 
LVL 8

Expert Comment

by:diakov
ID: 1222551
Aahhh, yes. I'm sorry. I misunderstand you.
- In general, what you have to do is to derive your own CustomFrame class from the original Frame class, override its paint() or update() mehtod and then you'll be able to draw.
- In case of MSJ (I do not use it) I believe you can do this ovveride authomatically, but catching the paint event from the properties window. Then MSJ will generate the source of your custom frame class authomatically. Or, just open the source and override the paint() or update() method.

Something like:

public void paint(Graphics g)
{
  g.draw(...);
}
0
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.

 

Author Comment

by:gautschi
ID: 1222552
can you give me a little example?
(open a new frame and draw sth in it)
then your answer would be excellent!
i would increase the points to 150 of course too.
thanks a lot!
0
 
LVL 8

Expert Comment

by:diakov
ID: 1222553
Hi 'gautschi',

---------
The html:
---------
<HTML>
<BODY>
<APPLET code="FrameOpenerAndDrawer.class" width=20 height=20 >
</APPLET>
</BODY>
</HTML>

--------------
the java files
--------------
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class FrameOpenerAndDrawer extends Applet
{
      
      CustomFrame cf;

      public void init()
      {

      }
      public void start()
      {
            cf = new CustomFrame();
            cf.pack();

            cf.resize(100, 100);  //deprecated but works with JDK 1.0
            cf.repaint(); //has to be called after sizing

            cf.show();
      }
      public void stop()
      {
            cf.hide();
            cf.dispose();
      }

}
class CustomFrame extends Frame
{
      CustomFrame()
      {
            super("Draw experiment");
      }
      public void paint(Graphics g)
      {
            g.setColor(Color.black);
            g.drawLine(1, 1, 100, 100);
      }
      public boolean handleEvent(Event e)
      {
            if (e.id == Event.WINDOW_DESTROY)
            {
                  hide();
                  dispose();
                  return true;
            }
            return true;
      }
}

-----------------------------------------------------
The source given above is JDK 1.0 compliant. It also works on 1.1 but does not use the 1.1 EventListeners and uses one deprecated method - resize(.,.)


Instructuins: Compile the java file, and then open the html file in a browser or the appletviewer.

Regards,
  Nikolay

----------------------------
e-mail: diakov@theoffice.net

0
 
LVL 8

Expert Comment

by:diakov
ID: 1222554
A, forgot to say,
the .java file must be the same name as the class - FrameOpenerAndDrawer.java

Success.
0
 

Author Comment

by:gautschi
ID: 1222555
Adjusted points to 150
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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.

837 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