Jump to User:

myOtaku.com: purplebeef


Sunday, April 18, 2004


/*
A nearly trivial guitar tuner app, 5/97, by Lisa Gade, made with CodeWarrior 11 on Mac.
Sampled notes from my Martin OMC-28 acoustic (tuned with quartz tuner, A=440),
artsy impressionistic picture of tuner courtesy of moi via Infini 3D and Photoshop.
Feel free to learn from or use pieces of this code. If you use substantial parts
of it, I ask that you give me credit, and perhaps even a ref to this page. Enjoy!
Last updated 7/22/97 to fix font sizing problems on Mac under Communicator 4.01
*/

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

public class Guitar extends Applet {
int width;
int height;


Image background;
boolean done_loading_image=false;
Graphics g;
Font font;

CheckboxGroup Group1;
//declare checkboxes
Checkbox radioButton1;
Checkbox radioButton2;
Checkbox radioButton3;
Checkbox radioButton4;
Checkbox radioButton5;
Checkbox radioButton6;

//define AudioClips variable names;
AudioClip snd1;
AudioClip snd2;
AudioClip snd3;
AudioClip snd4;
AudioClip snd5;
AudioClip snd6;

//____________finished declarations, now on to applet's working innards________


public void init() {
g=getGraphics();

//---set up double buffering/aka off-screen drawing of image to avoid flicker
background=this.getImage(this.getDocumentBase(), "tuner3.gif");
Image offScrImage=createImage(size().width, size().height);
Graphics offScrGC=offScrImage.getGraphics();
offScrGC.drawImage(background,0,0,this);
play(getDocumentBase(),"BlueDust.au"); // play that funky intro guitar riff!


super.init();
setLayout(null);
resize(224,181);
//addNotify();
Group1= new CheckboxGroup();

//Define and initialize the Checkbox items

radioButton1 = new Checkbox("",Group1, false);
add(radioButton1);
radioButton1.reshape(25, 56, 14, 12);
radioButton2 = new Checkbox("",Group1, false);
add(radioButton2);
radioButton2.reshape(48, 64, 14, 12);
radioButton3 = new Checkbox("",Group1, false);
add(radioButton3);
radioButton3.reshape(72, 70, 14, 12);
radioButton4 = new Checkbox("",Group1, false);
add(radioButton4);
radioButton4.reshape(95, 75, 14, 12);
radioButton5 = new Checkbox("",Group1, false);
add(radioButton5);
radioButton5.reshape(115, 80, 14, 12);
radioButton6 = new Checkbox("",Group1, true);
add(radioButton6);
radioButton6.reshape(138, 90, 14, 12);



//Define the audio clip files
snd6=getAudioClip(getDocumentBase(), "snd1.au");
snd5=getAudioClip(getDocumentBase(), "snd2.au");
snd4=getAudioClip(getDocumentBase(), "snd3.au");
snd3=getAudioClip(getDocumentBase(), "snd4.au");
snd2=getAudioClip(getDocumentBase(), "snd5.au");
snd1=getAudioClip(getDocumentBase(), "snd6.au");
}


//_______________________________________________________________

//Check to see if the entire image is done drawing yet (offscreen)
public boolean imageUpdate (Image img, int infoflags, int x, int y, int w, int h)
{
if (infoflags==ALLBITS) {
width=background.getWidth(this);
height=background.getHeight(this);
done_loading_image=true;
repaint();

return false;
}
else
return true;
}


//________________________________________________________________
public boolean handleEvent(Event event) {


//Defining event handlers
if (event.id == Event.ACTION_EVENT && event.target == radioButton1)
{
snd1.play();
}
if (event.id == Event.ACTION_EVENT && event.target == radioButton2)
{
snd2.play();
}
if (event.id == Event.ACTION_EVENT && event.target == radioButton3)
{
snd3.play();
}
if (event.id == Event.ACTION_EVENT && event.target == radioButton4)
{
snd4.play();
}
if (event.id == Event.ACTION_EVENT && event.target == radioButton5)
{
snd5.play();
}
if (event.id == Event.ACTION_EVENT && event.target == radioButton6)
{
snd6.play();
}

return super.handleEvent(event);
}

//___________________________________________________________________
public void paint(Graphics g) {
if (!done_loading_image)
showStatus("Guitar Tuner: loading image");
else {
showStatus("Guitar Tuner: Done");
g.drawImage(background, 0,0, null);
g.setColor(Color.red);
Font font=new Font("Helvetica", Font.BOLD, 10);
g.setFont(font);
g.drawString("GuitarTuner 1.3 by Lisa Gade,1997",10,165);

}
}
}

Comments (3)

« Home