Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package View;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- /**
- *
- * @author kovko
- */
- public class GUI extends JFrame{
- public static final int WIDTH = 1080;
- public static final int HEIGHT = 800;
- public static final int BUTTON_OFFSET = 10;
- public static final int BUTTON_HEIGHT = 20;
- public static final int BUTTON_WIDTH = 120;
- private JPanel menuDefault;
- private JPanel menuSetFocus;
- private JButton switchToSetFocusMenu;
- private JButton switchToDefaultMenu;
- private JButton tankDriverFocusSetter;
- private JButton tankGunnerFocusSetter;
- public GUI(Surface surface){
- add(surface);
- setTitle("Warsong Tank Edition");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setSize(WIDTH, HEIGHT);
- setMenus();
- add(menuDefault);
- }
- private void setMenus(){
- menuDefault = new JPanel();
- menuDefault.setBounds(HEIGHT, 0, WIDTH-HEIGHT, HEIGHT);
- menuDefault.setLayout(null);
- setDefaultMenuButtons();
- menuSetFocus = new JPanel();
- menuSetFocus.setBounds(HEIGHT, 0, WIDTH-HEIGHT, HEIGHT);
- menuSetFocus.setLayout(null);
- setSetFocusMenuButton();
- }
- private void switchMenus(JPanel toActivate, JPanel toDeactivate){
- remove(toDeactivate);
- add(toActivate);
- revalidate();
- repaint();
- }
- private JButton createButton(String name, JPanel parent){
- JButton button = new JButton(name);
- int x = parent.getBounds().x + (BUTTON_WIDTH*(parent.getComponentCount()%2))+(BUTTON_OFFSET*(parent.getComponentCount()%2));
- int y = parent.getBounds().y + (BUTTON_HEIGHT*(parent.getComponentCount()/2))+(BUTTON_OFFSET*(parent.getComponentCount()/2));
- button.setBounds(x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
- parent.add(button);
- return button;
- }
- private void setDefaultMenuButtons(){
- switchToSetFocusMenu = createButton("Vybrat tank", menuDefault);
- switchToSetFocusMenu.addActionListener(e->{switchMenus(menuSetFocus, menuDefault);});
- };
- private void setSetFocusMenuButton(){
- switchToDefaultMenu = createButton("Spat", menuSetFocus);
- switchToDefaultMenu.addActionListener(e->{switchMenus(menuDefault, menuSetFocus);});
- tankDriverFocusSetter = createButton("Vodic", menuSetFocus);
- tankDriverFocusSetter.addActionListener(e->{switchMenus(menuDefault, menuSetFocus);});
- tankGunnerFocusSetter = createButton("Strelec", menuSetFocus);
- tankGunnerFocusSetter.addActionListener(e->{switchMenus(menuDefault, menuSetFocus);});
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement