I have had problems in the past related to getting a MovieController to
display consistently in certain situations. I wanted to use
MovieController because I wanted the QT-standard widget, to confuse
newbie users of my software as little as possible.
After much trying and many suggestions from the helpful, I gave up.
Perhaps I could make it work if I tried just the right AWT voodoo
(other people seem to have no trouble, albeit not in as tight a
situation as I face); perhaps not. Either way, the problem became a
concord fallacy and I decided to cut my losses.
My workaround is to not use MovieController, which is an AWT widget;
instead I wrote my own widget using regular Swing widgets. This works
perfectly. I give my code here in case it might help someone someday
searching the archives. Code notes follow.
private class EnhancedMovieController extends JPanel {
private final Thread movieWatcher;
private boolean keepWatchingMovie = true;
private int watchHowOften = 100;
private final Movie movie;
private final JProgressBar mProgress = new JProgressBar(
0, 100 );
private final LabelButton bReset = new LabelButton(
"<<" );
private final LabelButton bPlay = new LabelButton(
">" );
public EnhancedMovieController( Movie m ) {
this.movie = m;
// set up the progress bar
this.mProgress.setBorder(
BorderFactory.createEtchedBorder() );
try {
this.mProgress.setMaximum( movie.getDuration() );
} catch( QTException qte ) {}
// set up the listeners which map mouse input on the
progress bar
// to changes in movie play
MouseInputAdapter lineProc = new MouseInputAdapter() {
private float savedRate = 0.0f;
public void mousePressed( MouseEvent e ) {
try {
this.savedRate = movie.getRate();
movie.stop();
public void mouseDragged( MouseEvent e ) {
// i can't fucking believe how stupidly hard it is
to do arithmatic in java
// i mean seriously this should be trivial
// totally fucking unbelievable
try {
double clickPlace = e.getX();
double barWidth = mProgress.getSize().width;
double widthRatio = clickPlace / barWidth;
int movieDur = movie.getDuration();
double durClickResult = widthRatio * movieDur;
int resultAsInt = (int) durClickResult;
This could be improved to provide volume control.
EnhancedMovieController does not display the actual movie, it only
controls the movie. You must lay out the movie in a MoviePlayer
somewhere. Note that a LabelButton is another custom class which is
simply a Label which behaves like a button. Here, I'll give that code
too.
/**
* This is a cheater button. It's just a label with clickability. We
use this
* because Aqua buttons are ugly when lots are grouped close together.
*/
public class LabelButton
extends JLabel
implements MouseListener {
// ---- v a r i a b l e d e c l a r a t i o n s
---------------------- //
private EventListenerList actionListeners = new EventListenerList();
// ---- p u b l i c a p i
-------------------------------------------- //
/**
* Returns a LabelButton which displays s.
*/
public LabelButton( String s ) {
super( s );
this.setBorder( BorderFactory.createEtchedBorder() );
this.addMouseListener( this );
}
/**
* Returns a LabelButton which displays s.
*/
public LabelButton( char c ) {
this( String.valueOf(c) );
}
/**
* Returns a LabelButton which displays i.
*/
public LabelButton( Icon i ) {
super( i );
this.setBorder( BorderFactory.createEtchedBorder() );
this.addMouseListener( this );
}