Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Rectangle;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import javax.swing.JApplet;
- import java.awt.Color;
- import java.awt.Image;
- import java.awt.*;
- import javax.swing.*;
- import java.util.ArrayList;
- import java.applet.AudioClip;
- import java.io.*;
- import java.net.*;
- import java.applet.*;
- // import java.util.Timer;
- // import java.util.TimerTask;
- // import java.util.TimerTask;
- //eventually allow the user to select specific notes and play them at once.
- //what if the notes had constructors that made it so they had predefined coordinates?
- //why is does the select chord feature act buggy at times?
- public class PianoPlayer extends JApplet implements MouseListener, MouseMotionListener
- {
- private int takeAway;
- private int inc;
- private String lastAction;
- private Color turnOn;
- private Color disclamer;
- private Graphics2D g2d;
- private Color colorS;
- private Color colorL;
- private int clicked;
- private int songType;
- private Color color;
- private Color colorSingle;
- private Color colorMaj;
- private Color colorMin;
- private Image piano;
- private Image barNorm;
- private Image barNormal;
- private Image barFinal;
- private Image typeBox;
- private Image wordSound;
- private Image typeBox2;
- private Image right;
- private Image left;
- private Image turner;
- private Image currentTurner;
- private int x;
- private int y;
- private int xBar;
- private int yBar;
- private static final int onWHITE = 365;
- // private static final int onBLACK = 0; //hasn't been used, but I hope to use it someday
- private int playBool;
- private static final int level = 0;
- private boolean runner;
- private boolean single;
- private boolean maj;
- private boolean min;
- public int turn;
- private Song singleMode = new Song(358, 453, 21, 10);
- private Song majMode = new Song(357, 467, 35, 25);
- private Song minMode = new Song(357, 467, 50, 40);
- private Song onRight = new Song(32, 41, 380, 366);
- private Song onLeft = new Song(17, 26, 380, 366);
- private Song board = new Song(51,215,392,110);
- private String note;
- private String currentSong = "";
- private int currentSongLength;
- private String type;
- private String typeOn;
- private Image mediant;
- private Image dominant;
- private int xMed;
- private int yMedDom;
- private int xDom;
- private int xE1;
- private int xA1;
- private int xD2;
- private int xG2;
- private int xB2;
- private int xE3;
- private ArrayList<Keys> hold = new ArrayList<Keys>();// use this and an array of pics to create a loop? How would I display them?
- private String showHold;
- private boolean holder;
- private Color colorHold;
- private Song holdMode = new Song(358, 444, 66, 55);
- private Song play = new Song (450, 509, 66, 55);
- private Color colorPlay;
- private Song pianoBoard = new Song(52, 758, 393, 108);
- //================================================================================
- Sound eSound1;
- Sound aSound1;
- Sound dSound2;
- Sound gSound2;
- Sound bSound2;
- Sound eSound3;
- //================================================================================
- private Image loading;
- private Image pE1;
- private Image pA1;
- private Image pD2;
- private Image pG2;
- private Image pB2;
- private Image pE3;
- //private Image pD1PRESS;
- private Image pE1PRESS;
- private Image pA1PRESS;
- private Image pD2PRESS;
- private Image pG2PRESS;
- private Image pB2PRESS;
- private Image pE3PRESS;
- private Image ePRESS1Add;
- private Image aPRESS1Add;
- private Image dPRESS2Add;
- private Image gPRESS2Add;
- private Image bPRESS2Add;
- private Image ePRESS3Add;
- //================================================================================
- private White e1 = new White(153, 202, 174, 202, ePRESS1Add);
- private White a1 = new White(304, 354, 320, 347, aPRESS1Add);
- private White d2 = new White(457, 507, 465, 497, dPRESS2Add);
- private White g2 = new White(607, 657, 618, 644, gPRESS2Add);
- private White b2 = new White(709, 759, 732, 754, bPRESS2Add);
- private White e3 = new White(406, 456, 406, 436, ePRESS3Add);
- //================================================================================
- public PianoPlayer()
- {
- takeAway = 0;
- inc = 0;
- lastAction = "none";
- addMouseListener(this);
- addMouseMotionListener(this);
- colorS = Color.white;
- colorL = Color.white;
- color = Color.white;
- colorSingle = Color.white;
- //colorMaj = Color.gray;
- //colorMin = Color.gray;
- //colorPlay = Color.black;
- piano = Toolkit.getDefaultToolkit().getImage("Piano.jpg");
- barNorm = Toolkit.getDefaultToolkit().getImage("BarNorm.jpg");
- barNormal = Toolkit.getDefaultToolkit().getImage("BarNorm.jpg");
- barFinal = Toolkit.getDefaultToolkit().getImage("BarFinal.jpg");
- typeBox = Toolkit.getDefaultToolkit().getImage("TypeBox.jpg");
- wordSound = Toolkit.getDefaultToolkit().getImage("Sound.jpg");
- typeBox2 = Toolkit.getDefaultToolkit().getImage("TypeBox2.jpg");
- right = Toolkit.getDefaultToolkit().getImage("Right.jpg");
- left = Toolkit.getDefaultToolkit().getImage("Left.jpg");
- runner = false;
- turn = 0;
- note = "";
- xBar = 670;
- yBar = 21;
- currentSong = "";
- currentSongLength = 0;
- single = true;
- //maj = false;
- //min = false;
- playBool = 0;
- //turnOn = Color.black;
- //disclamer = Color.black;
- clicked = 0;
- type = "Note: ";
- songType = 1;
- currentTurner = typeBox;
- typeOn = "Piano";
- yMedDom = level;
- xE1 = 146;
- xA1 = 296;
- xD2 = 446;
- xG2 = 602;
- xB2 = 701;
- xE3 = 396;
- holder= false;
- colorHold = Color.gray;
- ePRESS1Add = Toolkit.getDefaultToolkit().getImage("EPRESS1add.jpg");
- aPRESS1Add = Toolkit.getDefaultToolkit().getImage("APRESS1add.jpg");
- dPRESS2Add = Toolkit.getDefaultToolkit().getImage("DPRESS2add.jpg");
- gPRESS2Add = Toolkit.getDefaultToolkit().getImage("GPRESS2add.jpg");
- bPRESS2Add = Toolkit.getDefaultToolkit().getImage("BPRESS2add.jpg");
- ePRESS3Add = Toolkit.getDefaultToolkit().getImage("EPRESS3add.jpg");
- pE1 = Toolkit.getDefaultToolkit().getImage("E1.jpg");
- pA1 = Toolkit.getDefaultToolkit().getImage("A1.jpg");
- pD2 = Toolkit.getDefaultToolkit().getImage("D2.jpg");
- pG2 = Toolkit.getDefaultToolkit().getImage("G2.jpg");
- pB2 = Toolkit.getDefaultToolkit().getImage("B2.jpg");
- pE3 = Toolkit.getDefaultToolkit().getImage("E3.jpg");
- loading = Toolkit.getDefaultToolkit().getImage("loader.jpg");
- pE1PRESS = Toolkit.getDefaultToolkit().getImage("EPRESS1.jpg");
- pA1PRESS = Toolkit.getDefaultToolkit().getImage("APRESS1.jpg");
- pD2PRESS = Toolkit.getDefaultToolkit().getImage("DPRESS2.jpg");
- pG2PRESS = Toolkit.getDefaultToolkit().getImage("GPRESS2.jpg");
- pB2PRESS = Toolkit.getDefaultToolkit().getImage("BPRESS2.jpg");
- pE3PRESS = Toolkit.getDefaultToolkit().getImage("EPRESS3.jpg");
- }
- // private Keys[] myNotes = { c1, cSharp1, d1, dSharp1, e1, f1, fSharp1, g1, gSharp1, a1, aSharp1, b1,
- // c2, cSharp2, d2, dSharp2, e2, f2, fSharp2, g2, gSharp2, a2, aSharp2, b2, e3 };
- public void paint(Graphics g)
- {
- g2d = (Graphics2D) getGraphics();
- g2d.drawImage(piano, 0, 0, this);
- g2d.drawImage(mediant, xMed, yMedDom, this);
- g2d.drawImage(dominant, xDom, yMedDom, this);
- g2d.drawImage(barNorm, xBar, yBar, this);
- g2d.drawImage(barNormal, 670, 21, this);
- g2d.drawImage(barFinal, 670, 41, this);
- g2d.setColor(Color.white);
- g2d.drawString(typeOn, 14, 316);
- g2d.drawImage(currentTurner, 10, 316, this);
- g2d.drawImage(turner, 17, 363, this);
- //if (maj || min)
- // takeAway = 10;
- //else
- if ( !holder )
- takeAway = 0;
- g2d.setColor(color);
- g2d.drawString(type + note, (369 - takeAway), 106);
- // g2d.setColor(Color.white);
- //g2d.drawString("" + x + "," + y, x, y);
- g2d.setColor(Color.white);
- //g2d.drawString("= Normal guide note" , 689, 32);
- //g2d.drawString("= Final guide note" , 689, 52);
- g2d.setColor(colorSingle);
- g2d.drawString("Single Note Mode" , 357, 21);
- g2d.setColor(colorMaj);
- g2d.drawString("Major Chord Mode" , 356, 36);
- g2d.setColor(colorMin);
- g2d.drawString("Minor Chord Mode" , 356, 51);
- g2d.setColor(colorHold);
- g2d.drawString("Personal Chord", 358, 65);
- g2d.setColor(colorPlay);
- g2d.drawString("Play Chord", 450, 65);
- g2d.setColor(turnOn);
- g2d.drawString("One mode must be selected to make sound", 285,80);
- }
- public void restore()
- {
- colorS = Color.white;
- colorL = Color.white;
- xBar = 670;
- yBar = 21;
- turn = 0;
- runner = false;
- currentSong = "";
- currentSongLength = 0;
- barNorm = barNormal;
- takeAway = 0;
- }
- public void restoreChords()
- {
- mediant = null;
- dominant = null;
- }
- // TheSounds=====================================
- public void e1()
- {
- if (songType == 1)
- {
- Sound eSound1 = new Sound(this, "sE1.wav");
- eSound1.playSoundOnce();
- }
- }
- public void a1()
- {
- if (songType == 1)
- {
- Sound aSound1 = new Sound(this, "sA1.wav");
- aSound1.playSoundOnce();
- }
- }
- public void d2()
- {
- if (songType == 1)
- {
- Sound dSound2 = new Sound(this, "sD2.wav");
- dSound2.playSoundOnce();
- }
- }
- public void g2()
- {
- if (songType == 1)
- {
- Sound gSound2 = new Sound(this, "sG2.wav");
- gSound2.playSoundOnce();
- }
- }
- public void b2()
- {
- if (songType == 1)
- {
- Sound bSound2 = new Sound(this, "sB2.wav");
- bSound2.playSoundOnce();
- }
- }
- public void e3()
- {
- if (songType == 1)
- {
- Sound eSound3 = new Sound(this, "sE3.wav");
- bSound2.playSoundOnce();
- }
- }
- public void mouseClicked(MouseEvent e)
- {
- x = e.getX();
- y = e.getY();
- if ((!single) && (!min) && (!maj) && (!holder))
- turnOn = Color.red;
- else
- turnOn = Color.black;
- // if ( (maj || min) && clicked < 3)
- // disclamer = Color.red;
- // else
- // {
- // disclamer = Color.black;
- // }
- if ( single )
- {
- //del49
- //del55
- if( e1.onKey(x, y) )
- {
- e1();
- }
- else if( a1.onKey(x, y) )
- {
- a1();
- }
- else if( d2.onKey(x, y) )
- {
- d2();
- }
- else if( g2.onKey(x, y) )
- {
- g2();
- }
- else if( b2.onKey(x, y) )
- {
- b2();
- }
- else if( e3.onKey(x, y) )
- {
- e3();
- }
- }
- }
- public void mouseEntered(MouseEvent e)
- {
- }
- public void mouseExited(MouseEvent e)
- { }
- public void mousePressed(MouseEvent e)
- {
- x = e.getX();
- y = e.getY();
- if ( holder && pianoBoard.isIn(x,y) )
- takeAway+=9;
- //Del1
- else if (singleMode.isIn(x,y) )
- {
- colorSingle = Color.darkGray;
- //colorMaj = Color.gray;
- //colorMin = Color.gray;
- colorHold = Color.gray;
- repaint();//why do I need this here for this to work?
- }
- else if (holdMode.isIn(x,y) )
- {
- colorHold = Color.darkGray;
- colorSingle = Color.gray;
- //colorMaj = Color.gray;
- //colorMin = Color.gray;
- repaint();//why do I need this here for this to work?
- }
- else if (play.isIn(x,y))
- colorPlay = Color.gray;
- if (onRight.isIn(x,y) )
- turner = right;
- else if (onLeft.isIn(x,y) )
- turner = left;
- else if( e1.onKey(x, y) )
- {
- piano = pE1PRESS;
- //del6
- if (holder)
- {
- hold.add(e1);
- note += " E, ";
- }
- }
- else if( a1.onKey(x, y) )
- {
- piano = pA1PRESS;
- //del11
- if (holder)
- {
- hold.add(a1);
- note += " A, ";
- }
- }
- else if( d2.onKey(x, y) )
- {
- piano = pD2PRESS;
- //del16
- if (holder)
- {
- hold.add(d2);
- note += " D, ";
- }
- }
- else if( g2.onKey(x, y) )
- {
- piano = pG2PRESS;
- if (holder)
- {
- hold.add(g2);
- note += " G, ";
- }
- }
- else if( b2.onKey(x, y) )
- {
- piano = pB2PRESS;
- if (holder)
- {
- hold.add(b2);
- note += " B, ";
- }
- }
- else if( e3.onKey(x, y) )
- {
- piano = pE3PRESS;
- if (holder)
- {
- hold.add(e3);
- note += " E, ";
- }
- }
- else
- {
- piano = Toolkit.getDefaultToolkit().getImage( "Piano.jpg" );
- }
- repaint();
- }
- public void mouseReleased(MouseEvent e)
- {
- x = e.getX();
- y = e.getY();
- if (singleMode.isIn(x,y) )
- {
- if ( single )
- {
- colorSingle = Color.gray;
- single = false;
- }
- else
- {
- colorSingle = Color.white;
- single = true;
- note = "";
- type = "Note: ";
- //maj = false;
- //colorMaj = Color.gray;
- //min = false;
- //colorMin = Color.gray;
- clicked = 0;
- holder = false;
- colorHold = Color.gray;
- hold.clear();
- }
- }
- else if ( holdMode.isIn(x,y) )
- {
- if ( holder )
- {
- colorHold = Color.gray;
- holder = false;
- }
- else
- {
- holder = true;
- note = "";
- colorHold = Color.white;
- type = "Your Chord: ";
- //maj = false;
- //colorMaj = Color.gray;
- single = false;
- colorSingle = Color.gray;
- //min = false;
- //colorMin = Color.gray;
- hold.clear();
- }
- }
- if ( !holder )
- colorPlay = Color.black;
- if ( holder )
- {
- if (hold.size() < 2)
- colorPlay = Color.gray;
- else
- {
- colorPlay = Color.red;//why does it not realize hold has been cleared? Why do i need to use inc?
- }
- if ( colorPlay == Color.red && play.isIn(x,y) )
- {
- colorPlay = Color.gray;
- }
- }
- if (onRight.isIn(x,y) )
- {
- turner = null;
- if (songType == 1)
- {
- currentTurner = typeBox2;
- songType = 2;
- typeOn = "Guitar";
- }
- else
- {
- currentTurner = typeBox;
- songType = 1;
- typeOn = "Piano";
- }
- }
- else if (onLeft.isIn(x,y) )
- {
- turner = null;
- if (songType == 1)
- {
- currentTurner = typeBox2;
- songType = 2;
- typeOn = "Guitar";
- }
- else
- {
- currentTurner = typeBox;
- songType = 1;
- typeOn = "Piano";
- }
- }
- if( e1.onKey(x, y) )
- {
- piano = pE1;
- }
- else if( a1.onKey(x, y) )
- {
- piano = pA1;
- }
- else if( d2.onKey(x, y) )
- {
- piano = pD2;
- }
- else if( g2.onKey(x, y) )
- {
- piano = pG2;
- }
- else if( b2.onKey(x, y) )
- {
- piano = pB2;
- }
- else if( e3.onKey(x, y) )
- {
- piano = pE3;
- }
- else
- {
- piano = Toolkit.getDefaultToolkit().getImage( "Piano.jpg" );
- }
- if ( holder )
- {
- if (play.isIn(x,y) )
- {
- for (int rep = 0; rep < hold.size(); rep++)
- {
- //del51
- //del45
- //del58
- if( hold.get(rep) == e1 )
- {
- e1();
- }
- if( hold.get(rep) == a1 )
- {
- a1();
- }
- if( hold.get(rep) == d2 )
- {
- d2();
- }
- if( hold.get(rep) == g2 )
- {
- g2();
- }
- if( hold.get(rep) == b2 )
- {
- b2();
- }
- if( hold.get(rep) == e3 )
- {
- e3();
- }
- hold.remove(rep--); //why does this work?????????????????????????????? why should there be a --?
- }
- note = "";
- takeAway = 0;
- }
- }
- repaint();
- restoreChords();
- }
- // =======================================
- public void mouseMoved(MouseEvent e)
- {
- x = e.getX();
- y = e.getY();
- //del52
- //del59
- if( e1.onKey(x, y) )
- {
- piano = pE1;
- if (single)
- note ="E";
- }
- else if( a1.onKey(x, y) )
- {
- piano = pA1;
- if (single)
- note ="A";
- }
- else if( d2.onKey(x, y) )
- {
- piano = pD2;
- if (single)
- note ="D";
- }
- else if( g2.onKey(x, y) )
- {
- piano = pG2;
- if (single)
- note ="G";
- else if (!holder && !single )
- note = "";
- }
- else if( b2.onKey(x, y) )
- {
- piano = pB2;
- if (single)
- note ="B";
- else if (!holder && !single )
- note = "";
- }
- else if( e3.onKey(x, y) )
- {
- piano = pE3;
- if (single)
- note ="E";
- //else if (!holder && !single )
- //note = "";
- }
- else if ( !holder )
- {
- note = "";
- }
- repaint();
- }
- public void mouseDragged(MouseEvent e)
- {
- x = e.getX();
- y = e.getY();
- if ( !holder )
- {
- //del53
- //del60
- if( e1.onKey(x, y) )
- {
- e1();
- }
- else if( a1.onKey(x, y) )
- {
- a1();
- }
- else if( d2.onKey(x, y) )
- {
- d2();
- }
- else if( g2.onKey(x, y) )
- {
- g2();
- }
- else if( b2.onKey(x, y) )
- {
- b2();
- }
- else if( e3.onKey(x, y) )
- {
- e3();
- }
- else
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement