?
Solved

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

Posted on 2003-02-26
13
Medium Priority
?
155 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
[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
13 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
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: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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

777 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