?
Solved

Pb trying to update graphics in a panel from an applet ?

Posted on 2003-02-26
13
Medium Priority
?
156 Views
Last Modified: 2010-03-31
I'm using a javascript code in an html page to call an applet function which should update graphics of the associated panel.

When I call ma javascript function, it seems that my applet is still using a old set of data, even I put my mouse pointer inside applet's frame (for any of these mouse events : enter event, exit event, move event). BUT when I click my mouse button, data seem to be reloaded and updated with the last modified version of data set (the 'emps' vector).

My analysis is that my panel is working with an old set of data (a "frozen" data set), even my applet has changed these data. At any mouse event, but the mouse click, nothing change. And at mouse click, data are updated !!!

My question is : may I force my panel data to be updated (it seem's that the synchronized 'update' function lock the data for a while) ? It seems that a call to 'update' in my applet,or 'repaint'  doesn't work at all.

Source code following...
0
Comment
Question by:Philippe Charles
12 Comments
 

Author Comment

by:Philippe Charles
ID: 8031717
Source code example :

import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.Font;


class Emp {
    String name;
    double x;
    double y;
    int x_actual;
    int y_actual;
}


class GraphPanel extends Panel
    implements MouseListener, MouseMotionListener {
    Graph graph;
    int nemp;
    Vector emps;
    Dimension d = null;


    Image finalscreen;
    Graphics finalgraphics;


    GraphPanel(Graph graph) {
     this.graph = graph;
     addMouseListener(this);
        addMouseMotionListener(this);

     emps = new Vector ();
    }

    void addPoint (String name, int rx, int ry) {
     emps.addElement (new Emp(name,rx,ry));
     nemp = emps.size();
    }

    public void selectPoint (int i) {
     ((Emp)emps.elementAt(i)).picked = true;
    }
   
    public void paintAllPoints(Vector emps) {
         [...]
    }
    public void update(Graphics g) {
     d = getSize();

     if ((bgscreen == null) || (d.width != bgscreensize.width) || (d.height != bgscreensize.height)) {
          //first time
          [...]
          finalscreen = createImage(d.width,d.height);
          if (finalgraphics != null) {
               finalgraphics.dispose();
          }
          finalgraphics = (Graphics)finalscreen.getGraphics();
          finalgraphics.setFont (ttipFont);
     }
     [...]
     finalgraphics.drawImage(paintAllPoints(emps),0,0,this);
     g.drawImage(finalscreen, 0, 0, this);
    }

    public void paint(Graphics g) {
        update(g);
    }

    // traitements des évènements souris
    void traitementEvents (MouseEvent e) {
     [...]
     repaint();
     e.consume();
    }
         
    //1.1 event handling
    public void mouseClicked(MouseEvent e) {
     if (e.getClickCount() == 2) {
          for (int i = nemp-1; i >= 0; i --)
               ((Emp)emps.elementAt(i)).picked = false;
     }
     else
          ((Emp)emps.elementAt(current_picked)).picked = ((Emp)emps.elementAt(current_picked)).picked?false:true;

     traitementEvents (e);
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
     pick.paint_it = true;  
     traitementEvents (e);
     e.consume();
     repaint ();
    }

    public void mouseExited(MouseEvent e) {
     pick.paint_it = false;  
     traitementEvents (e);
     e.consume();
     repaint ();
    }

    public void mouseDragged(MouseEvent e) {
    }

    public void mouseMoved(MouseEvent e) {
     traitementEvents (e);
    }
}


public class Graph extends Applet {

    GraphPanel panel;
    Panel controlPanel;

    public void init() {
     setLayout(new BorderLayout());

     panel = new GraphPanel(this);
     add("Center", panel);

     String edge = "";
     int i = 3;
     while ((edge = getParameter("p"+i)) != null) {
          [...]
          panel.addPoint(pn, pa, ps);
          i ++;
     }

     panel.transformCoord (getSize());
    }

    public void selectLine (int k) {
         panel.selectPoint (k);
     panel.repaint ();
    }

[...]
0
 
LVL 92

Expert Comment

by:objects
ID: 8031719
can u post the applet code that does the update.
0
 
LVL 92

Expert Comment

by:objects
ID: 8031722
which method is the javascript calling?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:Philippe Charles
ID: 8031982
You have the applet code at the end.
Javascript is calling "selectLine(int k)".
0
 

Author Comment

by:Philippe Charles
ID: 8034553
Actually : 'update' method is 'synchronized' and is using data of 'emps' variable.
0
 
LVL 92

Expert Comment

by:objects
ID: 8037044
looks ok.

Add some debug to ensure Graph.selectLine() and GraphPanel.update() are actually getting called.

Can you post the code for paintAllPoints().
0
 

Author Comment

by:Philippe Charles
ID: 8040516
debug : OK, I found it :
It comes from my HTML page :
#1)
If I call 'selectLine' using javascript like this :
<input type="checkbox" onChange="document.all.test.selectLine(0)">Line 0
It causes the problem I described.'update' is differed until mouse click.
#2)
If I call 'selectLine' like this :
<a href="javascript:document.all.test.selectLine(0)">select line #0</a>
It works fine. 'update' is done in realtime, not differed like in case #1.

Any explanation ????

0
 
LVL 92

Expert Comment

by:objects
ID: 8040555
What are you refering to when you keep mentioning 'update'?

Did u check what was getting called as I suggested above?
0
 

Author Comment

by:Philippe Charles
ID: 8040676
'update' is the 'update' method of my panel.

Yes, I did.
case #1) (using checkbox) I change the value of the checkbox, and... nothing! selectLine,nor selectPoint are called (or it seems that they are not called). But calls are "stored" somewhere, because after mouse click (but not move events, nor enter or exit events), my traces show me that these function are finally called (events have been differed, or something like this).

case #2) (using <a ...> tag) I click the link, and... first selectLine, then selectPoint are called in realtime, and graphic update is done!!!!????

What do U think ?
0
 

Expert Comment

by:CleanupPing
ID: 9059044
thenaz:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9671439
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Question Deleted and Points refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TimYates
EE Cleanup Volunteer
0
 

Accepted Solution

by:
Philippe Charles earned 0 total points
ID: 9671746
Please accept my comment as an answer (this is the needed explanation) :

It comes from my HTML page :
#1)
If I call 'selectLine' using javascript like this :
<input type="checkbox" onChange="document.all.test.selectLine(0)">Line 0
It causes the problem I described.'update' is differed until mouse click.
#2)
If I call 'selectLine' like this :
<a href="javascript:document.all.test.selectLine(0)">select line #0</a>
It works fine. 'update' is done in realtime, not differed like in case #1.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month4 days, 2 hours left to enroll

599 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