Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package flags;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9.  
  10. import javax.swing.Box;
  11. import javax.swing.ImageIcon;
  12. import javax.swing.JButton;
  13. import javax.swing.JFrame;
  14. import javax.swing.JLabel;
  15. import javax.swing.JPanel;
  16.  
  17. public class Game extends JPanel {
  18.    
  19.     private static final long serialVersionUID = 1L;
  20.  
  21.     public static void setGUI() {
  22.         JFrame start_screen = new JFrame("Flags App");
  23.         // Image is 400x400px
  24.         start_screen.add(new JLabel(new ImageIcon("res/rsz_planet_earth.jpg")), BorderLayout.NORTH);
  25.  
  26.         // JButtons
  27.         Box box = Box.createVerticalBox();
  28.         start_screen.getContentPane().add(box, BorderLayout.CENTER);
  29.        
  30.         JButton button = new JButton("Start");
  31.         button.setBackground(Color.green);
  32.        
  33.         JButton button2 = new JButton("Help");
  34.         button2.setBackground(Color.red);
  35.        
  36.         JButton button3 = new JButton("Info");
  37.         button3.setBackground(Color.cyan);
  38.        
  39.         button.setAlignmentX(Component.CENTER_ALIGNMENT);
  40.         button2.setAlignmentX(Component.CENTER_ALIGNMENT);
  41.         button3.setAlignmentX(Component.CENTER_ALIGNMENT);
  42.        
  43.         button.setPreferredSize(new Dimension(66,66));
  44.         button2.setPreferredSize(new Dimension(66,66));
  45.         button3.setPreferredSize(new Dimension(66,66));
  46.        
  47.         box.add(button);
  48.         box.add(button2);
  49.         box.add(button3);
  50.        
  51.         final int WIDTH = 400;
  52.         final int HEIGHT = 600;
  53.  
  54.         // Window
  55.         start_screen.setSize(new Dimension(WIDTH, HEIGHT));
  56.         start_screen.setLocationRelativeTo(null);
  57.         start_screen.setResizable(true);
  58.         start_screen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  59.         start_screen.setVisible(true);
  60.     }
  61.  
  62.     public static void main(String[] args) {
  63.         setGUI();
  64.     }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement