Sie sind auf Seite 1von 3

import java.awt.

BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

public class EtiquetasyBotones extends JFrame implements ActionListener,


MouseListener {

private Container contenedor;


private JSplitPane jsp;
private JPanel panelSup, panelInf;
private JLabel lblMascota1;
private JLabel lblMascota2;
private JButton btnSalir;
private JLabel lblImgCasa, lblMsg;
private ImageIcon imgMascota1, imgMascota2, imgCasa1, imgCasa2;
private Font fuente;

//contructor
public EtiquetasyBotones(String titulo) {
super(titulo);
contenedor = this.getContentPane();

//creacion de componentes
jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
panelSup = new JPanel();
panelInf = new JPanel();
imgMascota1 = new
ImageIcon(this.getClass().getResource("snoopy.png"));//snoopy
imgMascota2 = new
ImageIcon(this.getClass().getResource("tortuga.png"));//turtle
imgCasa1 = new
ImageIcon(this.getClass().getResource("casaSnoopy.jpg"));//snphouse
imgCasa2 = new
ImageIcon(this.getClass().getResource("casaTortuga.png"));//turjouse

lblMascota1 = new JLabel("Snoopy", imgMascota1, JLabel.CENTER);


lblMascota2 = new JLabel("Crush", imgMascota2, JLabel.CENTER);
btnSalir = new JButton("Salir");
lblImgCasa = new JLabel();
lblImgCasa.setHorizontalAlignment(JLabel.CENTER);
lblMsg = new JLabel("Esta es mi casa");
fuente = new Font("Serif", Font.BOLD, 24);

//Cconfiguracion de componentes
panelSup.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
panelInf.setLayout(new BorderLayout());
lblMascota1.setVerticalTextPosition(JLabel.BOTTOM);
lblMascota1.setHorizontalTextPosition(JLabel.CENTER);
lblMascota2.setVerticalTextPosition(JLabel.BOTTOM);
lblMascota2.setHorizontalTextPosition(JLabel.CENTER);
lblMascota1.setToolTipText("Hola soy Snoopy");
lblMascota2.setToolTipText("Hola soy crush");
lblMascota1.setFont(fuente);
lblMascota2.setFont(fuente);
lblMascota1.setForeground(Color.red);
lblMascota2.setForeground(Color.green);
lblMascota1.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2,
true));
lblMascota2.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2,
true));
lblMsg.setHorizontalAlignment(JLabel.CENTER);
lblMsg.setFont(fuente);
lblMsg.setVisible(false);

//se agregan componentes


panelSup.add(lblMascota1);
panelSup.add(lblMascota2);
jsp.setTopComponent(panelSup);
panelInf.add(lblMsg, BorderLayout.NORTH);
panelInf.add(btnSalir, BorderLayout.SOUTH);
panelInf.add(lblImgCasa, BorderLayout.CENTER);
jsp.setBottomComponent(panelInf);
contenedor.add(jsp);

//configuracion de listeners
lblMascota1.addMouseListener(this);
lblMascota2.addMouseListener(this);
btnSalir.addActionListener(this);

//this.set
this.setVisible(true);
this.setSize(550, 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

@Override
public void setDefaultCloseOperation(int i) {
super.setDefaultCloseOperation(i);
}

@Override
public void setSize(int i, int i1) {
super.setSize(i, i1);
}

@Override
public void setSize(Dimension dmnsn) {
super.setSize(dmnsn);
}

@Override
public void setVisible(boolean bln) {
super.setVisible(bln);
}
@Override
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}

@Override
public void mouseClicked(MouseEvent me) {

@Override
public void mousePressed(MouseEvent me) {

@Override
public void mouseReleased(MouseEvent me) {
}

@Override
public void mouseEntered(MouseEvent me) {
lblMsg.setVisible(true);
if (me.getSource() == lblMascota1) {
lblImgCasa.setIcon(imgCasa1);
} else {
lblImgCasa.setIcon(imgCasa2);
}
}

@Override
public void mouseExited(MouseEvent me) {
lblImgCasa.setIcon(null);
lblMsg.setVisible(false);
}

Das könnte Ihnen auch gefallen