hi,
hab mir ein java-programm mit netbeans (!) geschrieben, allerdings wenn ich, es als jar-datei kompilieren will, spuckt er mir nen fehler aus. in netbeans selbst kommt kein fehler.
hier der code:
Java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class Gallery extends JFrame implements ItemListener, ActionListener
{
public JButton prev;
public JButton next;
public JLabel bild;
public Border border;
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 München",
"Bot. Garten Augsburg", "Autosalon Augsburg", "Paardurchbruch"};
public String year_path = "Main";
public String event_path = "";
public int[] insges = {1,36,25,11,12,7,51,13,18,9,17};
public int akt = 1;
public int eventid = 0;
public Gallery ()
{
setTitle("Gallery");
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]);
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");
p.add(q, "Center");
r = new JPanel();
r.setLayout(new BorderLayout());
r.add(p, "South");
// angeblich liegt der fehler hier, ka was da falsch sein soll...
icon = new ImageIcon(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild = new JLabel();
bild.setIcon(icon);
r.add(bild, "North");
next.addActionListener(this);
prev.addActionListener(this);
add(r);
setVisible(true);
pack();
}
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(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 1;
anz.setText("Bild " + akt + "/" + insges[eventid]);
pack();
}
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(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 2;
anz.setText("Bild " + akt + "/" + insges[eventid]);
pack();
}
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(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
anz.setText("Bild " + akt + "/" + insges[eventid]);
eventid = 3;
pack();
}
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(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 4;
anz.setText("Bild " + akt + "/" + insges[eventid]);
pack();
}
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(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 5;
anz.setText("Bild " + akt + "/" + insges[eventid]);
pack();
}
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(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 6;
anz.setText("Bild " + akt + "/" + insges[eventid]);
pack();
}
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(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 7;
anz.setText("Bild " + akt + "/" + insges[eventid]);
pack();
}
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(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 8;
anz.setText("Bild " + akt + "/" + insges[eventid]);
pack();
}
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(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 9;
anz.setText("Bild " + akt + "/" + insges[eventid]);
pack();
}
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(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
eventid = 10;
anz.setText("Bild " + akt + "/" + insges[eventid]);
pack();
}
}
}
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(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
pack();
}
}
else if (e.getSource() == prev)
{
if ((akt <= insges[eventid]) && (akt > 1))
{
akt--;
anz.setText("Bild " + akt + "/" + insges[eventid]);
icon = null;
icon = new ImageIcon(ClassLoader.getSystemResource("../src/"+year_path+"/"+event_path+"/bild"+akt+".jpg"));
bild.setIcon(icon);
r.add(bild, "North");
pack();
}
}
}
}
Alles anzeigen