Solved

Graphics in separate Frames

Posted on 1998-08-25
7
204 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
Comment Utility
- 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
Comment Utility
>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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:gautschi
Comment Utility
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
Comment Utility
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
Comment Utility
A, forgot to say,
the .java file must be the same name as the class - FrameOpenerAndDrawer.java

Success.
0
 

Author Comment

by:gautschi
Comment Utility
Adjusted points to 150
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now