Interfaz:
Codigo:
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
//INTERFAZ
public class Tecla extends Frame
{
//atributos
private int estado = 0;
private int ubicacion = 0;
private int sonido;
//constructor
public Tecla () { };
//metodos
public void paint(Graphics g) {
g.setColor(Color.white);
g.drawRect(43, 80, 20, 80);
g.fillRect(43, 80, 20, 80);
g.drawRect(66, 80, 20, 80);//posicion horizontal, vertical tamano ancho largo
g.fillRect(66, 80, 20, 80);
g.drawRect(89, 80, 20, 80);
g.fillRect(89, 80, 20, 80);
g.drawRect(112, 80, 20, 80);
g.fillRect(112, 80, 20, 80);
g.drawRect(135, 80, 20, 80);
g.fillRect(135, 80, 20, 80);
g.drawRect(158, 80, 20, 80);
g.fillRect(158, 80, 20, 80);
g.drawRect(181, 80, 20, 80);
g.fillRect(181, 80, 20, 80);
g.drawRect(204, 80, 20, 80);
g.fillRect(204, 80, 20, 80);
g.drawRect(227, 80, 20, 80);
g.fillRect(227, 80, 20, 80);
g.drawRect(250, 80, 20, 80);
g.fillRect(250, 80, 20, 80);
g.setColor(Color.black);
g.drawRect(60, 80, 12, 40);
g.fillRect(60, 80, 12, 40);
g.drawRect(83, 80, 12, 40);
g.fillRect(83, 80, 12, 40);
g.drawRect(129, 80, 12, 40);
g.fillRect(129, 80, 12, 40);
g.drawRect(152, 80, 12, 40);
g.fillRect(152, 80, 12, 40);
g.drawRect(175, 80, 12, 40);
g.fillRect(175, 80, 12, 40);
g.drawRect(218, 80, 12, 40);
g.fillRect(218, 80, 12, 40);
g.drawRect(241, 80, 12, 40);
g.fillRect(241, 80, 12, 40);
}
public static void main(String args[]) {
Frame frame = new Tecla();
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
frame.setBackground(Color.green);
frame.setSize(315,200);
frame.setVisible(true);
frame.setTitle("Mi piano");
}
//KeyEvent
public void keyPressed(KeyEvent e)
{
switch(){
case KeyEvent.VK_Q:
System.out.println("DO");
break;
case KeyEvent.VK_W:
System.out.println("RE");
break;
case KeyEvent.VK_E:
System.out.println("MI");
break;
case KeyEvent.VK_R:
System.out.println("FA");
break;
case KeyEvent.VK_T:
System.out.println("SOL");
break;
case KeyEvent.VK_Y:
System.out.println("LA");
break;
case KeyEvent.VK_Q:
System.out.println("SI");
break;
}
}
//music
//variables
//set estado newvar estado
public void setEstado ( int newVar ) {
estado = newVar;
}
//get estado return estado
public int getEstado ( ) {
return estado;
}
//set ubicacion newvar ubicacion
public void setUbicacion ( int newVar ) {
newVar = ubicacion++;
ubicacion = newVar;
}
//get ubicacion return ubicacion
public int getUbicacion ( ) {
return ubicacion;
}
}