Tema: Boton salir
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/11/2009, 12:28
cypres_snk
 
Fecha de Ingreso: noviembre-2009
Mensajes: 3
Antigüedad: 14 años, 5 meses
Puntos: 0
Boton salir

tengo este codigo:

/*Diseñar un frame que contenga 11 botones, como si se tratara de un traductor,
cuando se presione cualquiera de los 10 primeros botones se imprima su valor, pero en inglés.
Cuando se presione el último botón, salir de la aplicación.*/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class Traductor extends Applet implements ActionListener
{
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11;
String t="";
Traductor salir;
public Traductor()
{
b1=new Button("Uno");
b2=new Button("Dos");
b3=new Button("Tres");
b4=new Button("Cuatro");
b5=new Button("Cinco");
b6=new Button("Seis");
b7=new Button("Siete");
b8=new Button("Ocho");
b9=new Button("Nueve");
b10=new Button("Diez");
b11=new Button("Salir");

add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(b10);
add(b11);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t="One";
}
if(e.getSource()==b2)
{
t="Two";
}
if(e.getSource()==b3)
{
t="Three";
}
if(e.getSource()==b4)
{
t="Four";
}
if(e.getSource()==b5)
{
t="Five";
}
if(e.getSource()==b6)
{
t="Six";
}
if(e.getSource()==b7)
{
t="Seven";
}
if(e.getSource()==b8)
{
t="Eight";
}
if(e.getSource()==b9)
{
t="Nine";
}
if(e.getSource()==b10)
{
t="Ten";
}
if(e.getSource()==b11)
{
t="Exit";
System.exit(0);
}
repaint();
}

public void paint(Graphics g)
{
setBackground(Color.black);
g.setColor(Color.red);
g.drawString(t,150,150);
}

}

lo qeu busco qeu al darle al boton salir me cierre la aplicacion
alguien tiene alguna ayuda



modifiqeu la aplicacion enves de extends Applets le puse extends Frame
y agregre el main y le puse dentro del main
Traductor salir=new Traductor();
salir=new Traductor();
salir.setSize(400,400);
salir.setVisible(true);
salir.addWindowListener(new Cerrar());


y me cierra la aplicacion pero nomas me aparese ahora el boton salir ylos demas no aparecen

Nota el new Cerrar de una clase aparte qeu tiene lo siguieente:
import java.awt.event.*;

public class Cerrar extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}

Última edición por cypres_snk; 28/11/2009 a las 13:12