Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import javax.imageio.ImageIO;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.Scanner;
- import java.util.Random;
- import java.util.TimerTask;
- import java.util.Timer;
- public class Poziomy extends JPanel implements ActionListener {
- public int czas = 1;
- public int time = 0;
- public BufferedImage tlo_lvl;
- public int m = 100;
- public int n = 200;
- public int j;
- JButton łatwy;
- JButton sredni;
- JButton trudny;
- Timer timer = new Timer();
- TimerTask odlicz = new odliczanie();
- public Poziomy(){
- setLayout(null);
- File zdj_lvl = new File("zdjecia/tlo_menu.png");
- try{ tlo_lvl = ImageIO.read(zdj_lvl); }
- catch(IOException e){ System.err.println("Blad odczytu obrazków"); }
- łatwy = new JButton("łatwy");
- sredni = new JButton("średni");
- trudny = new JButton("trudny");
- łatwy.addActionListener(this);
- sredni.addActionListener(this);
- trudny.addActionListener(this);
- łatwy.setBounds(320, 100, 300, 80 );
- sredni.setBounds(320, 300, 300, 80);
- trudny.setBounds(320, 500, 300, 80);
- add(łatwy);
- add(sredni);
- add(trudny);
- }
- public void actionPerformed(ActionEvent f){
- Object poziom = f.getSource();
- if(poziom == łatwy){
- przejscie(30);
- }
- else if(poziom == sredni){
- przejscie(20);
- }
- else if(poziom == trudny){
- przejscie(10);
- }
- }
- /*private void odliczanie(int czas){
- long czas_teraz = System.currentTimeMillis();
- while(czas >= 0){
- if(System.currentTimeMillis() - czas_teraz > 1000){
- System.out.println(czas--);
- czas_teraz= System.currentTimeMillis();
- }
- }
- System.out.println("Bam");
- }*/
- public class odliczanie extends TimerTask {
- //public int time = 0;
- public void run() {
- System.out.println("Timer ran" + ++time);
- Etap_1.jt.setText(String.valueOf(czas - time));
- if(time == czas) {
- odlicz.cancel();
- //Okno noweOkno_3 = new Okno(1024, 768);
- CardLayout CL_3 = (CardLayout) (Projekt.noweOkno.karty.getLayout());
- CL_3.show(Projekt.noweOkno.karty, "etap_3");
- }
- }
- }
- public void przejscie(int tiktak){
- czas = tiktak;
- timer.schedule(odlicz, 0, 1000);
- //Okno noweOkno_2 = new Okno(1024, 768);
- CardLayout CL_2 = (CardLayout) (Projekt.noweOkno.karty.getLayout());
- CL_2.show(Projekt.noweOkno.karty, "etap_1");
- }
- public void paintComponent(Graphics graphic) {
- Graphics2D g2d = (Graphics2D) graphic;
- g2d.drawImage(tlo_lvl, 0, 0, this);
- }
- public static Image wez_zdjecie(String nazwa_pliku)
- {
- return new ImageIcon(nazwa_pliku).getImage();
- }
- }
- /*Okno noweOkno_2 = new Okno(1024,768);
- CardLayout CL =(CardLayout)(noweOkno_2.karty.getLayout());
- CL.show(noweOkno_2.karty, "etap_1"); */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement