import java.awt.Graphics;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.net.URL;
 import javax.imageio.ImageIO;
 import javax.swing.*;
 import java.util.*;
  import java.awt.FontMetrics;
  import java.awt.event.MouseEvent; 
import java.awt.event.MouseListener; 

  
 //pic erbt von Panel - spart eine Klasse
public class PicPanel extends JPanel  {
  
  ArrayList<Key> keys;
    
    
  public PicPanel(ArrayList<Key> keys){
    
    this.keys = keys;
    
    
  }
    
  public void drawCenteredString(String s, int xx, int yy, Graphics g) {
    FontMetrics fm = g.getFontMetrics();
    int x = xx-  fm.stringWidth(s) / 2;
    g.drawString(s, x, yy);
  }
    
    //paintComponent überschreiben, Image zeichnen, super-Aufruf nicht vergessen
      @Override
    protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    for (int x = 0; x < keys.size(); x++) {
      g.drawImage(keys.get(x).getImage(),x*32,2,this);
      drawCenteredString(keys.get(x).getName(),x*32+16,50,g);
    }
    
  }
  
  public String getToolTipText(MouseEvent evt) {
    int k = evt.getX() /32;
    if (keys.size()>k) {
      return "<html><p width=400><b>Exponent:</b><br>"+keys.get(k).getE()+"</p><p width=400><b>Modul:</b><br>"+keys.get(k).getN()+"</p></html>";
    } // end of if
    return "Schlüsselspeicher";
  }
    
    
    
}
