Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Button;
- import java.awt.Dialog;
- import java.awt.Frame;
- import java.awt.Label;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.util.Random;
- public class Bomb {
- public static final String NAME = "爆弾カウントダウン";
- private Frame window;
- private Dialog dialog;
- private int count;
- private int turn;
- public Bomb() {
- init_and_run();
- }
- private void init_and_run() {
- Random r = new Random();
- count = r.nextInt(30) + 1;
- turn = 0;
- window = new Frame(NAME);
- window.setIgnoreRepaint(true);
- window.setResizable(true);
- window.add(new Label("カウントを進めてください"));
- Button b;
- window.add(b = new Button(" −1 "), BorderLayout.WEST);
- b.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- turn++;
- window.add(new Label("" + turn + "回"));
- decrease_count();
- }
- });
- window.add(b = new Button(" −2 "), BorderLayout.EAST);
- b.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- turn++;
- decrease_count();
- decrease_count();
- }
- });
- window.add(b = new Button("Exit"), BorderLayout.SOUTH);
- b.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- quit();
- }
- });
- window.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- quit();
- }
- });
- window.pack();
- window.setVisible(true);
- window.requestFocus();
- }
- private void decrease_count() {
- count--;
- if (count < 0) bomb();
- }
- private void bomb() {
- dialog = new Dialog(window, "BOMB!", true);
- dialog.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- quit();
- dialog_quit();
- }
- });
- Button b;
- dialog.add(b = new Button("Exit"), BorderLayout.CENTER);
- b.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- quit();
- dialog_quit();
- }
- });
- dialog.add(new Label("BOOOOMB!!!!! " + turn + " 回"), BorderLayout.NORTH);
- dialog.pack();
- dialog.setVisible(true);
- }
- public void quit() {
- window.setVisible(false);
- window.dispose();
- }
- public void dialog_quit() {
- dialog.setVisible(false);
- dialog.dispose();
- }
- public static void main(String[] args) {
- Bomb b = new Bomb();
- b.quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement