Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1 zadanie
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.Random;
- public class BouncingString extends JPanel implements ActionListener {
- private String text;
- private int x, y, dx;
- private Color color;
- private Random random;
- public BouncingString() {
- random = new Random();
- text = "I'm Artem Sultanov, yes!";
- x = 0;
- y = 200;
- dx = 2;
- color = Color.BLACK;
- Timer timer = new Timer(10, this);
- timer.start();
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- x += dx;
- if (x < 0 || x > getWidth() - 150) {
- dx = -dx;
- color = new Color(random.nextFloat(), random.nextFloat(), random.nextFloat());
- }
- repaint();
- }
- @Override
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.setColor(color);
- g.drawString(randomizeCase(text), x, y);
- }
- private String randomizeCase(String str) {
- StringBuilder sb = new StringBuilder(str.length());
- for (char c : str.toCharArray()) {
- sb.append(random.nextBoolean() ? Character.toUpperCase(c) : Character.toLowerCase(c));
- }
- return sb.toString();
- }
- public static void main(String[] args) {
- JFrame frame = new JFrame("Bouncing String");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(500, 500);
- frame.setLocationRelativeTo(null);
- frame.add(new BouncingString());
- frame.setVisible(true);
- }
- }
- -------------------------
- // 2 zadanie punkt 1
- import java.io.File;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- import java.util.concurrent.TimeUnit;
- public class FileSearch {
- private static class FileSearchTask implements Runnable {
- private final String directory;
- public FileSearchTask(String directory) {
- this.directory = directory;
- }
- @Override
- public void run() {
- searchFiles(new File(directory));
- }
- private void searchFiles(File directory) {
- File[] files = directory.listFiles();
- if (files != null) {
- for (File file : files) {
- if (file.isDirectory()) {
- searchFiles(file);
- } else {
- System.out.println("Found file: " + file.getAbsolutePath());
- }
- }
- }
- }
- }
- public static void main(String[] args) throws InterruptedException {
- List<String> directories = new ArrayList<>();
- directories.add("C:/Users/6acco/Documents/учёба/ООП/Cursovaya");
- directories.add("C:/Users/6acco/Documents/учёба/ООП/prac1");
- ExecutorService executor = Executors.newFixedThreadPool(directories.size());
- for (String directory : directories) {
- executor.execute(new FileSearchTask(directory));
- }
- executor.shutdown();
- executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
- }
- }
- // 2 zadanie punkt 2+3, ya ego ne sdaval, ono vrode chut-chut ne pravilno rabotaet
- https://pastebin.com/wnkTnWvD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement