Ich habe diesen Code hier:
Ich weiß nicht woran das Problem liegt? kennt jemand die Lösung, oder sieht jemand ein Fehler in meinem Code? Ich sitze an diesen Bildern nun schon seit 2 Tagen und finde die Lösung nicht, das demotiviert...
.
Danke!
Code:
package de.m_ver.minigamecollector.scheresteinpapier;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class SchereSteinPapierGUI extends JFrame {
public SchereSteinPapierGUI() {
super("Schere Stein Papier");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocation(450, 0);
this.initialisiereKomponenenten();
this.ordneKomponenten();
this.setSize(550, 735);
//this.add(new JLabel(new ImageIcon("C:\\Users\\name\\Pictures\\Game \\images.png"))); [So wird das Bild angezeigt
}
private JLabel labelBackground;
private JLabel labelScissors;
private JLabel labelStone;
private JLabel labelPaper;
private JLabel labelMessage;
private ImageIcon iconBackground;
private ImageIcon iconScissors;
private ImageIcon iconStone;
private ImageIcon iconPaper;
private void initialisiereKomponenenten() {
this.labelBackground = new JLabel(iconBackground); //so wird das Bild nicht angezeigt
this.labelScissors = new JLabel(iconScissors);
this.labelStone = new JLabel(iconStone);
this.labelPaper = new JLabel(iconPaper);
this.labelMessage = new JLabel("MESSAGE");
this.iconBackground = new ImageIcon("C:\\Users\\name\\Pictures\\Game\\images.png");
this.iconScissors = new ImageIcon("C:\\Users\\name\\Pictures\\Game\\schere.png");
this.iconStone = new ImageIcon("C:\\Users\\name\\Pictures\\Game\\stein.png");
this.iconPaper = new ImageIcon("C:\\Users\\name\\Pictures\\Game\\papier.png");
}
private void ordneKomponenten() {
this.getContentPane().setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(4, 4, 4, 4);
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 20;
c.gridheight = 40;
this.getContentPane().add(labelBackground, c);
c.gridx = 4;
c.gridy = 4;
c.gridwidth = 6;
c.gridheight = 6;
this.getContentPane().add(labelScissors, c);
c.gridx = 8;
this.getContentPane().add(labelStone, c);
c.gridx = 16;
this.getContentPane().add(labelPaper, c);
c.gridx = 2;
c.gridy = 50;
c.gridwidth = 1;
c.gridheight = 1;
this.getContentPane().add(labelMessage, c);
}
public void start() {
this.setVisible(true);
}
}
Ich weiß nicht woran das Problem liegt? kennt jemand die Lösung, oder sieht jemand ein Fehler in meinem Code? Ich sitze an diesen Bildern nun schon seit 2 Tagen und finde die Lösung nicht, das demotiviert...
Danke!