Hallo,
in versuche einen CookieClicker zu programmieren. Da schaffe ich es allerdings nicht so, wie ich mir das vorstellle die Komponenten anzuordnen. Hier der Code:
Eigentlich will ich die Komponenten so haben, am roten "PUNKT" wird die gewünschte Stelle der jeweiligen Komponenten verdeutlicht:
Ich hoffe ihr könnt mir weiterhelfen. Danke im vorraus.
in versuche einen CookieClicker zu programmieren. Da schaffe ich es allerdings nicht so, wie ich mir das vorstellle die Komponenten anzuordnen. Hier der Code:
Java:
public class CookieClickerGUI extends JFrame {
public CookieClickerGUI() {
super("Cookie Clicker");
this.setLocation(300, 150);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.initialisiereKomponenten();
this.ordneKomponenentenInJPanelOverlay();
this.ordneKomponenentenInPanelCookie();
this.ordneKomponenentenInPanelCookieShop();
this.setSize(820, 500);
}
private JPanelOverlay panelOverlay;
private JPanel panelCookie;
private JPanel panelAnzeige;
private JPanel panelCookieShop;
private ImageIcon iconCookie;
private JLabel labelCookie;
private JLabel labelAnzahlCookies;
private JLabel labelCookiesProKlick;
private JLabel labelCookieShop;
//Layouts
private BorderLayout borderLayoutCookie;
private BorderLayout borderLayoutCookieShop;
private FlowLayout flowLayoutCookieWerte;
private void initialisiereKomponenten() {
this.iconCookie = new ImageIcon("images/CookieClickerCookie.png");
this.panelOverlay = new JPanelOverlay();
this.panelOverlay.setOpaque(false);
this.panelCookie = new JPanel();
this.panelCookie.setOpaque(false);
this.panelAnzeige = new JPanel();
this.panelAnzeige.setOpaque(false);
this.panelCookieShop = new JPanel();
this.panelCookieShop.setOpaque(false);
this.labelCookie = new JLabel(this.iconCookie);
this.labelCookie.setOpaque(false);
this.labelAnzahlCookies = new JLabel("0");
this.labelAnzahlCookies.setOpaque(false);
this.labelCookiesProKlick = new JLabel("1");
this.labelCookiesProKlick.setOpaque(false);
this.labelCookieShop = new JLabel("Cookie Shop");
this.labelCookieShop.setOpaque(false);
//Layouts initialization
this.borderLayoutCookie = new BorderLayout();
this.borderLayoutCookieShop = new BorderLayout();
this.flowLayoutCookieWerte = new FlowLayout();
}
private void ordneKomponenentenInPanelCookie() {
this.panelAnzeige.setLayout(flowLayoutCookieWerte);
flowLayoutCookieWerte.setHgap(150);
flowLayoutCookieWerte.setVgap(10);
this.panelAnzeige.add(this.labelCookiesProKlick);
this.panelAnzeige.add(this.labelAnzahlCookies);
this.panelCookie.setLayout(borderLayoutCookie);
borderLayoutCookie.setHgap(200);
borderLayoutCookie.setVgap(150);
this.panelCookie.add(this.labelCookie, BorderLayout.CENTER);
this.panelCookie.add(this.panelAnzeige, BorderLayout.NORTH);
}
private void ordneKomponenentenInJPanelOverlay() {
this.panelOverlay.setLayout((new GridBagLayout()));
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(5, 5, 5, 5);
c.weightx = 1;
c.weighty = 1;
c.gridx = 0;
c.gridy = 0;
this.panelOverlay.add(this.panelCookie, c);
c.gridx = 1;
this.panelOverlay.add(this.panelCookieShop, c);
this.getContentPane().add(this.panelOverlay);
}
private void ordneKomponenentenInPanelCookieShop() {
this.panelCookieShop.setLayout(borderLayoutCookieShop);
borderLayoutCookieShop.setHgap(300);
borderLayoutCookieShop.setVgap(343);
this.panelCookieShop.add(labelCookieShop, BorderLayout.NORTH);
this.panelCookieShop.add(new JLabel("Auswähloptionen"), BorderLayout.CENTER);
}
public void start() {
this.setVisible(true);
}
}
Ich hoffe ihr könnt mir weiterhelfen. Danke im vorraus.