applet not refreshing right away

hi all,

in my applet, i'm trying to display an image of an hourglass image using a canvas to hold the image. (i'm stuck with AWT and unable to use custom mouse pointers.)

however, the hourglass image does not appear immediately. there's always some delay, and by the time it's done, the processing that takes place is already done. i want the hourglass icon to appear while the processing takes place.

the pertinent methods in my applet class are :

========================

BEGIN CODE

========================

// This method gets called when someone clicks a button and initiates some // applet processing.

public void firstButton_actionPerformed(MouseEvent me) {

showHourglass();

{code doing some processing}

}

private void showHourglass() {

hourGlass.setVisible(setVisible);

hourGlass.repaint();

========================

END CODE

========================

my question is: how can i force the hourglass to appear before the processing takes place?

i need a solution that works in both the MSFT JVM and the SUN JVM.

thanks!

[1154 byte] By [speedcodera] at [2007-10-3 9:53:21]
# 1
the 10 duke dollars are for anyone who provides the solution ... even if you provide part of the solution, i'll provide some duke dollars.this problem is incredibly frustrating.
speedcodera at 2007-7-15 5:10:59 > top of Java-index,Desktop,Core GUI APIs...
# 2
I believe it's because the setVisible() and repaint() calls are held up by your {code doing some processing}. You have to put the {code doing some processing} in a separate thread.
pressburg_boya at 2007-7-15 5:10:59 > top of Java-index,Desktop,Core GUI APIs...
# 3

> I believe it's because the setVisible() and repaint()

> calls are held up by your {code doing some

> processing}.

>

> You have to put the {code doing some processing} in a

> separate thread.

thanks for the suggestion. i also agree, but i need the code to execute synchronously. in other words, i don't want the code to process independent of the panel getting displayed since the panel is supposed to show the user that some processing is taking place.

what's frustrating is that if i use a dialog instead of a canvas, the dialog gets displayed immediately whereas the canvas doesn't. i don't understand why.

any ideas?

speedcodera at 2007-7-15 5:10:59 > top of Java-index,Desktop,Core GUI APIs...
# 4
You can use the predefined wait cursor.Cursor waitCursor = new Cursor(Cursor.WAIT_CURSOR);yourApplet.setCursor(waitCursor);
CaptainMorgan08a at 2007-7-15 5:10:59 > top of Java-index,Desktop,Core GUI APIs...
# 5

> You can use the predefined wait cursor.

> > Cursor waitCursor = new Cursor(Cursor.WAIT_CURSOR);

>

> yourApplet.setCursor(waitCursor);

thanks for the suggestion. however, this doesn't seem to work because the cursor doesn't change right away and only changes if i move off a button. i need something that is clear to the user and easy to see (that doesn't require moving of the mouse).

any other ideas?

speedcodera at 2007-7-15 5:10:59 > top of Java-index,Desktop,Core GUI APIs...
# 6
Where are you setting the cursor? If you do it properly, it should change right away.
CaptainMorgan08a at 2007-7-15 5:10:59 > top of Java-index,Desktop,Core GUI APIs...
# 7

> thanks for the suggestion. i also agree, but i need

> the code to execute synchronously. in other words, i

> don't want the code to process independent of the

> panel getting displayed since the panel is supposed

> to show the user that some processing is taking

> place.

>

> what's frustrating is that if i use a dialog instead

> of a canvas, the dialog gets displayed immediately

> whereas the canvas doesn't. i don't understand why.

>

> any ideas?

I think that using a separate thread can do what you want. This is what I am thinking:

// This method gets called when someone clicks a button and initiates some

// applet processing.

public void firstButton_actionPerformed(MouseEvent me) {

new CodeProcessor(hourGlass).start();

}

...

public class CodeProcessor extends Thread {

HourGlass hourGlass;

public CodeProcessor(HourGlass hg) {

hourGlass = hg;

}

public void run() {

//showHourGlass

EventQueue.invokeLater(new Runnable() {

public void run() {

hourGlass.setVisible(true);

hourGlass.repaint();

}

});

{code doing some processing}

EventQueue.invokeLater(new Runnable() {

public void run() {

hourGlass.setVisible(false);

}

});

}

}

I am not familiar with cursors, so I cannot comment about the other solution.

pressburg_boya at 2007-7-15 5:10:59 > top of Java-index,Desktop,Core GUI APIs...
# 8
Are you having any problems? You havent shown us much code.
CaptainMorgan08a at 2007-7-15 5:10:59 > top of Java-index,Desktop,Core GUI APIs...
# 9

hi everyone,

my code is fairly straightforward for the cursor changing. here's what happens:

public void firstButton_ActionPerformed(MouseEvent ae) {

textPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

[code processing ...]

textPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

}

capt, the cursor does change immediately. the problem is, it's only apparent if the mouse is moved off the button. if the user clicks on the button, and leaves the mouse hovering over the button, the cursor never changes.

i like the separate thread idea, but my concern is that there's no guarantee that the thread will run before the [code processing ...] part begins, unless i put in some notify() calls. but that doesn't seem right. there must be something i'm doing wrong in rendering the canvas.

any other ideas?

speedcodera at 2007-7-15 5:10:59 > top of Java-index,Desktop,Core GUI APIs...
# 10
another data point: if i use a dialog instead of a canvas, the dialog appears immediately. but the drawback to the dialog is only the user can close the dialog. it doesn't appear like i can close it -- unless someone has some ideas about how to close it.
speedcodera at 2007-7-15 5:10:59 > top of Java-index,Desktop,Core GUI APIs...