Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.applet.*;
- public class Soundplayer extends JApplet implements ActionListener
- {
- JRadioButton radio1, radio2, radio3;
- ButtonGroup group1;
- JPanel panel1;
- JLabel label1, label2, label3;
- JButton button4,button5,button6;
- AudioClip clip1,clip2,clip3;
- public void init()
- {
- setSize(400,250);
- Container cp;
- cp = getContentPane();
- cp.setLayout(new GridLayout(1,1));
- radio1 = new JRadioButton();
- radio2 = new JRadioButton();
- radio3 = new JRadioButton();
- label1 = new JLabel("Charmander");
- label2 = new JLabel("Bulbasaur");
- label3 = new JLabel("Squirtle");
- button4 = new JButton("Play");
- button5 = new JButton("Stop");
- button6 = new JButton("Loop");
- clip1 = getAudioClip(getDocumentBase(), "ashchar.wav");
- clip2 = getAudioClip(getDocumentBase(), "ashbsaur.wav");
- clip3 = getAudioClip(getDocumentBase(), "ashsqrtl.wav");
- ButtonGroup group1 = new ButtonGroup();
- group1.add(radio1);
- group1.add(radio2);
- group1.add(radio3);
- panel1 = new JPanel();
- cp.add(panel1);
- panel1.setLayout(null);
- panel1.add(radio1);
- panel1.add(radio2);
- panel1.add(radio3);
- panel1.add(label1);
- panel1.add(label2);
- panel1.add(label3);
- panel1.add(button4);
- panel1.add(button5);
- panel1.add(button6);
- radio1.setBounds(50,50,50,50);
- radio2.setBounds(50,100,50,50);
- radio3.setBounds(50,150,50,50);
- label1.setBounds(100,50,100,50);
- label2.setBounds(100,100,100,50);
- label3.setBounds(100,150,100,50);
- button4.setBounds(200,65,150,20);
- button5.setBounds(200,115,150,20);
- button6.setBounds(200,165,150,20);
- radio1.addActionListener(this);
- radio2.addActionListener(this);
- radio3.addActionListener(this);
- button4.addActionListener(this);
- button5.addActionListener(this);
- button6.addActionListener(this);
- }
- public void actionPerformed (ActionEvent e)
- {
- if (e.getSource() == button4)
- {
- if(radio1.isSelected())
- {
- clip1.play();
- }
- else if(radio2.isSelected())
- {
- clip2.play();
- }
- else if (radio3.isSelected())
- {
- clip3.play();
- }
- }
- if (e.getSource() == button5)
- {
- if(radio1.isSelected())
- {
- clip1.stop();
- }
- else if(radio2.isSelected())
- {
- clip2.stop();
- }
- else if (radio3.isSelected())
- {
- clip3.stop();
- }
- }
- if (e.getSource() == button6)
- {
- if(radio1.isSelected())
- {
- clip1.loop();
- }
- else if(radio2.isSelected())
- {
- clip2.loop();
- }
- else if (radio3.isSelected())
- {
- clip3.loop();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment