[C con Clase] duda java crear 3 botones para 3 imagenes
Miguel Angulo Martínez
djfunk19 en hotmail.com
Lun Mayo 14 18:55:42 CEST 2012
Quiero que al pinchar un boton me salga una imagen, inmediantemente cuando pincho en otro boton se me desactive esa imagen y me active la imagen en el fondo de pantalla. Lo he intentado hacer pero no me funciona alguien me puede echar una mano
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Imagenes extends JFrame implements ActionListener{
static final long serialVersionUID=0;
JPanel panel;
JLabel etiqueta;
JButton b1;
JButton b2;
JButton b3;
Image bg;
public Imagenes(){
panel = new JPanel();
panel.setLayout(new FlowLayout());
etiqueta = new JLabel();
setSize(800,600);
setLocation(110,90);
b1 = new JButton("Imagen 1");
b2 = new JButton("Imagen 2");
b3 = new JButton("Imagen 3");
panel.add(b1);
panel.add(b2);
panel.add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
add(panel);
}
public void actionPerformed(ActionEvent evento){
if(evento.getSource()==b1){
ImageIcon imagen1 = new ImageIcon("imagen1.jpg");
etiqueta.setIcon(imagen1);
etiqueta.setVisible(true);
panel.add(etiqueta);
}
if(evento.getActionCommand()=="Imagen 2"){
ImageIcon imagen2 = new ImageIcon("imagen2.jpg");
etiqueta.setIcon(imagen2);
etiqueta.setVisible(true);
panel.add(etiqueta);
}
if(evento.getActionCommand()=="Imagen 3"){
ImageIcon imagen3 = new ImageIcon("imagen3.jpg");
etiqueta.setIcon(imagen3);
panel.add(etiqueta);
etiqueta.setVisible(true);
}
}
public static void main(String args[]){
Imagenes img = new Imagenes();
img.setVisible(true);
}
}
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.conclase.net/pipermail/cconclase_listas.conclase.net/attachments/20120514/f065a8df/attachment.html>
Más información sobre la lista de distribución Cconclase