• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pausing loop to wait for response of actionListener  RSS feed

 
Joanne Quinn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, I'm fairly new to Java and programming in general, and it often makes my head spin. I have been trying to write a program that I can use to conduct a survey. The program will play a short video clip and then the user will select the emotion that they hear/see in the clip. When the "submit" button is pressed, the clip name and emotion are then stored in a .csv file for me to examine later. I have been trying for ages to get the submit button to control the for loop so that the program waits in between each iteration; I keep seeing that the way to do this is with the actionListener, but it doesn't seem to work for me. The for loop just continues to execute, and the only video that is ever actually seen is the last one. Any help would be appreciated. Thank you.

Just to not claim that all this code is mine, I got some of it from random tutorials over the course of many weeks trying to get different parts to work.
Also, I do realize how disgusting this code is, but when I try to break it down into methods, it stops working all together...

Thanks again,
Joanne


 
Knute Snortum
Sheriff
Posts: 3556
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch! Sounds like an interesting project.

I'm going to correct you code tags (you can read about it here: UseCodeTags) and move this to the Swing forum.
 
Piet Souris
Rancher
Posts: 1783
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Joanne,

there is no need to wait for some action in the first place. Just let the actionListeners
do all th hard work,

What about a structure like this?


Currently you have all your code in the 'main' method. However, this
makes it necessary to make all the extra methods static as well, and it
is generally considered bad coding style. So, let's change that structure
a little.

First, change 'main' to the following:


That's all for the main method! It creates an instance of your
class, so that we can dispose of the word 'static'.
And secondly, it forces your code to be run on what is called
the EDT. That is important for programs using a Swing GUI.

Now, we need a constructor that actually creates an instance
of WDPlayer.

So here goes:

And in theory, that's it! No for-next loops, no complicated things,
just implement the methods 'loadVideo' and the 'saveAssessment'.

Mybe you need some code to decide what to do when a video
is finished.

I hope I made clear what structure I have in mind. Give it a
thought, and let us know what you think of it.
 
Joanne Quinn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I will give it a try! Usually when I use methods, I wind up breaking the whole thing, but your suggestions are very good, so hopefully this time will be different. I am going to try and implement the changes now (though it will most likely take me a while...) I will let you know how it works out. Thanks again!

Joanne
 
Joanne Quinn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Piet,

I was not able to get it working with separate methods like I know I was supposed to, but I was able to get it functional (but very, very ugly) by incrementing the global variable currentVideo from within the submitButton actionListener. Hopefully it will work for my experiment (and hopefully I will one day understand how to get methods to work together!!).

Thanks for your help!

Joanne
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!