martaczaska

lvl

Jan 4th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.93 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 int czas = 1;
  17.     public BufferedImage tlo_lvl;
  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(null);
  30.  
  31.         File zdj_lvl = new File("zdjecia/tlo_menu.png");
  32.         try{ tlo_lvl = ImageIO.read(zdj_lvl); }
  33.         catch(IOException e){ System.err.println("Blad odczytu obrazków"); }
  34.  
  35.         łatwy = new JButton("łatwy");
  36.         sredni = new JButton("średni");
  37.         trudny = new JButton("trudny");
  38.  
  39.         łatwy.addActionListener(this);
  40.         sredni.addActionListener(this);
  41.         trudny.addActionListener(this);
  42.  
  43.         łatwy.setBounds(320, 100, 300, 80 );
  44.         sredni.setBounds(320, 300, 300, 80);
  45.         trudny.setBounds(320, 500, 300, 80);
  46.  
  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.                 //w pętli wyswietlanie i wpisywanie liter
  80.             }
  81.             else if(czas == 0){
  82.                 Okno noweOkno_3 = new Okno(1024,768);
  83.                 CardLayout CL_3 =(CardLayout)(noweOkno_3.karty.getLayout());
  84.                 CL_3.show(noweOkno_2.karty, "etap_3");
  85.             }
  86.  
  87.         }
  88.     }
  89.  
  90.     private void odliczanie(int czas){
  91.         long czas_teraz = System.currentTimeMillis();
  92.         while(czas >= 0){
  93.             if(System.currentTimeMillis() - czas_teraz > 1000){
  94.                 System.out.println(czas--);
  95.                 czas_teraz= System.currentTimeMillis();
  96.             }
  97.         }
  98.         System.out.println("Bam");
  99.     }
  100.  
  101.     public void paintComponent(Graphics graphic) {
  102.         Graphics2D g2d = (Graphics2D) graphic;
  103.         g2d.drawImage(tlo_lvl, 0, 0, this);
  104.     }
Advertisement
Add Comment
Please, Sign In to add comment