Sunday 27 July 2014

if adt doesn't start??? ADT error !!! Solve it now :)

what to do if your adt bundle suddenly stops working? it happened with me... when i started the adt eclipse, it just appeared for a flash of time and the adt startup screen disappeared.. so i have a solution for this...
if this happens with you all you have to do is

  1. go to the folder where you have saved all the adt files
  2. then delete the metadata  folder
  3. reopen the eclipse
  4. it will work as it was working previously
  5. if you are facing some other problem you can comment below... we will solve your problem 

Monday 21 July 2014

program to play music in JFrame

import java.io.*;
import java.net.URL;
import javax.sound.sampled.*;
import javax.swing.*;
 
// To play sound using Clip, the process need to be alive.
// Hence, we use a Swing application.
public class sounds extends JFrame {
 
   // Constructor
   public sounds() {
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      this.setTitle("Test Sound Clip");
      this.setSize(300, 200);
      this.setVisible(true);
   
      try {
   
         // Open an audio input stream.
         URL url = this.getClass().getClassLoader().getResource("mus.wav");
         //
          AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
         // Get a sound clip resource.
          for(int i=0; i<10; i++){   Clip clip = AudioSystem.getClip();
         // Open audio clip and load samples from the audio input stream.
         clip.open(audioIn);
         clip.start();}
      } catch (UnsupportedAudioFileException e) {
     JOptionPane.showMessageDialog(this, e.getMessage());
         e.printStackTrace();
      } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getMessage());
         e.printStackTrace();
      } catch (LineUnavailableException e) { JOptionPane.showMessageDialog(this, e.getMessage());
         e.printStackTrace();
      }
   }
 
   public static void main(String[] args) {
      new sounds();
   }
}

Wednesday 16 July 2014

Program to play and stop music on your choice in java applet

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class mus3 extends Applet
implements ActionListener{
   Button play,stop;
   AudioClip audioClip;
   public void init(){
      play = new Button("  Play ");
      add(play);
      play.addActionListener(this);
      stop = new Button("  Stop  ");
      add(stop);
      stop.addActionListener(this);
      audioClip = getAudioClip(getCodeBase(), "mus.wav");
   }
   public void actionPerformed(ActionEvent ae){
      Button source = (Button)ae.getSource();
      if (source.getLabel() == "  Play  "){
         audioClip.play();
      }
      else if(source.getLabel() == "  Stop  "){
         audioClip.stop();
      }
   }
}

Tuesday 15 July 2014

Program to play music in java Applet

import java.applet.*;
import java.awt.*;

public class music1 extends Applet {
   Button play,stop;
   AudioClip audioClip;
   public void init(){
   
      audioClip = getAudioClip(getCodeBase(), "mus.wav");
      audioClip.play();
   }
 
}