Results 1 to 2 of 2
- 12-07-2008, 05:35 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 3
- Rep Power
- 0
Cannot Implement Stop And Pause...multiple Actionlisteners..please Help.
hi
I have a problem in the GUI where im not able to implement stop and pause buttons while "play" is pressed where "play" can perform: audio and video playback. While its playing the button stays pressed and its not registering actions with other buttons..(i only need pause and stop to work while there are other buttons in the GUI)...
code snippet: the action performed function...sorry its big..
play basically plays the showimage(i) which plays video frame by frame..where i is the ith frame...
public void actionPerformed(ActionEvent event)
{
if (event.getSource()== button2)
{if (com1==0&&com2==1)
{//scalling the video
JTextField input1 = new JTextField();
JTextField input2 = new JTextField();
int num = fps.getValue();
Object[] msg = {"Input X:", input1, "Input Y:", input2};
JOptionPane op = new JOptionPane(
msg,
JOptionPane.QUESTION_MESSAGE,
JOptionPane.OK_CANCEL_OPTION,
null,
null);
JDialog dialog = op.createDialog(this, "Enter Resize Values");
dialog.setVisible(true);
int result = JOptionPane.OK_OPTION;
try
{
result = ((Integer)op.getValue()).intValue();
}
catch(Exception uninitializedValue)
{}
if(result == JOptionPane.OK_OPTION)
{
rv1 = Integer.parseInt( input1.getText());
rv2 = Integer.parseInt( input2.getText());
panel.setresizev(rv1,rv2);
System.out.println("input video x : " + rv1);
System.out.println("input video y : " + rv2);
}
else
{
System.out.println("Canceled");
}
panel.showImage(num);a1.updateUI();
}
}
if (event.getSource()== button2)
{if (com1==2&&com2==1)
{//scalling the image
JTextField input1 = new JTextField();
JTextField input2 = new JTextField();
Object[] msg = {"Input X:", input1, "Input Y:", input2};
JOptionPane op = new JOptionPane(
msg,
JOptionPane.QUESTION_MESSAGE,
JOptionPane.OK_CANCEL_OPTION,
null,
null);
JDialog dialog = op.createDialog(this, "Enter Resize Values");
dialog.setVisible(true);
int result = JOptionPane.OK_OPTION;
try
{
result = ((Integer)op.getValue()).intValue();
}
catch(Exception uninitializedValue)
{}
if(result == JOptionPane.OK_OPTION)
{
ri1 = Integer.parseInt( input1.getText());
ri2 = Integer.parseInt( input2.getText());
panel.setresizei(ri1,ri2);
System.out.println("input image x : " + ri1);
System.out.println("input image y : " + ri2);
}
else
{
System.out.println("Canceled");
}
n1.setSize(ri1,ri2);
a1.updateUI();
}
}
if (event.getSource()== button1)
{if (com1==0)
{
fc = new JFileChooser();
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
filev = fc.getSelectedFile();
panel.setfilev(filev);panel.showImage(0);a1.update UI();
}
}
if (com1==1)
{
fc = new JFileChooser();
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
filea = fc.getSelectedFile();
//panel.setfilea(file1);
}
}
if (com1 ==2)
{
fc = new JFileChooser();
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
filei = fc.getSelectedFile();
panel.setfilei(filei);
//panel.simage();
n1=panel.simage();
n1.addMouseMotionListener(new MouseMotionHandler());
a1.add(n1); n1.setSize(240,180);
n1.setVisible(true);a1.updateUI();
}
}}
if (event.getSource()== button2)
{
if (com2==1)
{
}
}
if (event.getSource()== button4)
{
}
if (event.getSource()== publish)
{
publish.setText("Published");}
if (event.getSource()== play)
{
play.setEnabled(false);
int num = fps.getValue();
if(filei!=null)
{
n1.setVisible(false);
}
if(filea!=null)
{PCMFilePlayerLeveler pcm1;
try {
pcm1 = new PCMFilePlayerLeveler(filea);
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}}
try{
for(int i=num;i<192;i++)
{
if(filev!=null)
{
panel.showImage(i);}
if(filei!=null)
{
if(i>10 && i<40 )
{
n1.setVisible(true);
a1.updateUI();
System.out.println(" value of i = "+i);
}
else{
n1.setVisible(false);a1.updateUI();
}}
}
}catch(Exception e){System.out.println(e);}
}
if (event.getSource()== pause)
{
play.setEnabled(false);
System.out.println("clicked pause");
}
if (event.getSource()== stop)
{
try{
play.setEnabled(false);
}
catch(Exception e){System.out.println("ERROR - SOUND FILE IS NOT SET - PLEASE SET SOUND FILE");}
}
}
-
Your problem is that you're tying up the EDT (Event Dispatch Thread), the Swing application's main thread that is involved with drawing the application and interacting with the user. This happens when you call a method that is very time or CPU intensive on the EDT. The solution is to call these methods on a different background thread.
Have a look here for more details on this and for a solution, the SwingWorker: Concurrency in Swing
Similar Threads
-
pause until JFrame is closed.
By Tamu in forum Advanced JavaReplies: 8Last Post: 11-30-2008, 09:46 PM -
how to stop a thread
By willemjav in forum Advanced JavaReplies: 19Last Post: 09-10-2008, 07:11 AM -
how to pause and repaint in a loop, to draw a mathematical function.
By Abdelhamidem in forum AWT / SwingReplies: 3Last Post: 06-05-2008, 11:10 PM -
How to implement multiple peers downloads
By breznev in forum Advanced JavaReplies: 2Last Post: 03-12-2008, 09:03 PM -
Help with Pause
By trill in forum Java AppletsReplies: 2Last Post: 09-28-2007, 08:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks