Ja, hallo ich bins mal wieder, ich bin schon sehr viel Weitergekommen mit meinem Klavierprojekt, es ist theoretisch Fertig, aber er speilt einfach keinen Ton ab, der Compiler gibt auch keine Fehlermeldung aus...
Die Dateien befinden sich im gleichen verzeichnis. JDK ist version 1.6
EDIT: Jetzt hab ich meinen Lehrer konsultiert, und nur noch einen Fehler, und zwar, dass er clip nicht kennt, obwohl ich javax.sound.sampled eingebunden habe...
Den rest kannn man sich ja denken...
Ich bin euch wie immer Dankbar
Die Dateien befinden sich im gleichen verzeichnis. JDK ist version 1.6
EDIT: Jetzt hab ich meinen Lehrer konsultiert, und nur noch einen Fehler, und zwar, dass er clip nicht kennt, obwohl ich javax.sound.sampled eingebunden habe...
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.Long.*;
import java.io.*;
import javax.sound.sampled*;
public class Keyboard extends Frame implements MouseListener
{
private Button bt1 = new Button("Ton1");
private Button bt2 = new Button("Ton2");
private Button bt3 = new Button("Ton3");
private Button bt4 = new Button("Ton4");
private Button bt5 = new Button("Ton5");
private Button bt6 = new Button("Ton6");
private Button bt7 = new Button("Ton7");
private Button bt8 = new Button("Ton8");
private Button bt9 = new Button("Ton9");
private Button bt10 = new Button("Ton10");
private Button bt11 = new Button("Ton11");
private Button bt12 = new Button("Ton12");
private Button bt13 = new Button("Ton13");
private Button bt14 = new Button("Ton14");
private Button bt15 = new Button("Ton15");
private Button bt16 = new Button("Ton16");
private Button bt17 = new Button("Ton17");
private Button bt18 = new Button("Ton18");
private Button bt19 = new Button("Ton19");
private Button bt20 = new Button("Ton20");
//ImageIcon bt1 = createImageIcon("p.gif");
AudioClip ton1;
AudioClip ton2;
AudioClip ton3;
AudioClip ton4;
AudioClip ton5;
AudioClip ton6;
AudioClip ton7;
AudioClip ton8;
AudioClip ton9;
AudioClip ton10;
AudioClip ton11;
AudioClip ton12;
AudioClip ton13;
AudioClip ton14;
AudioClip ton15;
AudioClip ton16;
AudioClip ton17;
AudioClip ton18;
AudioClip ton19;
AudioClip ton20;
public Keyboard()
{
super("Keyboard");
setSize(1000,300);
setLocation(100,100);
setVisible(true);
setLayout(null);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
System.exit(0);
}
});
bt1.setBounds(50,100,40,90);
bt2.setBounds(90,100,40,90);
bt3.setBounds(130,100,40,90);
bt4.setBounds(170,100,40,90);
bt5.setBounds(210,100,40,90);
bt6.setBounds(250,100,40,90);
bt7.setBounds(290,100,40,90);
bt8.setBounds(330,100,40,90);
bt9.setBounds(370,100,40,90);
bt10.setBounds(410,100,40,90);
bt11.setBounds(450,100,40,90);
bt12.setBounds(490,100,40,90);
bt13.setBounds(530,100,40,90);
bt14.setBounds(570,100,40,90);
bt15.setBounds(610,100,40,90);
bt16.setBounds(650,100,40,90);
bt17.setBounds(690,100,40,90);
bt18.setBounds(730,100,40,90);
bt19.setBounds(770,100,40,90);
bt20.setBounds(810,100,40,90);
add(bt1);
add(bt2);
add(bt3);
add(bt4);
add(bt5);
add(bt6);
add(bt7);
add(bt8);
add(bt9);
add(bt10);
add(bt11);
add(bt12);
add(bt13);
add(bt14);
add(bt15);
add(bt16);
add(bt17);
add(bt18);
add(bt19);
add(bt20);
getDocBase();
bt1.addActionListener(new Taste());
bt2.addActionListener(new Taste());
bt3.addActionListener(new Taste());
bt4.addActionListener(new Taste());
bt5.addActionListener(new Taste());
bt6.addActionListener(new Taste());
bt7.addActionListener(new Taste());
bt8.addActionListener(new Taste());
bt9.addActionListener(new Taste());
bt10.addActionListener(new Taste());
bt11.addActionListener(new Taste());
bt12.addActionListener(new Taste());
bt13.addActionListener(new Taste());
bt14.addActionListener(new Taste());
bt15.addActionListener(new Taste());
bt16.addActionListener(new Taste());
bt17.addActionListener(new Taste());
bt18.addActionListener(new Taste());
bt19.addActionListener(new Taste());
bt20.addActionListener(new Taste());
File file = new File ("tada.wav");
AudioInputStream stream =
AudioSystem.getAudioInputStream(file);
AudioFormat format = stream.getFormat();
DataLine.Info info = new DataLine.Info (Clip.class, format);
Clip clip = (clip) AudioSystem.getLine(info);
clip.open();
}
public void getDocBase()
{
try
{
File f = new File( "tada.wav" );
ton1 = Applet.newAudioClip( f.toURL() );
File a = new File( "tada.wav" );
ton2 = Applet.newAudioClip( a.toURL() );
File b = new File( "tada.wav" );
ton3 = Applet.newAudioClip( b.toURL() );
File c = new File( "tada.wav" );
ton4 = Applet.newAudioClip( c.toURL() );
File d = new File( "tada.wav" );
ton5 = Applet.newAudioClip( d.toURL() );
File e = new File( "tada.wav" );
ton6 = Applet.newAudioClip( e.toURL() );
File g = new File( "tada.wav" );
ton7 = Applet.newAudioClip( g.toURL() );
File h = new File( "tada.wav" );
ton8 = Applet.newAudioClip( h.toURL() );
File i = new File( "tada.wav" );
ton9 = Applet.newAudioClip( i.toURL() );
File j = new File( "tada.wav" );
ton10 = Applet.newAudioClip( j.toURL() );
File k = new File( "tada.wav" );
ton11 = Applet.newAudioClip( k.toURL() );
File l = new File( "tada.wav" );
ton12 = Applet.newAudioClip( l.toURL() );
File m = new File( "tada.wav" );
ton13 = Applet.newAudioClip( m.toURL() );
File n = new File( "tada.wav" );
ton14 = Applet.newAudioClip( n.toURL() );
File o = new File( "tada.wav" );
ton15 = Applet.newAudioClip( o.toURL() );
File p = new File( "tada.wav" );
ton16 = Applet.newAudioClip( p.toURL() );
File q = new File( "tada.wav" );
ton17 = Applet.newAudioClip( q.toURL() );
File r = new File( "tada.wav" );
ton18 = Applet.newAudioClip( r.toURL() );
File s = new File( "tada.wav" );
ton19 = Applet.newAudioClip( s.toURL() );
File t = new File( "tada.wav" );
ton20 = Applet.newAudioClip( t.toURL() );
}
catch (Exception e )
{
}
}
class Taste implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="ton1") ton1.play();
if(e.getActionCommand()=="ton2") ton2.play();
if(e.getActionCommand()=="ton3") ton3.play();
if(e.getActionCommand()=="ton4") ton4.play();
if(e.getActionCommand()=="ton5") ton5.play();
if(e.getActionCommand()=="ton6") ton6.play();
if(e.getActionCommand()=="ton7") ton7.play();
if(e.getActionCommand()=="ton8") ton8.play();
if(e.getActionCommand()=="ton9") ton9.play();
if(e.getActionCommand()=="ton10") ton10.play();
if(e.getActionCommand()=="ton11") ton11.play();
if(e.getActionCommand()=="ton12") ton12.play();
if(e.getActionCommand()=="ton13") ton13.play();
if(e.getActionCommand()=="ton14") ton14.play();
if(e.getActionCommand()=="ton15") ton15.play();
if(e.getActionCommand()=="ton16") ton16.play();
if(e.getActionCommand()=="ton17") ton17.play();
if(e.getActionCommand()=="ton18") ton18.play();
if(e.getActionCommand()=="ton19") ton19.play();
if(e.getActionCommand()=="ton20") ton20.play();
}
}
public void paint(Graphics g)
{
g.drawString("Willkomen bei Daniels Klavier",50,50);
}
public void mouseClicked(MouseEvent evt)
{
ton1.play();
}
public void mousePressed(MouseEvent evt)
{
ton1.play();
clip.start();
Den rest kannn man sich ja denken...
Ich bin euch wie immer Dankbar