Bild aus button + 2 bild wenn zeiger drauf ist

gutes Beispiel, du bis geil,Thomas Darimont

Hallo!

Schau mal hier:
Code:
 /**
  * 
  */
 package de.tutorials;
 
 import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.Image;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 
 import javax.imageio.ImageIO;
 import javax.swing.JFrame;
 import javax.swing.JPanel;
 
 /**
  * @author Tom
  * 
  */
 public class RolloverExample extends JFrame {
 
 	public RolloverExample() {
 		super("RolloverExample");
 		setDefaultCloseOperation(EXIT_ON_CLOSE);
 
 		add(new RolloverPanel(new File("c:/Sonnenuntergang.jpg"), new File(
 				"c:/Wasserlilien.jpg")));
 
 		pack();
 		setVisible(true);
 	}
 
 	/**
 	 * @param args
 	 */
 	public static void main(String[] args) {
 		new RolloverExample();
 	}
 
 	class RolloverPanel extends JPanel {
 
 		BufferedImage overImage, outImage;
 
 		boolean showOut = true;
 
 		public RolloverPanel(File overImage, File outImage) {
 			try {
 				this.overImage = ImageIO.read(overImage);
 				this.outImage = ImageIO.read(outImage);
 			} catch (IOException e) {
 				e.printStackTrace();
 			}
 
 			setPreferredSize(new Dimension(this.overImage.getWidth(),
 					this.overImage.getHeight()));
 
 			addMouseListener(new MouseAdapter() {
 				public void mouseEntered(MouseEvent e) {
 					showOut = false;
 					repaint();
 				}
 
 				public void mouseExited(MouseEvent e) {
 					showOut = true;
 					repaint();
 				}
 			});
 
 		}
 
 		protected void paintComponent(Graphics g) {
 			super.paintComponent(g);
 
 			Image img = showOut ? outImage : overImage;
 			g.drawImage(img, 0, 0, this);
 		}
 	}
 }

Gruß Tom
 
Zurück