Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package eventosBotonesApplet;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.event.MouseAdapter;
  6. import java.awt.event.MouseEvent;
  7. import javax.swing.JApplet;
  8. import javax.swing.JButton;
  9. import javax.swing.JLabel;
  10.  
  11. /**
  12.  *
  13.  * @author Rafa
  14.  */
  15. public class eventosBotonesApplet extends JApplet{
  16.     private JButton bt1, bt2, bt3;
  17.     private JLabel label;
  18.    
  19.     public void init(){
  20.         bt1 = new JButton("Boton1");
  21.         bt2 = new JButton("Boton2");
  22.         bt3 = new JButton("Boton3");
  23.        
  24.         label = new JLabel("Prueba de Eventos");
  25.        
  26.         //Agrega los botones
  27.         add(bt1);
  28.         add(bt2);
  29.         add(bt3);
  30.         add(label);
  31.         setLayout(null);
  32.        
  33.         //Establece colores a loc botones
  34.         bt1.setBackground(Color.red);
  35.         bt2.setBackground(Color.GREEN);
  36.         bt3.setBackground(Color.CYAN);
  37.        
  38.         //izquierda, arriba, ancho, altura
  39.         bt1.reshape(70, 20, 100, 30);
  40.         bt2.reshape(70, 60, 100, 30);
  41.         bt3.reshape(70, 100, 100, 30);
  42.        
  43.     }
  44.    
  45.     public void eventos(){
  46.         bt1.addMouseListener(new MouseAdapter() {
  47.             public void mousePressed(MouseEvent e){
  48.                 System.out.println("Se ha presionado el Boton1");
  49.             }
  50.         });
  51.         bt2.addMouseListener(new MouseAdapter() {
  52.             public void mousePressed(MouseEvent e){
  53.                 System.out.println("Se ha presionado el Boton2");
  54.             }
  55.         });
  56.         bt3.addMouseListener(new MouseAdapter() {
  57.             public void mousePressed(MouseEvent e){
  58.                 System.out.println("Se ha presionado el Boton3");
  59.             }
  60.         });
  61.     }
  62.     public void start(){
  63.         eventos();
  64.     }
  65.     public void paint(Graphics g){
  66.        
  67.     }      
  68. }