Guten Tag liebe Mitglieder,
Die einzige Frage, die ich habe ist, wie ich wenn ich beispielsweise 2 jLabels habe, eines davon quasi während einer möglichen Überlappung davor und das andere dahinter anzeigen lassen kann. Finde da irgendwie nichts zu. Hoffe mir kann jemand helfen, Danke.
Das Spielfeld soll hinter allen Feldern sein:
Die einzige Frage, die ich habe ist, wie ich wenn ich beispielsweise 2 jLabels habe, eines davon quasi während einer möglichen Überlappung davor und das andere dahinter anzeigen lassen kann. Finde da irgendwie nichts zu. Hoffe mir kann jemand helfen, Danke.
Das Spielfeld soll hinter allen Feldern sein:
Java:
public class Spieloberflaeche2 extends JFrame {
private JLabel jLabelSpielfeld = new JLabel();
private JButton bWuerfeln = new JButton();
private JLabel jLabelAugenzahl = new JLabel();
private JLabel Feld0 = new JLabel();
private JLabel Feld1 = new JLabel();
private JLabel Feld2 = new JLabel();
private JLabel Feld3 = new JLabel();
private JLabel Feld4 = new JLabel();
private JLabel Feld5 = new JLabel();
private JLabel Feld6 = new JLabel();
private JLabel Feld7 = new JLabel();
private JLabel Feld8 = new JLabel();
private JLabel Feld9 = new JLabel();
private JLabel Feld10 = new JLabel();
// Ende Attribute
public Spieloberflaeche2() {
// Frame-Initialisierung
super();
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int frameWidth = 1412;
int frameHeight = 1048;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
setTitle("Spieloberflaeche2");
setResizable(false);
Container cp = getContentPane();
cp.setLayout(null);
jLabelSpielfeld.setBounds(58, 22, 958, 960);
jLabelSpielfeld.setText("");
jLabelSpielfeld.setIcon(new ImageIcon("Spielfeld.png"));
jLabelSpielfeld.setVerticalAlignment(SwingConstants.BOTTOM);
jLabelSpielfeld.setVerticalTextPosition(SwingConstants.BOTTOM);
cp.add(jLabelSpielfeld);
bWuerfeln.setBounds(1192, 904, 193, 81);
bWuerfeln.setText("Würfeln");
bWuerfeln.setMargin(new Insets(2, 2, 2, 2));
bWuerfeln.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
bWuerfeln_ActionPerformed(evt);
}
});
bWuerfeln.setFont(new Font("Impact", Font.BOLD, 36));
bWuerfeln.setBorder(BorderFactory.createEtchedBorder(0, Color.BLACK, Color.BLACK));
bWuerfeln.setCursor(new Cursor(Cursor.HAND_CURSOR));
bWuerfeln.setBorderPainted(true);
cp.add(bWuerfeln);
jLabelAugenzahl.setBounds(1160, 664, 225, 225);
jLabelAugenzahl.setText("");
cp.add(jLabelAugenzahl);
cp.setBackground(new Color(0xC0C0C0));
setVisible(true);
Feld0.setBounds(864, 840, 145, 145);
Feld0.setText("");
Feld0.setIcon(new ImageIcon("TestBild.png"));
Feld0.setVisible(true);
cp.add(Feld0);
Feld1.setBounds(800, 840, 74, 145);
Feld1.setText("");
cp.add(Feld1);
Feld2.setBounds(728, 840, 74, 145);
Feld2.setText("");
cp.add(Feld2);
Feld3.setBounds(656, 840, 74, 145);
Feld3.setText("");
cp.add(Feld3);
Feld4.setBounds(584, 840, 74, 145);
Feld4.setText("");
cp.add(Feld4);
Feld5.setBounds(512, 840, 74, 145);
Feld5.setText("");
cp.add(Feld5);
Feld6.setBounds(440, 840, 74, 145);
Feld6.setText("");
cp.add(Feld6);
Feld7.setBounds(368, 840, 74, 145);
Feld7.setText("");
cp.add(Feld7);
Feld8.setBounds(296, 840, 74, 145);
Feld8.setText("");
cp.add(Feld8);
Feld8.setText("text");
cp.add(Feld8);
Feld9.setBounds(223, 840, 74, 145);
Feld9.setText("");
cp.add(Feld9);
Feld10.setBounds(72, 840, 145, 145);
Feld10.setText("");
cp.add(Feld10);
}
public static void main(String[] args) {
new Spieloberflaeche2();