public FenetrePrincipale(PlanSalle modele) { super(); this.modele = modele; this.setTitle(modele.getNom() + " - OSE"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.creerBarreMenus(); this.creerMenuContextuel(); JLayeredPane lp = new JLayeredPane(); lp.setPreferredSize( new Dimension( Parametres.NB_TRAVEES * Parametres.LARGEUR_TRAVEE, Parametres.NB_RANGEES * Parametres.HAUTEUR_RANGEE)); lePlan = new Plan(modele); lePlan.setBounds( 0, 0, Parametres.NB_TRAVEES * Parametres.LARGEUR_TRAVEE, Parametres.NB_RANGEES * Parametres.HAUTEUR_RANGEE); lp.add(lePlan, new Integer(0)); Container conteneur = this.getContentPane(); conteneur.setLayout(new FlowLayout()); conteneur.add(lp); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true); }
/** * This method adds the panels to the window and organises them using a GridBagLayout and a * JLayeredPane. */ private void populateFrame(Container frame) { frame.setLayout(new GridBagLayout()); GridBagConstraints layoutConstraints = new GridBagConstraints(); JLayeredPane dungeonArea = new JLayeredPane(); dungeonArea.setPreferredSize(new Dimension(448, 448)); dungeonArea.add(dungeonPanel, JLayeredPane.DEFAULT_LAYER); // the DungeonPanel is added underneath dungeonArea.add(dungeonPanelOverlay, JLayeredPane.PALETTE_LAYER); // the mostly transparent DungeonPanelOverlay is added on top in the same position layoutConstraints.gridx = 0; layoutConstraints.gridy = 0; layoutConstraints.gridwidth = 7; layoutConstraints.gridheight = 7; frame.add(dungeonArea, layoutConstraints); layoutConstraints.gridx = 7; layoutConstraints.gridwidth = 1; frame.add(serverSettings, layoutConstraints); layoutConstraints.gridx = 0; layoutConstraints.gridy = 7; layoutConstraints.gridwidth = 8; layoutConstraints.gridheight = 1; frame.add(chatPanel, layoutConstraints); }
public TestPanel(Player p) { super(); player = p; layeredPane.setPreferredSize(new Dimension(300, 300)); money = new JLabel("Money: $" + player.getMoney()); product = new JLabel("Product: " + player.getProduct()); risk = new JLabel("Risk: " + getRisk() + "%"); JButton buy = new JButton("Buy RV"); buy.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { buy(); } }); JButton sell = new JButton("Sell RV"); sell.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { sell(); } }); JButton collect = new JButton("Collect"); collect.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { collect(); } }); JButton cook = new JButton("cook"); cook.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { cook(); } }); layeredPane.add(money, new Integer(0)); money.setBounds(0, 0, 100, 20); layeredPane.add(product, new Integer(0)); product.setBounds(0, 20, 100, 20); layeredPane.add(risk, new Integer(0)); risk.setBounds(0, 40, 100, 20); layeredPane.add(buy, new Integer(0)); buy.setBounds(100, 0, 101, 30); layeredPane.add(sell, new Integer(0)); sell.setBounds(100, 30, 101, 30); layeredPane.add(collect, new Integer(0)); collect.setBounds(100, 60, 101, 30); layeredPane.add(cook, new Integer(0)); cook.setBounds(100, 90, 101, 30); add(layeredPane); (new Thread(new StartGame())).start(); }