mp3 in java eclipse -


//here copy code trying make play eye of tiger, have saved on desktop. first should save it, how make play? , matter type of file (i using mp3) appreciated. if explain code (music saved eclipse < java < stopwatch < src < stopwatch )

package stopwatch;    import java.awt.container;  import java.awt.gridbagconstraints;  import java.awt.gridbaglayout;  import java.awt.event.actionevent;  import java.awt.event.actionlistener;  import java.util.date;  import javax.swing.jbutton;  import javax.swing.jframe;  import javax.swing.jlabel; import javax.swing.jtextfield; import javax.swing.uimanager; import javax.swing.plaf.coloruiresource;  import org.omg.corba.portable.inputstream;   public class stopwatch    extends jframe  { /**      *       */     private static final long serialversionuid = -7203812812064067525l;    long starttime;    long stoptime;    long currenttime;    double elapsedtime;    boolean timestarted = false;    int laptime;     jbutton startbutton = new jbutton();    jlabel startlabel = new jlabel();    jtextfield starttextfield = new jtextfield();     jbutton lapbutton = new jbutton();    jlabel laplabel = new jlabel();    jtextfield laptextfield = new jtextfield();     jbutton stopbutton = new jbutton();    jlabel stoplabel = new jlabel();    jtextfield stoptextfield = new jtextfield();     jbutton exitbutton = new jbutton();    jlabel elapsedlabel = new jlabel();    jtextfield elapsedtextfield = new jtextfield();     public stopwatch(string title)    {              settitle(title);      setdefaultcloseoperation(3);        getcontentpane().setlayout(new gridbaglayout());      gridbagconstraints gridconstraints = new gridbagconstraints();        this.startbutton.settext("start timing");      gridconstraints.gridx = 0;      gridconstraints.gridy = 0;      getcontentpane().add(this.startbutton, gridconstraints);        this.startbutton.addactionlistener(new actionlistener()      {        public void actionperformed(actionevent e)        {          stopwatch.this.startbuttonactionperformed(e);        }      });      this.startlabel.settext("  start system time  ");      gridconstraints.gridx = 1;      gridconstraints.gridy = 0;      getcontentpane().add(this.startlabel, gridconstraints);       this.starttextfield.settext("");      this.starttextfield.setcolumns(20);      gridconstraints.gridx = 2;      gridconstraints.gridy = 0;      getcontentpane().add(this.starttextfield, gridconstraints);       this.lapbutton.settext("lap");      gridconstraints.gridx = 0;      gridconstraints.gridy = 1;      getcontentpane().add(this.lapbutton, gridconstraints);       this.lapbutton.addactionlistener(new actionlistener()      {        public void actionperformed(actionevent e)        {          stopwatch.this.lapbuttonactionperformed(e);        }      });      this.laplabel.settext("  lap system time  ");      gridconstraints.gridx = 1;      gridconstraints.gridy = 1;      getcontentpane().add(this.laplabel, gridconstraints);        this.laptextfield.settext("");      this.laptextfield.setcolumns(20);      gridconstraints.gridx = 2;      gridconstraints.gridy = 1;      getcontentpane().add(this.laptextfield, gridconstraints);         this.stopbutton.settext("stop timing");      gridconstraints.gridx = 0;      gridconstraints.gridy = 2;      getcontentpane().add(this.stopbutton, gridconstraints);       this.stopbutton.addactionlistener(new actionlistener()      {        public void actionperformed(actionevent e)        {          stopwatch.this.stopbuttonactionperformed(e);        }      });      this.stoplabel.settext("  stop system time  ");      gridconstraints.gridx = 1;      gridconstraints.gridy = 2;      getcontentpane().add(this.stoplabel, gridconstraints);       this.stoptextfield.settext("");      this.stoptextfield.setcolumns(20);      gridconstraints.gridx = 2;      gridconstraints.gridy = 2;      getcontentpane().add(this.stoptextfield, gridconstraints);         this.exitbutton.settext("close watches");      gridconstraints.gridx = 0;      gridconstraints.gridy = 3;      getcontentpane().add(this.exitbutton, gridconstraints);       this.exitbutton.addactionlistener(new actionlistener()      {        public void actionperformed(actionevent e)        {          stopwatch.this.exitbuttonactionperformed(e);        }      });         this.elapsedlabel.settext("  elapsed time seconds  ");      gridconstraints.gridx = 1;      gridconstraints.gridy = 3;      getcontentpane().add(this.elapsedlabel, gridconstraints);       this.elapsedtextfield.settext("");      this.elapsedtextfield.setcolumns(20);      gridconstraints.gridx = 2;      gridconstraints.gridy = 3;      getcontentpane().add(this.elapsedtextfield, gridconstraints);         setlocationrelativeto(null);       pack();    }     private void startbuttonactionperformed(actionevent e)    {      this.starttime = system.currenttimemillis();        date startdate = new date();      this.starttextfield.settext(startdate.tostring());       this.stoptextfield.settext("");      this.elapsedtextfield.settext("");      this.timestarted = true;      this.laptextfield.settext("");    }     private void lapbuttonactionperformed(actionevent e)    {          if (this.timestarted)          {            this.currenttime = system.currenttimemillis();              this.elapsedtime = ((this.currenttime - this.starttime) / 1000.0d);            this.laptextfield.settext(string.valueof(this.elapsedtime));           }          else {}        }     private void stopbuttonactionperformed(actionevent e)    {      if (this.timestarted)      {        this.stoptime = system.currenttimemillis();        date stopdate = new date();        this.stoptextfield.settext(stopdate.tostring());         this.elapsedtime = ((this.stoptime - this.starttime) / 1000.0d);        this.elapsedtextfield.settext(string.valueof(this.elapsedtime));         timestarted=(false);      }      else {}    }     private void exitbuttonactionperformed(actionevent e)    {      system.exit(0);    }  } 

to play mp3's in java you'd need add mp3 library program. use javazoom that. otherwise convert wav file , use sound buffering.

http://www.javazoom.net/javalayer/javalayer.html


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -