Advertisement
Vedro

Marta2_Poziomy

Jan 5th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.25 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. import java.util.TimerTask;
  14. import java.util.Timer;
  15.  
  16.  
  17. public class Poziomy extends JPanel implements ActionListener {
  18.     public int czas = 1;
  19.     public int time = 0;
  20.     public BufferedImage tlo_lvl;
  21.  
  22.     public int m = 100;
  23.     public int n = 200;
  24.  
  25.     public int j;
  26.  
  27.     JButton łatwy;
  28.     JButton sredni;
  29.     JButton trudny;
  30.  
  31.     Timer timer = new Timer();
  32.     TimerTask odlicz = new odliczanie();
  33.  
  34.     public Poziomy(){
  35.         setLayout(null);
  36.  
  37.         File zdj_lvl = new File("zdjecia/tlo_menu.png");
  38.         try{ tlo_lvl = ImageIO.read(zdj_lvl); }
  39.         catch(IOException e){ System.err.println("Blad odczytu obrazków"); }
  40.  
  41.         łatwy = new JButton("łatwy");
  42.         sredni = new JButton("średni");
  43.         trudny = new JButton("trudny");
  44.  
  45.         łatwy.addActionListener(this);
  46.         sredni.addActionListener(this);
  47.         trudny.addActionListener(this);
  48.  
  49.         łatwy.setBounds(320, 100, 300, 80 );
  50.         sredni.setBounds(320, 300, 300, 80);
  51.         trudny.setBounds(320, 500, 300, 80);
  52.  
  53.         add(łatwy);
  54.         add(sredni);
  55.         add(trudny);
  56.  
  57.     }
  58.  
  59.     public void actionPerformed(ActionEvent f){
  60.         Object poziom = f.getSource();
  61.         if(poziom == łatwy){
  62.             przejscie(30);
  63.         }
  64.         else if(poziom == sredni){
  65.             przejscie(20);
  66.         }
  67.         else if(poziom == trudny){
  68.             przejscie(10);
  69.  
  70.         }
  71.     }
  72.  
  73.     /*private void odliczanie(int czas){
  74.         long czas_teraz = System.currentTimeMillis();
  75.         while(czas >= 0){
  76.             if(System.currentTimeMillis() - czas_teraz > 1000){
  77.                 System.out.println(czas--);
  78.                 czas_teraz= System.currentTimeMillis();
  79.             }
  80.         }
  81.         System.out.println("Bam");
  82.     }*/
  83.  
  84.     public class odliczanie extends TimerTask {
  85.         //public int time = 0;
  86.  
  87.         public void run() {
  88.             System.out.println("Timer ran" + ++time);
  89.             Etap_1.jt.setText(String.valueOf(czas - time));
  90.                 if(time == czas) {
  91.                 odlicz.cancel();
  92.                 //Okno noweOkno_3 = new Okno(1024, 768);
  93.                CardLayout CL_3 = (CardLayout) (Projekt.noweOkno.karty.getLayout());
  94.                CL_3.show(Projekt.noweOkno.karty, "etap_3");
  95.             }
  96.  
  97.         }
  98.     }
  99.  
  100.     public void przejscie(int tiktak){
  101.         czas = tiktak;
  102.         timer.schedule(odlicz, 0, 1000);
  103.         //Okno noweOkno_2 = new Okno(1024, 768);
  104.         CardLayout CL_2 = (CardLayout) (Projekt.noweOkno.karty.getLayout());
  105.         CL_2.show(Projekt.noweOkno.karty, "etap_1");
  106.     }
  107.  
  108.     public void paintComponent(Graphics graphic) {
  109.         Graphics2D g2d = (Graphics2D) graphic;
  110.         g2d.drawImage(tlo_lvl, 0, 0, this);
  111.     }
  112.  
  113.     public static Image wez_zdjecie(String nazwa_pliku)
  114.     {
  115.         return new ImageIcon(nazwa_pliku).getImage();
  116.     }
  117. }
  118.  
  119.     /*Okno noweOkno_2 = new Okno(1024,768);
  120.     CardLayout CL =(CardLayout)(noweOkno_2.karty.getLayout());
  121.     CL.show(noweOkno_2.karty, "etap_1"); */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement