Foros del Web » Programación para mayores de 30 ;) » Java »

eventos java

Estas en el tema de eventos java en el foro de Java en Foros del Web. amigos necesito una pista de como hacer para meter un evento a un boton. !!!!!!!!!!!!!!!!!!!!Tengo la clase base:!!!!!!!!!!!! package Instrumentos; import java.io.*; import java.util.*; abstract ...
  #1 (permalink)  
Antiguo 05/06/2012, 11:33
 
Fecha de Ingreso: junio-2012
Mensajes: 32
Antigüedad: 11 años, 11 meses
Puntos: 1
eventos java

amigos necesito una pista de como hacer para meter un evento a un boton.

!!!!!!!!!!!!!!!!!!!!Tengo la clase base:!!!!!!!!!!!!




package Instrumentos;
import java.io.*;
import java.util.*;
abstract class Instrumento {

protected String notas;
protected String clave;
public Instrumento(String notas,String clave) {
this.notas=notas;
this.clave=clave;
}
public void setNotas(String notas){
this.notas=notas;
}
public String getNotas(){
return notas;
}
public void setClave(String clave){
this.clave=clave;
}
public String getClave(){
return clave;
}
abstract String conversion();

public String leerGrafico()
{
File f;
javax.swing.JFileChooser j= new javax.swing.JFileChooser();
j.showOpenDialog(j);
String path= j.getSelectedFile().getAbsolutePath();
String lectura="";
f = new File(path);
try{
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String aux;
while((aux = br.readLine())!=null)
lectura = lectura+aux+"\n";
}catch(IOException e){}
return lectura;
}
}




!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!la subclase!!!!!!!!!!!!!!!!!!!





package Instrumentos;
import java.io.*;
import java.util.*;
public class Trompeta extends Instrumento{
private String tono;
public Trompeta(String notas,String clave) {
super(notas,clave);
this.tono="Sib";
}
public String conversion(){
String TokenActual="";
String conversion1="";
String conversion2="";
String conversion3="";
String conversion4="";
String conversion5="";
String conversion6="";
String conversion7="";
String conversion8="";
String conversion9="";
String conversion10="";
String conversion11="";
String conversion12="";
String conversion13="";
String echo="";

Instrumento Trompeta=new Trompeta(notas,clave);
String l=Trompeta.leerGrafico();
StringTokenizer tokens=new StringTokenizer(l);

while(tokens.hasMoreTokens()){
TokenActual=tokens.nextToken();
conversion1=TokenActual.replaceAll("DO" , "re");
conversion2+="\t"+conversion1.replaceAll("DO#" , "re#");
conversion3=conversion2.replaceAll("RE" , "mi");
conversion4=conversion3.replaceAll("RE#" , "fa");
conversion5=conversion4.replaceAll("MI" , "fa#");
conversion6=conversion5.replaceAll("FA" , "sol");
conversion7=conversion6.replaceAll("FA#" , "sol#");
conversion8=conversion7.replaceAll("SOL" , "la");
conversion9=conversion8.replaceAll("SOL#" , "la#");
conversion10=conversion9.replaceAll("LA" , "si");
conversion11=conversion10.replaceAll("LA#" , " do ");
conversion12=conversion11.replaceAll("SI" , "do#");
conversion13=conversion12.replaceAll("SIB" , "la#");
echo=conversion13;
}
return echo;
}
}

!!!!!!!!!!!!!!!!!!!!!!!!!!la clase prueba (main)!!!!!!!!!!!!!!!!!!!!!

