?
Solved

Graphics in separate Frames

Posted on 1998-08-25
7
Medium Priority
?
213 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
[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
  • 4
  • 3
7 Comments
 
LVL 8

Accepted Solution

by:
diakov earned 600 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
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

 

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses
Course of the Month11 days, 5 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