Solved

Graphics in separate Frames

Posted on 1998-08-25
7
210 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

679 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