package Instrumentos;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class PruebaInstrumentos {
public static void main(String args[])throws IOException{
int max=5;
Instrumento x[]=new Instrumento[max];
int menu=1;
while(menu!=0){
menu=Integer.parseInt(JOptionPane.showInputDialog( "A que instrumento transportara sus notas :\n1.-Transportar a trompeta \n2.-Transportar a Tuba \n3.-Transportar a Sax Alto \n4.-Transportar a Sax Tenor\n5.-Transportar a Corno\n6.-Transportar a Trombon \n0.-Salir"));
switch(menu){
case 1:
int i=0;
if(x[i]==null){
x[i]=new Trompeta("[Sonoridad:Agudas--","Instrumento En Clave de (SOL)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("Trompeta.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
else{
i++;
x[i]=new Trompeta("[Sonoridad:Agudas--","Instrumento En Clave de (SOL)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("Trompeta.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
break;
case 2:
i=0;
if(x[i]==null){
x[i]=new Tuba("[Sonoridad:Graves--","Instrumento En Clave de (FA)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("Tuba.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
else{i++;
x[i]=new Tuba("[Sonoridad:Graves--","Instrumento En Clave de(FA)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("Tuba.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
break;
case 3:
i=0;
if(x[i]==null){
x[i]=new SaxofonAlto("[Sonoridad:Medios--","Instrumento En Clave de (SOL)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("SaxAlto.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
else{i++;
x[i]=new SaxofonAlto("[Sonoridad:Medios--","Instrumento En Clave de (SOL)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("SaxAlto.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
break;
case 4:
i=0;
if(x[i]==null){
x[i]=new SaxofonTenor("[Sonoridad:MediosGraves--","Instrumento En Clave de (SOL)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("SaxTenor.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
else{
i++;
x[i]=new SaxofonTenor("[Sonoridad:MediosGraves--","Instrumento En Clave de (SOL)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("SaxTenor.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
break;
case 5:
i=0;
if(x[i]==null){
x[i]=new CORNO("[Sonoridad:MediasGraves--","Instrumento En Clave de (SOL)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("CORNO.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
else{
i++;
x[i]=new CORNO("[Sonoridad:MediasGraves--","Instrumento En Clave de (SOL)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("CORNO.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
break;
case 6:
i=0;
if(x[i]==null){
x[i]=new Trombon("[Sonoridad:MediasGraves--","Instrumento En Clave de (SOL)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("Trombon.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
else{
i++;
x[i]=new Trombon("[Sonoridad:MediasGraves--","Instrumento En Clave de (SOL)]");
PrintWriter stdOut = new PrintWriter(new FileWriter("Trombon.txt"));
stdOut.print(x[i].getNotas());
stdOut.print(x[i].getClave());
stdOut.println(x[i].conversion());
stdOut.close();}
break;

}}}}

!!!!!!!!!!!!!!!!!!!!!!!!!!HAORA AKI MI PROBLEMA!!!!!!!!!!!!!!!!!!!!!
esta es la clase ventana



import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;

public class Ventana extends JFrame {
private JButton boton,boton2,boton3,boton4,boton5,boton6,boton7;
private JLabel nombre;
private JTextField op;

public Ventana() {
boton=new JButton("Trompeta");
boton2=new JButton("Tuba");
boton3=new JButton("Sax Alto");
boton4=new JButton("Sax Tenor");
boton5=new JButton("Corno");
boton6=new JButton("Trombom");
boton7=new JButton("Cancelar");
nombre=new JLabel("Elige el instrumento deseado");
op=new JTextField();
setLayout(null);
add(boton);
boton.setBounds(30,80,100,40);
add(nombre);
nombre.setBounds(160,40,80,80);
nombre.setSize(200,10);
add(boton2);
boton2.setBounds(190,80,100,40);
add(boton3);
boton3.setBounds(350,80,100,40);
add(boton4);
boton4.setBounds(30,230,100,40);
add(boton5);
boton5.setBounds(190,230,100,40);
add(boton6);
boton6.setBounds(350,230,100,40);
add(boton7);
boton7.setBounds(390,320,100,40);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Manejadorvent manejador=new Manejadorvent();
boton.addActionListener(manejador);
}
public class Manejadorvent implements ActionListener{
public void actionPerformed(ActionEvent e){


}}




public static void main(String args[]){
final Ventana Miventana=new Ventana();
Miventana.setVisible(true);
Miventana.setSize(500,400);
Miventana.setTitle("UNIVERSAL SPEED NOTAS");

}


}

como le agrego lo que tiene el case 1 a el primer boton porque ya no tendria chiste el menu en la clase main si ya los puse en la ventana?

Etiquetas: eventos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:09.