martaczaska

Poziomy

Jan 4th, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.22 KB | None | 0 0
  1. package com.company;
  2. import javax.imageio.ImageIO;
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.image.BufferedImage;
  8. import java.io.File;
  9. import java.io.FileNotFoundException;
  10. import java.io.IOException;
  11. import java.util.Scanner;
  12. import java.util.Random;
  13.  
  14.  
  15. public class Poziomy extends JPanel implements ActionListener {
  16.         //public String litera = "";
  17.         public int czas = 1;
  18.  
  19.         public int m = 100;
  20.         public int n = 200;
  21.  
  22.         public int j;
  23.  
  24.         JButton łatwy;
  25.         JButton sredni;
  26.         JButton trudny;
  27.  
  28.        public Poziomy(){
  29.            //setLayout(new GridLayout(3, 1, 200, 200));
  30.            //int WIDTH = 200;
  31.            //int HEIGHT = 130;
  32.            setLayout(null);
  33.  
  34.            łatwy = new JButton("łatwy");
  35.            sredni = new JButton("średni");
  36.            trudny = new JButton("trudny");
  37.  
  38.            łatwy.addActionListener(this);
  39.            sredni.addActionListener(this);
  40.            trudny.addActionListener(this);
  41.  
  42.            łatwy.setBounds(320, 100, 300, 80 );
  43.            sredni.setBounds(320, 300, 300, 80);
  44.            trudny.setBounds(320, 500, 300, 80);
  45.  
  46.            //setPreferredSize(new Dimension(WIDTH, HEIGHT));
  47.            add(łatwy);
  48.            add(sredni);
  49.            add(trudny);
  50.  
  51.        }
  52.  
  53.         public void actionPerformed(ActionEvent f){
  54.             Object poziom = f.getSource();
  55.             if(poziom == łatwy){
  56.                 czas = 30;
  57.                 System.out.println("tutaj!");
  58.                 odliczanie(czas);
  59.                     while(czas != 0){
  60.                         //wyswietlanie();
  61.                     }
  62.             }
  63.             else if(poziom == sredni){
  64.                 czas = 20;
  65.                 odliczanie(czas);
  66.                     while(czas != 0){
  67.                         //wyswietlanie();
  68.                     }
  69.             }
  70.             else if(poziom == trudny){
  71.                 Okno noweOkno_2 = new Okno(1024,768);
  72.                 CardLayout CL_2 =(CardLayout)(noweOkno_2.karty.getLayout());
  73.                 CL_2.show(noweOkno_2.karty, "etap_1");
  74.  
  75.                 czas = 1; //na razie, normalnie czas =10
  76.                 odliczanie(czas);
  77.  
  78.                 if(czas != 0){
  79.                     //new Etap_1();
  80.                     //w pętli wyswietlanie i wpisywanie liter
  81.                 }
  82.                 else if(czas == 0){
  83.                     Okno noweOkno_3 = new Okno(1024,768);
  84.                     CardLayout CL_3 =(CardLayout)(noweOkno_3.karty.getLayout());
  85.                     CL_3.show(noweOkno_2.karty, "etap_3");
  86.                 }
  87.  
  88.             }
  89.         }
  90.  
  91.          private void odliczanie(int czas){
  92.             long czas_teraz = System.currentTimeMillis();
  93.             while(czas >= 0){
  94.                 if(System.currentTimeMillis() - czas_teraz > 1000){
  95.                     System.out.println(czas--);
  96.                     czas_teraz= System.currentTimeMillis();
  97.                 }
  98.             }
  99.             System.out.println("Bam");
  100.         }
  101.  
  102.  
  103.         public static Image wez_zdjecie(String nazwa_pliku)
  104.         {
  105.             return new ImageIcon(nazwa_pliku).getImage();
  106.         }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment