xmauron avatar

Starting to Learn Java

xmauron3

Published: 11 Aug 2024 › Updated: 11 Aug 2024Starting to Learn Java

Starting to Learn Java

Hey my hivean friends,

I decided to learn JAVA a few days ago, and asked Chat GPT to build a study routine for me. First of all, it gave me some subjects that would be important for me to learn. So, I asked it to organize all subjects in a Timetable so that I could adapt in my daily routine.

It was very good. So good that I decided to create a Pomodoro routine, and asked chat GPT to create an image with this representation for me.

And here's the image:

alt

Eu decidi aprender java há alguns dias, e pedi ao Chat GPT construir uma rotina de estudos para mim. Primeiramente, ele me deu um algumas matérias que seriam importantes para eu aprender. Então, o pedi que as organizasse em uma Timetable para que eu pudesse incluir na minha rotina diária.

Ficou muito bom. Tão bom que eu decidi criar uma rotina Pomodoro, e pedi para que o chat GPT fizesse isso numa imagem para mim.

Ficou assim:

Legal, né?

Então tive a incrível idéia de pedir para que o chat GPT fizesse um programa de Java para mim, com notificações no Sistema operacional. Estou usando o intelliJ IDEA community version.

Aqui está o código:

Here's the code:

import java.awt.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class PomodoroScheduler {

private static final String[] TASKS = {
        "Set up study space, review Java basics",
        "Break",
        "Practice writing basic Java programs",
        "Break",
        "Study Java object-oriented programming concepts",
        "Break",
        "Code along with a tutorial on Java OOP",
        "Break",
        "Explore Java collections framework",
        "Break",
        "Practice coding with collections",
        "Lunch Break",
        "Study Java exception handling",
        "Break",
        "Implement exception handling in your code",
        "Break",
        "Study Java input/output (I/O) operations",
        "Break",
        "Practice Java I/O",
        "Break",
        "Study Java multithreading basics",
        "Break",
        "Implement multithreading in your programs",
        "Break",
        "Explore Java networking",
        "Break",
        "Practice networking in Java",
        "Break",
        "Review and consolidate the day's learning",
        "Break",
        "Free Time"
};

private static final int[] DURATIONS = {
        25, 5, 25, 5,
        25, 5, 25, 5,
        25, 5, 25, 35,
        25, 5, 25, 5,
        25, 5, 25, 5,
        25, 5, 25, 5,
        25, 5, 25, 5,
        25, 5, 25
};

public static void main(String[] args) {
    if (SystemTray.isSupported()) {
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

        Runnable task = new Runnable() {
            int currentTask = 0;

            @Override
            public void run() {
                if (currentTask < TASKS.length) {
                    displayNotification("Pomodoro Timer", "Time for: " + TASKS[currentTask]);
                    scheduler.schedule(this, DURATIONS[currentTask], TimeUnit.MINUTES);
                    currentTask++;
                } else {
                    scheduler.shutdown();
                }
            }
        };

        scheduler.schedule(task, 0, TimeUnit.SECONDS);
    } else {
        System.err.println("System tray not supported!");
    }
}

private static void displayNotification(String title, String message) {
    try {
        SystemTray tray = SystemTray.getSystemTray();
        Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
        TrayIcon trayIcon = new TrayIcon(image, "Pomodoro Timer");
        trayIcon.setImageAutoSize(true);
        trayIcon.setToolTip("Pomodoro Timer");
        tray.add(trayIcon);

        trayIcon.displayMessage(title, message, TrayIcon.MessageType.INFO);
        Thread.sleep(5000); // Show notification for 5 seconds
        tray.remove(trayIcon);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

Fiquem livres para experimentar e copiar. Aceito dúvidas e sugestões!

Be free to experiment and copy. I accept all questions and suggestions!

Esse foi outro incrível post de:

This was another great post by:

xmauron3Hive account@xmauron3

"O futuro é Incrível"

alt

Leave Starting to Learn Java to:

Written by

Certified Cybercitizen

Read more #coding posts


Best Posts From xmauron

We have not curated any of xmauron3's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From xmauron