Advertisement
LoanHoang

Untitled

Dec 15th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.awt.event.WindowEvent;
  5. import java.awt.event.WindowListener;
  6.  
  7. /**
  8. * Created by LENOVO on 12/15/2017.
  9. */
  10. public class StartGame {
  11. public static void main(String[] args) {
  12. // set attr for frame
  13. final JFrame frame = new JFrame("Siri đoán số");
  14. frame.setSize(300, 200);
  15. frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  16. frame.setLocationRelativeTo(null);
  17. frame.setLayout(null);
  18. frame.setResizable(false);
  19. frame.addWindowListener(new WindowListener() {
  20.  
  21. public void windowOpened(WindowEvent e) {
  22. }
  23.  
  24. public void windowClosing(WindowEvent e) {
  25. int option = JOptionPane.showConfirmDialog(null, "Bạn muốn thoát khỏi trò chơi?", "Đóng?", JOptionPane.YES_NO_OPTION);
  26. if (option == JOptionPane.YES_OPTION) {
  27. System.exit(0);
  28. } else {
  29.  
  30. }
  31. }
  32.  
  33. public void windowClosed(WindowEvent e) {
  34. }
  35.  
  36. public void windowIconified(WindowEvent e) {
  37. }
  38.  
  39. public void windowDeiconified(WindowEvent e) {
  40. }
  41.  
  42. public void windowActivated(WindowEvent e) {
  43. }
  44.  
  45. public void windowDeactivated(WindowEvent e) {
  46. }
  47. });
  48. // create two button start and help
  49. JButton btn_start = new JButton("Start");
  50. JButton btn_help = new JButton("Help");
  51. // set bounds
  52. btn_start.setBounds(100, 50, 100, 20);
  53. btn_help.setBounds(100, 80, 100, 20);
  54. // add listener for btn
  55. btn_start.addActionListener(new ActionListener() {
  56.  
  57. public void actionPerformed(ActionEvent e) {
  58. int option = JOptionPane.showConfirmDialog(null, "Bạn đã sẵn sàng?", "Siri đoán số", JOptionPane.YES_NO_OPTION);
  59. if (option == JOptionPane.YES_OPTION) {
  60. frame.setVisible(false);
  61. Game.start();
  62. } else {
  63.  
  64. }
  65.  
  66. }
  67. });
  68. btn_help.addActionListener(new ActionListener() {
  69. @Override
  70. public void actionPerformed(ActionEvent e) {
  71. JOptionPane.showMessageDialog(null, " Bạn chọn 1 số " +
  72. "\n trong khoảng 1-100 sau đó ấn nút Start. " +
  73. "\n Siri sẽ đoán số của bạn với tối đa 10 lần. " +
  74. "\n Sau đó Siri sẽ đưa ra kết quả đoán của Siri " +
  75. "\n để so sánh với số của bạn. " +
  76. "\n Bạn chọn 1 trong 3 ô tương ứng để giúp Siri so sánh kết quả. " +
  77. "\n Trò chơi kết thúc sau tối đa 10 lần đoán của Siri " +
  78. "\n Nếu trong 10 lần đoán, Siri đoán trúng thì Siri thắng " +
  79. "\n Nếu sau 10 lần Siri không đoán được thì Siri thua. " +
  80. "\n Trò chơi kết thúc " +
  81. JOptionPane.INFORMATION_MESSAGE);
  82. }
  83. });
  84. // add to frame
  85. frame.add(btn_start);
  86. frame.add(btn_help);
  87. // set visible
  88. frame.setVisible(true);
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement