martaczaska

Etap_3

Jan 5th, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1. package com.company;
  2.  
  3. import javax.imageio.ImageIO;
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.image.BufferedImage;
  7. import java.io.File;
  8. import java.io.FileNotFoundException;
  9. import java.io.IOException;
  10. import java.util.Scanner;
  11. import java.util.ArrayList;
  12.  
  13. public class Etap_3 extends JPanel{
  14.  
  15.     float time = 100;
  16.     static int suma_pkt = 0;
  17.  
  18.     public BufferedImage tlo_3;
  19.     static JLabel label_zebrane = new JLabel();
  20.     public String sklejone = "";
  21.     public String spacja = " ";
  22.  
  23.     static JTextField jt_pole = new JTextField();
  24.  
  25.     public Etap_3(){
  26.         setLayout(null);
  27.  
  28.         File zdjecie_tlo = new File("zdjecia/tlo_GRA_3.png");
  29.  
  30.         try{ tlo_3 = ImageIO.read(zdjecie_tlo); }
  31.         catch(IOException e){ System.err.println("Blad odczytu obrazków"); }
  32.  
  33.         JTextField jt_timer = new JTextField();
  34.         jt_timer.setBounds(320, 650, 370, 70);
  35.         add(jt_timer);
  36.  
  37.         jt_pole.setBounds(320, 650, 370, 70);
  38.         add(jt_pole);
  39.  
  40.         System.out.println("Jestem już na 3 etapie!");
  41.  
  42.         //label_zebrane.setBounds(340, 200, 400, 50);
  43.  
  44.         //String s = Etap_1.lista.toString();
  45.  
  46.         //label_zebrane.setText(String.valueOf(Etap_1.lista));
  47.  
  48.         sklejone = Etap_1.sklejka;
  49.         label_zebrane.setText(sklejone);
  50.  
  51.         add(label_zebrane);
  52.  
  53.  
  54.        
  55.  
  56.     }
  57.  
  58.  
  59.  
  60.     public static void sprawdzanie(){                 // fragment napisany do prezentacji na moodla, ZAMIENIĆ SKAN NA WPISYWANIE DO JTEXTFIELD
  61.         Scanner skan = new Scanner (System.in);
  62.         System.out.println("Podaj słowo:");
  63.         String slowo = skan.nextLine();
  64.  
  65.         try{
  66.  
  67.             Scanner odczyt = new Scanner(new File("slownik.txt"));
  68.             while (odczyt.hasNextLine()) {
  69.                 String linia = odczyt.nextLine();
  70.  
  71.                 if(linia.contains(slowo)){
  72.                     suma_pkt ++;
  73.                     break;
  74.                 }
  75.  
  76.             }
  77.             System.out.println("Zdobyłeś " + suma_pkt + " punktów.");
  78.         }
  79.         catch(FileNotFoundException e){
  80.             System.out.println("Przykro mi, problem z plikiem.");
  81.         }
  82.  
  83.     }
  84.  
  85.     public void paintComponent(Graphics graphic) {
  86.         Graphics2D g2d = (Graphics2D) graphic;
  87.         g2d.drawImage(tlo_3, 0, 0, this);
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment