hi,
sry, dass ich schon wieder so unwissend bin, aber ich hab noch ein kleines Problem bzgl. der Darstellung. und zwar hab ich mir ein Applet programmiert, welches eine Bildergalerie darstellt. Jetzt das Problem: In der Bildergalerie befinden sich Bilder im Hoch- und Querformat. Bei den Bildern im Hochformat wird jetzt der Rahmen nicht richtig angepasst, und das Bild wird auch nicht zentriert, wär nett, wenn mir einer von euch helfen könnte.
Hier könnt ihr euch das Applet auch anschauen! Das erste unter 2008 ist z.B. ein Hochformatbild!
Hier mein Code:
Java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Color.*;
import javax.swing.border.*;
public class Gallery extends JApplet implements ItemListener, ActionListener
{
public Color c1;
public Color c2;
public JButton prev;
public JButton next;
public JLabel bild;
public JComboBox year;
public JComboBox event;
public JLabel anz;
public JPanel p;
public JPanel q;
public JPanel r;
public Icon icon;
public String[] year_feld = {"Jahr", "2007", "2008", "2009"};
public String[] event_feld = {"Event", "Garten", "Lonetal", "Eurasburg", "Chiemsee", "Staffelsee", "Kanada", "Bot. Garten Muenchen",
"Bot. Garten Augsburg", "Autosalon Augsburg", "Paardurchbruch"};
public String year_path = "Main";
public String event_path = "Main";
public int[] insges = {1,36,25,11,12,7,51,13,18,9,17};
public int akt = 1;
public int eventid = 0;
public void init ()
{
c1 = new Color(51,51,51);
c2 = new Color(223,223,223);
p = new JPanel();
p.setLayout(new BorderLayout());
prev = new JButton("Previous");
next = new JButton("Next");
p.add(prev, "West");
p.add(next, "East");
year = new JComboBox();
event = new JComboBox();
anz = new JLabel("Bild " + akt + "/" + insges[eventid]);
anz.setForeground(c2);
year.addItem(year_feld[0]);
year.addItem(year_feld[1]);
year.addItem(year_feld[2]);
year.addItem(year_feld[3]);
year.addItemListener(this);
event.addItem(event_feld[0]);
event.addItemListener(this);
q = new JPanel();
q.add(year, "West");
q.add(anz, "East");
q.add(event, "Center");
q.setBackground(c1);
p.add(q, "Center");
r = new JPanel();
r.setLayout(new BorderLayout());
r.add(p, "South");
r.setBackground(c1);
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild = new JLabel();
bild.setIcon(icon);
bild.setBorder(new EtchedBorder(Color.gray, Color.GRAY));
r.add(bild, "North");
next.addActionListener(this);
prev.addActionListener(this);
add(r);
setVisible(true);
}
public void itemStateChanged (ItemEvent e)
{
if (e.getSource() == year)
{
if ((String)year.getSelectedItem() == year_feld[1])
{
year.removeItem(year_feld[0]);
event.removeAllItems();
event.addItem(event_feld[1]);
event.addItem(event_feld[2]);
event.addItem(event_feld[3]);
event.addItem(event_feld[4]);
event.addItem(event_feld[5]);
event.addItem(event_feld[6]);
}
else if ((String)year.getSelectedItem() == year_feld[2])
{
year.removeItem(year_feld[0]);
event.removeAllItems();
event.addItem(event_feld[7]);
event.addItem(event_feld[8]);
event.addItem(event_feld[9]);
}
else if ((String)year.getSelectedItem() == year_feld[3])
{
year.removeItem(year_feld[0]);
event.removeAllItems();
event.addItem(event_feld[10]);
}
}
else if (e.getSource() == event)
{
if (((String)year.getSelectedItem() == year_feld[1]) && ((String)event.getSelectedItem() == event_feld[1]))
{
year_path = year_feld[1];
event_path = event_feld[1];
akt = 1;
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 1;
anz.setText("Bild " + akt + "/" + insges[eventid]);
}
else if (((String)year.getSelectedItem() == year_feld[1]) && ((String)event.getSelectedItem() == event_feld[2]))
{
event_path = event_feld[2];
akt = 1;
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 2;
anz.setText("Bild " + akt + "/" + insges[eventid]);
}
else if (((String)year.getSelectedItem() == year_feld[1]) && ((String)event.getSelectedItem() == event_feld[3]))
{
event_path = event_feld[3];
akt = 1;
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
anz.setText("Bild " + akt + "/" + insges[eventid]);
eventid = 3;
}
else if (((String)year.getSelectedItem() == year_feld[1]) && ((String)event.getSelectedItem() == event_feld[4]))
{
event_path = event_feld[4];
akt = 1;
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 4;
anz.setText("Bild " + akt + "/" + insges[eventid]);
}
else if (((String)year.getSelectedItem() == year_feld[1]) && ((String)event.getSelectedItem() == event_feld[5]))
{
event_path = event_feld[5];
akt = 1;
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 5;
anz.setText("Bild " + akt + "/" + insges[eventid]);
}
else if (((String)year.getSelectedItem() == year_feld[1]) && ((String)event.getSelectedItem() == event_feld[6]))
{
event_path = event_feld[6];
akt = 1;
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 6;
anz.setText("Bild " + akt + "/" + insges[eventid]);
}
else if (((String)year.getSelectedItem() == year_feld[2]) && ((String)event.getSelectedItem() == event_feld[7]))
{
year_path = year_feld[2];
event_path = event_feld[7];
akt = 1;
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 7;
anz.setText("Bild " + akt + "/" + insges[eventid]);
}
else if (((String)year.getSelectedItem() == year_feld[2]) && ((String)event.getSelectedItem() == event_feld[8]))
{
event_path = event_feld[8];
akt = 1;
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 8;
anz.setText("Bild " + akt + "/" + insges[eventid]);
}
else if (((String)year.getSelectedItem() == year_feld[2]) && ((String)event.getSelectedItem() == event_feld[9]))
{
event_path = event_feld[9];
akt = 1;
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 9;
anz.setText("Bild " + akt + "/" + insges[eventid]);
}
else if (((String)year.getSelectedItem() == year_feld[3]) && ((String)event.getSelectedItem() == event_feld[10]))
{
year_path = year_feld[3];
event_path = event_feld[10];
akt = 1;
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 10;
anz.setText("Bild " + akt + "/" + insges[eventid]);
}
}
}
public void actionPerformed (ActionEvent e)
{
if (e.getSource() == next)
{
if (akt < insges[eventid])
{
akt++;
anz.setText("Bild " + akt + "/" + insges[eventid]);
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
}
}
else if (e.getSource() == prev)
{
if ((akt <= insges[eventid]) && (akt > 1))
{
akt--;
anz.setText("Bild " + akt + "/" + insges[eventid]);
icon = null;
icon = new ImageIcon(Gallery.class.getResource(year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
}
}
}
}
Alles anzeigen