martaczaska

Menu_2

Jan 2nd, 2020
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. package com.company;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import javax.swing.*;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import javax.swing.JButton;
  10. import javax.swing.JPanel;
  11.  
  12. public class Menu extends JPanel implements ActionListener{
  13.  
  14.         private JButton instrukcja;
  15.         private JButton start;
  16.         private JButton wyjscie;
  17.  
  18.         private JButton łatwy;
  19.         private JButton średni;
  20.         private JButton trudny;
  21.  
  22.         int w = 1024;
  23.         int h = 768;
  24.         int time = 1;
  25.  
  26.         public Menu(int w_okno, int h_okno){
  27.             setLayout(new GridLayout(3, 1,200, 200));
  28.  
  29.             int WIDTH = 200;
  30.             int HEIGHT = 130;
  31.  
  32.             instrukcja = new JButton("Instrukcja");
  33.             start = new JButton("Start");
  34.             wyjscie = new JButton("Wyjście");
  35.  
  36.             instrukcja.addActionListener(this);
  37.             start.addActionListener(this);
  38.             wyjscie.addActionListener(this);
  39.  
  40.             setPreferredSize(new Dimension(WIDTH, HEIGHT));
  41.             add(instrukcja);
  42.             add(start);
  43.             add(wyjscie);
  44.         }
  45.  
  46.         public void poziomy(){
  47.             setLayout(new GridLayout(3, 1, 200, 200));
  48.  
  49.             łatwy = new JButton("łatwy");
  50.             średni = new JButton("średni");
  51.             trudny = new JButton("trudny");
  52.  
  53.             łatwy.addActionListener(this);
  54.             średni.addActionListener(this);
  55.             trudny.addActionListener(this);
  56.  
  57.             setPreferredSize(new Dimension(WIDTH, HEIGHT));
  58.             add(łatwy);
  59.             add(średni);
  60.             add(trudny);
  61.         }
  62.  
  63.         public void actionPerformed_2(ActionEvent f){
  64.             Object poziom = f.getSource();
  65.             String s = poziom.toString();
  66.             when(s = "łatwy"){
  67.                
  68.             }
  69.         }
  70.  
  71.         public void actionPerformed(ActionEvent e){
  72.             Object source = e.getSource();
  73.  
  74.             if(source == instrukcja) {
  75.  
  76.                 JOptionPane.showMessageDialog(null, "Tutaj będzie cała instrukcja do grania");   //DZIAŁA, NAJS
  77.  
  78.             }
  79.  
  80.             else if(source == start) {
  81.  
  82.                 poziomy();
  83.                 actionPerformed_2(ActionEvent g);
  84.  
  85.                     if (time != 0) {
  86.                         add(new etap_1(w, h));
  87.  
  88.                         long czas = System.currentTimeMillis();
  89.                         int i = 5;
  90.  
  91.                         while (i >= 0) {
  92.                             if (System.currentTimeMillis() - czas > 1000) {
  93.                                 System.out.println(i--);
  94.                                 czas = System.currentTimeMillis();
  95.                             }
  96.                         }
  97.                         time = 0;
  98.                         System.out.println("Bam");
  99.                     }
  100.                     else if(time == 0){
  101.                         //
  102.                     }
  103.  
  104.             }
  105.  
  106.             else if(source == wyjscie){
  107.                 //frame.dispose();
  108.                 System.exit(0);    //DZIAŁA, NAJS
  109.             }
  110.  
  111.         }
  112.  
  113.         //setVisible(true);
  114.  
  115.     }
Advertisement
Add Comment
Please, Sign In to add comment