Christopher
2013-05-22 14:57:50 UTC
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
/**
* Date:5/15/13
* Description:Learning
*/
public class Sax extends JFrame implements KeyListener{
char c;
boolean n, b, m, o, k, h = false;
private Graphics g;
public void paint(Graphics g)
{
super.paint(g);
if (c == 'n'){
n = true;}
if (c == 'm'){
m = true;}
if (c == 'b'){
b = true;}
if (c == 'o'){
o = true;}
if (c == 'k'){
k = true;}
if (c == 'h'){
h = true;}
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent e) {
c = e.getKeyChar();
if (n == true){
/*Neck and Bell*/
g.fillOval(406, 410, 80, 60);
g.fillRoundRect(271, 260, 120, 30, 10, 10);
}
if (m == true){
/*Mouthpiece*/
g.setColor(Color.BLACK);
g.fillOval(217, 259, 70, 32);
g.fillRect(238, 260, 50, 30);
}
if (b == true){
/*Body of Sax*/
g.setColor(Color.ORANGE);
g.fillArc(350, 560, 120, 120, 180, 180);
g.fillRoundRect(351, 260, 40, 380, 10, 10);
g.fillRoundRect(415, 423, 55, 200, 10, 10);
}
if (o == true){
/*Octave Key*/
g.setColor(Color.ORANGE);
g.drawArc(294, 249, 95, 30, 180, -180);
g.drawArc(294, 248, 95, 30, 180, -180);
g.drawArc(294, 247, 95, 30, 180, -180);
g.setColor(Color.BLACK);
g.drawArc(294, 250, 95, 30, 180, -180);
g.drawArc(294, 246, 95, 30, 180, -180);
}
if (k == true){
/*Keys*/
g.setColor(Color.BLACK);
g.fillOval(376, 350, 15, 15);
g.fillOval(376, 366, 15, 15);
g.fillOval(376, 382, 15, 15);
g.fillOval(360, 500, 15, 15);
g.fillOval(360, 516, 15, 15);
g.fillOval(360, 532, 15, 15);
}
if (h == true){
/*Hole In Bell and Outline of Bell*/
g.setColor(Color.BLACK);
g.fillOval(416, 417, 60, 40);
g.drawArc(410, 431, 70, 37, 186, 150);
}
}
}