Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private class OptionsPanel extends JPanel{
- private Galaga parent;
- public OptionsPanel(Galaga p) {
- super();
- parent = p;
- //layout components however you wish
- setLayout(null);
- JButton backButton = new JButton("<< Back");
- backButton.setBounds(5, 20, 100, 20);
- backButton.setFont(new Font("Arial", Font.PLAIN, 15));
- backButton.setForeground(Color.white);
- backButton.setBackground(Color.black);
- backButton.setOpaque(true);
- backButton.setBorderPainted(false);
- backButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- parent.getLayeredPane().remove(parent.getOptionsPanel());
- parent.getLayeredPane().add(parent.getButtonPanel(), new Integer(10));
- parent.invalidate();
- }
- });
- add(backButton);
- JButton shipSelectButton = new JButton("Ship Selection");
- shipSelectButton.setBounds(10, 60, 200, 40);
- shipSelectButton.setFont(new Font("Arial", Font.PLAIN, 20));
- shipSelectButton.setForeground(Color.white);
- shipSelectButton.setBackground(Color.black);
- shipSelectButton.setOpaque(true);
- shipSelectButton.setBorderPainted(false);
- shipSelectButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- }
- });
- add(shipSelectButton);
- }
- }
- }
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.EventQueue;
- import java.awt.Font;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.GridLayout;
- import java.awt.Insets;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.UIManager;
- import javax.swing.UnsupportedLookAndFeelException;
- public class LayoutExamples {
- public static void main(String[] args) {
- new LayoutExamples();
- }
- public LayoutExamples() {
- EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
- }
- JFrame frame = new JFrame("Testing");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLayout(new GridLayout(0, 2));
- frame.add(new OptionsPanel());
- frame.add(new OtherPane());
- frame.pack();
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
- });
- }
- public class OtherPane extends JPanel {
- public OtherPane() {
- setBackground(Color.RED);
- }
- @Override
- public Dimension getPreferredSize() {
- return new Dimension(100, 200);
- }
- }
- public class OptionsPanel extends JPanel {
- public OptionsPanel() {
- super();
- //layout components however you wish
- setLayout(new GridBagLayout());
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.insets = new Insets(8, 8, 8, 8);
- gbc.anchor = GridBagConstraints.NORTHWEST;
- JButton backButton = new JButton("<< Back");
- backButton.setFont(new Font("Arial", Font.PLAIN, 15));
- backButton.setForeground(Color.white);
- backButton.setBackground(Color.black);
- backButton.setOpaque(true);
- backButton.setBorderPainted(false);
- backButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- }
- });
- add(backButton, gbc);
- JButton shipSelectButton = new JButton("Ship Selection");
- shipSelectButton.setFont(new Font("Arial", Font.PLAIN, 20));
- shipSelectButton.setForeground(Color.white);
- shipSelectButton.setBackground(Color.black);
- shipSelectButton.setOpaque(true);
- shipSelectButton.setBorderPainted(false);
- shipSelectButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- }
- });
- gbc.insets = new Insets(12, 8, 12, 12);
- gbc.gridx = 0;
- gbc.gridy = 1;
- gbc.anchor = GridBagConstraints.NORTHWEST;
- gbc.weighty = 1;
- gbc.weightx = 1;
- add(shipSelectButton, gbc);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement