Guest User

Untitled

a guest
Nov 21st, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. import java.awt.EventQueue;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JButton;
  5. import javax.swing.JOptionPane;
  6.  
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.Color;
  10.  
  11.  
  12. public class NiceGui {
  13.  
  14. private JFrame frmSomegame;
  15.  
  16. /**
  17. * Launch the application.
  18. */
  19. public static void main(String[] args) {
  20. EventQueue.invokeLater(new Runnable() {
  21. public void run() {
  22. try {
  23. NiceGui window = new NiceGui();
  24. window.frmSomegame.setVisible(true);
  25. } catch (Exception e) {
  26. e.printStackTrace();
  27. }
  28. }
  29. });
  30. }
  31.  
  32. /**
  33. * Create the application.
  34. */
  35. public NiceGui() {
  36. initialize();
  37. }
  38.  
  39. /**
  40. * Initialize the contents of the frame.
  41. */
  42. private void initialize() {
  43. frmSomegame = new JFrame();
  44. frmSomegame.setTitle("SomeGame");
  45. frmSomegame.getContentPane().setBackground(Color.BLUE);
  46. frmSomegame.setBounds(100, 100, 450, 300);
  47. frmSomegame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  48. frmSomegame.getContentPane().setLayout(null);
  49.  
  50. JButton btnNewButton = new JButton("Play");
  51. btnNewButton.addActionListener(new ActionListener() {
  52. public void actionPerformed(ActionEvent arg0) {
  53. JOptionPane.showMessageDialog(null,"Hello!");
  54. }
  55. });
  56. btnNewButton.setBounds(28, 41, 133, 50);
  57. frmSomegame.getContentPane().add(btnNewButton);
  58.  
  59. JButton btnNewButton_1 = new JButton("Credit");
  60. btnNewButton_1.addActionListener(new ActionListener() {
  61. public void actionPerformed(ActionEvent arg0) {
  62. JOptionPane.showMessageDialog(null,"Created by Calvin");
  63. }
  64. });
  65. btnNewButton_1.setBounds(25, 142, 136, 50);
  66. frmSomegame.getContentPane().add(btnNewButton_1);
  67.  
  68. JButton btnNewButton_2 = new JButton("Quit");
  69. btnNewButton_2.addActionListener(new ActionListener() {
  70. public void actionPerformed(ActionEvent arg0) {
  71. int result = JOptionPane.showConfirmDialog(null,"Do you want to quit?","Are you sure?",JOptionPane.YES_NO_OPTION) ;
  72. if(result == JOptionPane.YES_OPTION) {
  73. System.exit(0) ;
  74. }
  75. }
  76. });
  77. btnNewButton_2.setBounds(249, 142, 156, 50);
  78. frmSomegame.getContentPane().add(btnNewButton_2);
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment