Jump to content

It's solved, but why did it have to be solved?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
So i created a little program to change all the pictures in a map to a resolution that the user gives in.

Background info
My father bought one of those digital photo frames from philips but when you give it photo's of a resolution to big, it shows really really bad. So i was looking on the internet to search for some software that turns all images in a certain map into a set resolution. But google'ing for photo map change resolution would only give me software to change the resolution of 1 picture a time, not a whole map.

So i figured it'd be faster to just write a program than keep on searching on the internet :cool:
---------------------------------------------------------------
---------------------------------------------------------------
I first had it working, a simple inputbox to let the user give in the path on the computer. the resolution 800x600 was build in the code. From the moment the inputbox is filled in and the user pressed ok. it starts to set the resolution of all JPG and BMP files in the map and overwrites the photos with the new version. During the process it updates a label like:
"now processing photo " + i + " from " + total

After that i wanted to let the user choose it's own resolution. quickly wrote an (ugly) GUI with 3 labels and 3 textfields to let the user fill in, X-resolution, Y-resolution, path on computer. Then the label that needs to get updated for every loop, and a button to start it all.

The weird thing is that when i press the button, it won't update the GUI anymore for every loop. It did so without the button.

I solved it with using a thread in the actionperformed. But why would that be needed as it worked without a button?

[highlight=Java]
goButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Thread(new Runnable() {
public void run() {
startInMap(pathField.getText());
}
}).start(); // start the thread
}
}
);
[/highlight]

[highlight=Java]
private void startInMap(String map) {
....
for (int i = 0; i < noDirsList.size(); i++) {
label2.setText("Foto " + (i + 1) + " van " + noDirsList.size());
....
}
[/highlight]

#2
GMVResources

GMVResources

    Learning Programmer

  • Members
  • PipPipPip
  • 72 posts
I think you solved it around the long way if you hover over the error some IDE's give you why it's like that, and then you'll know exactly what is wrong with it.

#3
smithi

smithi

    Newbie

  • Members
  • Pip
  • 9 posts
When the execution is inside an ActionPerformed method, the Gui doesn't respond.
The ActionPerformed method doesn't execute the command for update the GUI but it put the command in queue, so the command will be executed only when ActionPerformed ends.

#4
abzero

abzero

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 217 posts
Clearer answer, the actionPerformed function is run as part of the event loop thread. The gui repainting event's also run in this thread. If you did all your processing in that thread, it cannot process any events, such as mouse events, repaint events etc. You solution as you found out was to kick off the running in a seperate thread, free'ing up the GUI to paint and respond.