[英]mp3 in java eclipse
//here is a copy my code that i am trying to make play eye of the tiger, which i have saved on my desktop. //这是我尝试使自己的老虎机发挥作用的代码副本,已保存在桌面上。 first where should i save it, also how do i make it play?
首先,我应该在哪里保存它,还应该如何播放它? and also does it matter what type of file it is (i am using a mp3) any help would be appreciated.
而且它是什么类型的文件也无关紧要(我正在使用mp3),任何帮助将不胜感激。 also if you could explain the code that would help (music is also saved to eclipse < java < stopwatch < src < stopwatch )
同样,如果您可以解释会有所帮助的代码(音乐也会保存到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 ALL 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 to add an MP3 library to your program. 要使用Java播放MP3,您需要在程序中添加MP3库。 I normally use javazoom for that.
我通常为此使用javazoom。 Otherwise you could convert it to a wav file and use sound buffering.
否则,您可以将其转换为wav文件并使用声音缓冲。
http://www.javazoom.net/javalayer/javalayer.html http://www.javazoom.net/javalayer/javalayer.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.