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.ActionListener;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import java.util.Random;
- import java.util.Scanner;
- import java.util.concurrent.Flow;
- import java.util.ArrayList;
- import java.awt.List;
- import java.awt.event.KeyAdapter;
- public class Etap_1 extends JPanel{
- public static Image[]kolo;
- public String[] litery = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "R", "S", "T", "U", "W", "Y", "Z"}; //(23 ale od 0 do 22)
- static public String wybrana_zol = "";
- public String wybrana_kolor = "";
- public BufferedImage image_1;
- public BufferedImage image_2;
- public BufferedImage kolo_1;
- public BufferedImage kolo_2;
- public BufferedImage tlo_1;
- static JLabel label_timer = new JLabel();
- static ArrayList<String> lista = new ArrayList<String>(); // RISKY SHIT
- static JTextField jt = new JTextField();
- static boolean czy_wpisane = false;
- static StringBuilder sB = new StringBuilder();//1:57
- static String sklejka ="";
- public Etap_1(){
- setLayout(null);
- Random losowa = new Random();
- int polozenie = losowa.nextInt(2);
- int nr_litery_1 = losowa.nextInt(22);
- int nr_litery_2 = losowa.nextInt(22);
- wybrana_zol = litery[nr_litery_1];
- wybrana_kolor = litery[nr_litery_2];
- File zdjecie_1 = new File("zdjecia/zolte/" + wybrana_zol + ".png");
- File zdjecie_2 = new File("zdjecia/kolorowe/" + wybrana_kolor + ".png");
- File zdjecie_3 = new File("zdjecia/tlo_GRA_1.png");
- try{
- image_1 = ImageIO.read(zdjecie_1);
- image_2 = ImageIO.read(zdjecie_2);
- tlo_1 = ImageIO.read(zdjecie_3);
- }
- catch(IOException e){
- System.err.println("Blad odczytu obrazków");
- }
- if(polozenie == 0){
- kolo_1 = image_1;
- kolo_2 = image_2;
- }
- else if(polozenie == 1){
- kolo_1 = image_2;
- kolo_2 = image_1;
- }
- //JTextField jt = new JTextField();
- jt.setBounds(320, 650, 370, 70);
- add(jt);
- label_timer.setBounds(800, 85, 220, 50);
- label_timer.setFont(new Font("Cambria", Font.BOLD, 35));
- add(label_timer);
- jt.addKeyListener(new KeyAdapter(){
- public void keyPressed(KeyEvent pr){
- if (pr.getKeyCode() == KeyEvent.VK_ENTER) {
- if (jt.getText().equals(wybrana_zol)) {
- lista.add(wybrana_zol);
- sB.append(wybrana_zol);
- sB.append(" ");
- czy_wpisane = true;
- jt.setText("");
- /*jt.setCaretPosition(0);
- int caretPosition = jt.getCaretPosition();
- jt.setCaretPosition(caretPosition);*/
- Okno.karty.add((new Etap_1()), "etap_1");
- CardLayout CL_2 = (CardLayout) (Projekt.noweOkno.karty.getLayout());
- CL_2.show(Projekt.noweOkno.karty, "etap_1");
- } else {
- jt.setText("");
- //System.out.println("Wpisałeś złą literę");
- }
- }
- }
- });
- sklejka = sB.toString();
- System.out.println(sklejka);
- }
- public void paintComponent(Graphics graphic) {
- Graphics2D g2d = (Graphics2D) graphic;
- g2d.drawImage(tlo_1, 0, 0, this);
- g2d.drawImage(kolo_1, 100, 180, this);
- g2d.drawImage(kolo_2, 600, 180, this);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment