Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Graphics in separate Frames

Posted on 1998-08-25
7
Medium Priority
?
214 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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:
This video teaches viewers about errors in exception handling.
Suggested Courses

609 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