Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowEvent;
- import java.awt.event.WindowListener;
- /**
- * Created by LENOVO on 12/15/2017.
- */
- public class StartGame {
- public static void main(String[] args) {
- // set attr for frame
- final JFrame frame = new JFrame("Siri đoán số");
- frame.setSize(300, 200);
- frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- frame.setLayout(null);
- frame.setResizable(false);
- frame.addWindowListener(new WindowListener() {
- public void windowOpened(WindowEvent e) {
- }
- public void windowClosing(WindowEvent e) {
- int option = JOptionPane.showConfirmDialog(null, "Bạn muốn thoát khỏi trò chơi?", "Đóng?", JOptionPane.YES_NO_OPTION);
- if (option == JOptionPane.YES_OPTION) {
- System.exit(0);
- } else {
- }
- }
- public void windowClosed(WindowEvent e) {
- }
- public void windowIconified(WindowEvent e) {
- }
- public void windowDeiconified(WindowEvent e) {
- }
- public void windowActivated(WindowEvent e) {
- }
- public void windowDeactivated(WindowEvent e) {
- }
- });
- // create two button start and help
- JButton btn_start = new JButton("Start");
- JButton btn_help = new JButton("Help");
- // set bounds
- btn_start.setBounds(100, 50, 100, 20);
- btn_help.setBounds(100, 80, 100, 20);
- // add listener for btn
- btn_start.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int option = JOptionPane.showConfirmDialog(null, "Bạn đã sẵn sàng?", "Siri đoán số", JOptionPane.YES_NO_OPTION);
- if (option == JOptionPane.YES_OPTION) {
- frame.setVisible(false);
- Game.start();
- } else {
- }
- }
- });
- btn_help.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- JOptionPane.showMessageDialog(null, " Bạn chọn 1 số " +
- "\n trong khoảng 1-100 sau đó ấn nút Start. " +
- "\n Siri sẽ đoán số của bạn với tối đa 10 lần. " +
- "\n Sau đó Siri sẽ đưa ra kết quả đoán của Siri " +
- "\n để so sánh với số của bạn. " +
- "\n Bạn chọn 1 trong 3 ô tương ứng để giúp Siri so sánh kết quả. " +
- "\n Trò chơi kết thúc sau tối đa 10 lần đoán của Siri " +
- "\n Nếu trong 10 lần đoán, Siri đoán trúng thì Siri thắng " +
- "\n Nếu sau 10 lần Siri không đoán được thì Siri thua. " +
- "\n Trò chơi kết thúc " +
- JOptionPane.INFORMATION_MESSAGE);
- }
- });
- // add to frame
- frame.add(btn_start);
- frame.add(btn_help);
- // set visible
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement