Advertisement
Teammasik

laba9_OOP

Dec 12th, 2023
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.42 KB | None | 0 0
  1. // 1 zadanie
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.util.Random;
  7.  
  8. public class BouncingString extends JPanel implements ActionListener {
  9.     private String text;
  10.     private int x, y, dx;
  11.     private Color color;
  12.     private Random random;
  13.  
  14.     public BouncingString() {
  15.         random = new Random();
  16.         text = "I'm Artem Sultanov, yes!";
  17.         x = 0;
  18.         y = 200;
  19.         dx = 2;
  20.         color = Color.BLACK;
  21.  
  22.         Timer timer = new Timer(10, this);
  23.         timer.start();
  24.     }
  25.  
  26.     @Override
  27.     public void actionPerformed(ActionEvent e) {
  28.         x += dx;
  29.  
  30.         if (x < 0 || x > getWidth() - 150) {
  31.             dx = -dx;
  32.             color = new Color(random.nextFloat(), random.nextFloat(), random.nextFloat());
  33.         }
  34.  
  35.         repaint();
  36.     }
  37.  
  38.     @Override
  39.     protected void paintComponent(Graphics g) {
  40.         super.paintComponent(g);
  41.         g.setColor(color);
  42.         g.drawString(randomizeCase(text), x, y);
  43.     }
  44.  
  45.     private String randomizeCase(String str) {
  46.         StringBuilder sb = new StringBuilder(str.length());
  47.         for (char c : str.toCharArray()) {
  48.             sb.append(random.nextBoolean() ? Character.toUpperCase(c) : Character.toLowerCase(c));
  49.         }
  50.         return sb.toString();
  51.     }
  52.  
  53.     public static void main(String[] args) {
  54.         JFrame frame = new JFrame("Bouncing String");
  55.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  56.         frame.setSize(500, 500);
  57.         frame.setLocationRelativeTo(null);
  58.         frame.add(new BouncingString());
  59.         frame.setVisible(true);
  60.     }
  61. }
  62. -------------------------
  63. // 2 zadanie punkt 1
  64. import java.io.File;
  65. import java.util.ArrayList;
  66. import java.util.List;
  67. import java.util.concurrent.ExecutorService;
  68. import java.util.concurrent.Executors;
  69. import java.util.concurrent.TimeUnit;
  70.  
  71. public class FileSearch {
  72.  
  73.     private static class FileSearchTask implements Runnable {
  74.         private final String directory;
  75.  
  76.         public FileSearchTask(String directory) {
  77.             this.directory = directory;
  78.         }
  79.  
  80.         @Override
  81.         public void run() {
  82.             searchFiles(new File(directory));
  83.         }
  84.  
  85.         private void searchFiles(File directory) {
  86.             File[] files = directory.listFiles();
  87.             if (files != null) {
  88.                 for (File file : files) {
  89.                     if (file.isDirectory()) {
  90.                         searchFiles(file);
  91.                     } else {
  92.                         System.out.println("Found file: " + file.getAbsolutePath());
  93.                     }
  94.                 }
  95.             }
  96.         }
  97.     }
  98.  
  99.     public static void main(String[] args) throws InterruptedException {
  100.         List<String> directories = new ArrayList<>();
  101.         directories.add("C:/Users/6acco/Documents/учёба/ООП/Cursovaya");
  102.         directories.add("C:/Users/6acco/Documents/учёба/ООП/prac1");
  103.  
  104.         ExecutorService executor = Executors.newFixedThreadPool(directories.size());
  105.  
  106.         for (String directory : directories) {
  107.             executor.execute(new FileSearchTask(directory));
  108.         }
  109.  
  110.         executor.shutdown();
  111.         executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
  112.     }
  113. }
  114. // 2 zadanie punkt 2+3, ya ego ne sdaval, ono vrode chut-chut ne pravilno rabotaet
  115. https://pastebin.com/wnkTnWvD
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement