"webster" <> wrote in message news:<aKmTa.9169$>...
> I have a program that plays drum samples. The problem is when i select 2
> check boxes close together it gets out of time a bit. I was just wondering
> if there is a way of overcoming this? Some body has told me that i cant fix
> it cos that's just what java does. I have included a sample of my program so
> you can see what I'm on about.
> thanks
> matt
>
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
> import java.applet.*;
> import java.net.*;
> public class TBtest extends JFrame implements ActionListener{
> JCheckBox box1,box2,box3,box4;
> JButton play;
> public TBtest(){
> super("Test for sound using tickBox and button");
> setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> setSize(200,100);
> setVisible(true);
> Container contentArea = getContentPane();
> contentArea.setLayout(new FlowLayout());
> box1 = new JCheckBox();
> box2 = new JCheckBox();
> box3 = new JCheckBox();
> box4 = new JCheckBox();
> play = new JButton("play");
> play.addActionListener(this);
> contentArea.add(box1);
> contentArea.add(box2);
> contentArea.add(box3);
> contentArea.add(box4);
> contentArea.add(play);
> setContentPane(contentArea);
> }
> void pause(int duration) {
> try {
> Thread.sleep(duration);
> }catch (InterruptedException e) {}
> }
> public void actionPerformed(ActionEvent event) {
> String command = event.getActionCommand();
> if(event.getSource() == play)
> { try
> { URL Basefile = new URL("file:base.wav");
> AudioClip Base = JApplet.newAudioClip(Basefile);
> URL Snarefile = new URL("file:snare.wav");
> AudioClip Snare = JApplet.newAudioClip(Snarefile);
> if (box1.isSelected())
> Base.play();
> if (box2.isSelected())
> Snare.play();
> pause(800);
> if (box3.isSelected())
> Base.play();
> if (box4.isSelected())
> Snare.play();
> }
> catch (MalformedURLException error) {}
> }
> }
> public static void main(String[] args)
> {TBtest Drum = new TBtest();}
> }
it is easy
|