Revision: 1775
Updated Code
at November 10, 2006 00:05 by whitetiger
Updated Code
package Multimedia; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.plaf.metal.MetalLookAndFeel; public class AudioSystem { public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel(new MetalLookAndFeel()); } catch(UnsupportedLookAndFeelException e) { e.printStackTrace(); } new AudioGUI(); } } package Multimedia; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.File; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JPanel; public class AudioGUI extends JFrame implements WindowListener { public AudioGUI() { this.setTitle("AudioSystem"); this.setSize(240, 100); this.setResizable(false); this.addWindowListener(this); Container gc = this.getContentPane(); gc.add(new AudioGUIPan()); this.setVisible(true); } public void windowOpened(WindowEvent e) { } public void windowClosing(WindowEvent e) { System.exit(0); } public void windowClosed(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } } class AudioGUIPan extends JPanel implements ActionListener { private JButton play; private JButton stop; private JButton loop; private JButton open; private JButton close; private JFileChooser jfc; private String file; private AudioDevice ad; public AudioGUIPan() { play = new JButton("Play"); play.addActionListener(this); stop = new JButton("Stop"); stop.addActionListener(this); open = new JButton("Open"); open.addActionListener(this); close = new JButton("Close"); close.addActionListener(this); this.add(stop); this.add(play); this.add(open); this.add(close); } public void actionPerformed(ActionEvent e) { if(e.getSource() == close) { System.exit(0); } else if(e.getSource() == open) { jfc = new JFileChooser(); jfc.setFileFilter(new AudioFilter()); if(jfc.showOpenDialog(this) != JFileChooser.CANCEL_OPTION) { file = jfc.getSelectedFile().getAbsolutePath(); ad = new AudioDevice(new File(file)); } } else if(e.getSource() == play) { if(ad != null) ad.play(); } else if(e.getSource() == stop) { if(ad != null) ad.stop(); } } } package Multimedia; import java.io.File; import javax.swing.filechooser.FileFilter; public class AudioFilter extends FileFilter { public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".wav") || f.isDirectory(); } public String getDescription() { return "Audio File *.wav"; } } package Multimedia; import java.applet.Applet; import java.applet.AudioClip; import java.io.File; import java.net.MalformedURLException; public class AudioDevice implements AudioClip { private AudioClip ac; public AudioDevice(File f) { try { ac = Applet.newAudioClip(f.toURL()); } catch(MalformedURLException e) { e.printStackTrace(); } } public void play() { ac.play(); } public void stop() { ac.stop(); } public void loop() { } }
Revision: 1774
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 9, 2006 23:55 by whitetiger
Initial Code
package Multimedia; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.plaf.metal.MetalLookAndFeel; public class AudioSystem { public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel(new MetalLookAndFeel()); } catch(UnsupportedLookAndFeelException e) { e.printStackTrace(); } new AudioGUI(); } } package Multimedia; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.File; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JPanel; public class AudioGUI extends JFrame implements WindowListener { public AudioGUI() { this.setTitle("AudioSystem"); this.setSize(240, 100); this.setResizable(false); this.addWindowListener(this); Container gc = this.getContentPane(); gc.add(new AudioGUIPan()); this.setVisible(true); } public void windowOpened(WindowEvent e) { } public void windowClosing(WindowEvent e) { System.exit(0); } public void windowClosed(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } } class AudioGUIPan extends JPanel implements ActionListener { private JButton play; private JButton stop; private JButton loop; private JButton open; private JButton close; private JFileChooser jfc; private String file; private AudioDevice ad; public AudioGUIPan() { play = new JButton("Play"); play.addActionListener(this); stop = new JButton("Stop"); stop.addActionListener(this); open = new JButton("Open"); open.addActionListener(this); close = new JButton("Close"); close.addActionListener(this); this.add(stop); this.add(play); this.add(open); this.add(close); } public void actionPerformed(ActionEvent e) { if(e.getSource() == close) { System.exit(0); } else if(e.getSource() == open) { jfc = new JFileChooser(); jfc.setFileFilter(new AudioFilter()); if(jfc.showOpenDialog(this) != JFileChooser.CANCEL_OPTION) { file = jfc.getSelectedFile().getAbsolutePath(); ad = new AudioDevice(new File(file)); } } else if(e.getSource() == play) { if(ad != null) ad.play(); } else if(e.getSource() == stop) { if(ad != null) ad.stop(); } } } package Multimedia; import java.io.File; import javax.swing.filechooser.FileFilter; public class AudioFilter extends FileFilter { public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".wav") || f.isDirectory(); } public String getDescription() { return "Audio File *.wav"; } } package Multimedia; import java.applet.Applet; import java.applet.AudioClip; import java.io.File; import java.net.MalformedURLException; public class AudioDevice implements AudioClip { private AudioClip ac; public AudioDevice(File f) { try { ac = Applet.newAudioClip(f.toURL()); } catch(MalformedURLException e) { e.printStackTrace(); } } public void play() { ac.play(); } public void stop() { ac.stop(); } public void loop() { } }
Initial URL
Initial Description
Initial Title
Java - Mini Lettore Wav
Initial Tags
window, java, python, video, windows, filter, linux, theme
Initial Language
Java