Advertisement
Guest User

JButton Help

a guest
Jan 20th, 2013
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. public class MainMenu extends JFrame {
  2.  
  3. private JPanel contentPane;
  4.  
  5. /**
  6. * Launch the application.
  7. */
  8.  
  9. //variables
  10. public static Image bg;
  11.  
  12. public static void main(String[] args) {
  13.  
  14. MainMenu mainFrame = new MainMenu();
  15. mainFrame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
  16. mainFrame.setResizable(false);
  17. mainFrame.setLocationRelativeTo(null);
  18. mainFrame.setTitle ("Zumby");
  19. mainFrame.setLayout(null);
  20.  
  21. // Loads the background image and stores in bg object.
  22. try {
  23. bg = ImageIO.read(new File("zumby.png"));
  24. } catch (IOException e) {
  25. }
  26. mainFrame.setVisible(true);
  27. }
  28.  
  29.  
  30. /**
  31. * Overrides the paint method.
  32. * MONDAY
  33. */
  34. public void paint(Graphics g)
  35. {
  36. // Draws the img to the BackgroundPanel.
  37. System.out.println("paint");
  38. g.drawImage(bg, 0, 0, null);
  39. }
  40.  
  41. /**
  42. */
  43. public MainMenu() {
  44. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  45. setBounds(100, 100, 800, 500);
  46. contentPane = new JPanel();
  47. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  48. contentPane.setOpaque(false);
  49. setContentPane(contentPane);
  50. contentPane.setLayout(null);
  51.  
  52. //create buttons
  53. JButton btnPlay = new JButton("PLAY");
  54. btnPlay.setBackground(Color.BLACK);
  55. btnPlay.setForeground(Color.WHITE);
  56. btnPlay.setFont(font);
  57. btnPlay.setBorder(border);
  58. btnPlay.setFocusPainted(false);
  59.  
  60. //if "Play" is clicked
  61.  
  62. btnPlay.addActionListener(new ActionListener() {
  63. public void actionPerformed(ActionEvent click) {
  64. setVisible(false);
  65. new GamePlay(); //opens up GamePlay window
  66. }
  67. });
  68. btnPlay.setBounds(600, 64, 141, 61);
  69. contentPane.add(btnPlay);
  70.  
  71. JButton btnInstructions = new JButton("INSTRUCTIONS");
  72.  
  73. btnInstructions.setBounds(600, 160, 141, 61);
  74. btnInstructions.setBackground(Color.BLACK);
  75. btnInstructions.setFocusPainted(false);
  76. // btnInstructions.setEnabled(true);
  77.  
  78. contentPane.add(btnInstructions);
  79. repaint();
  80. pack();
  81. setVisible(true);
  82.  
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement