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;
- public class Poziomy extends JPanel implements ActionListener {
- public int czas = 1;
- public BufferedImage tlo_lvl;
- public int m = 100;
- public int n = 200;
- public int j;
- JButton łatwy;
- JButton sredni;
- JButton trudny;
- 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){
- czas = 30;
- System.out.println("tutaj!");
- odliczanie(czas);
- while(czas != 0){
- //wyswietlanie();
- }
- }
- else if(poziom == sredni){
- czas = 20;
- odliczanie(czas);
- while(czas != 0){
- //wyswietlanie();
- }
- }
- else if(poziom == trudny){
- Okno noweOkno_2 = new Okno(1024,768);
- CardLayout CL_2 =(CardLayout)(noweOkno_2.karty.getLayout());
- CL_2.show(noweOkno_2.karty, "etap_1");
- czas = 1; //na razie, normalnie czas =10
- odliczanie(czas);
- if(czas != 0){
- //w pętli wyswietlanie i wpisywanie liter
- }
- else if(czas == 0){
- Okno noweOkno_3 = new Okno(1024,768);
- CardLayout CL_3 =(CardLayout)(noweOkno_3.karty.getLayout());
- CL_3.show(noweOkno_2.karty, "etap_3");
- }
- }
- }
- 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 void paintComponent(Graphics graphic) {
- Graphics2D g2d = (Graphics2D) graphic;
- g2d.drawImage(tlo_lvl, 0, 0, this);
- }
Advertisement
Add Comment
Please, Sign In to add comment