728x90
๋ฐ˜์‘ํ˜•

1) ์ •์ฒ˜๊ธฐ ์นด์šดํŠธ๋‹ค์šด ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ

 

1-1) java ๋ฒ„์ „ : ๊ณ„์†ํ•ด์„œ ์‹œ๊ฐ„ ์นด์šดํŠธํ•˜๊ณ  ๋”ฐ๋กœ ํŽ˜์ด์ง€๊ฐ€ ๋œจ๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ๋ฐ”๋กœ ํŒŒ์ด์ฌ์œผ๋กœ ๋ณ€๊ฒฝ

๋”๋ณด๊ธฐ

package java0328;

import java.time.Duration;

import java.time.LocalDateTime;

public class Countdown {

public static void main(String[] args) {

LocalDateTime endDateTime = LocalDateTime.of(2023, 5, 13, 0, 0, 0);

LocalDateTime nowDateTime;

while (true) {

nowDateTime = LocalDateTime.now();

if (nowDateTime.isAfter(endDateTime)) {

System.out.println("Time's up!");

break;

}

Duration duration = Duration.between(nowDateTime, endDateTime);

long days = duration.toDays();

long hours = duration.toHours() % 24;

long minutes = duration.toMinutes() % 60;

long seconds = duration.getSeconds() % 60;

String remainingTime = String.format("%02d:%02d:%02d:%02d", days, hours, minutes, seconds);

System.out.println(remainingTime);

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

 

}

๋‚˜์˜ค๋Š” ๊ฒฐ๊ณผ๋Š” 

์‹œ๊ฐ„์ด ์ง€๋‚ ์ˆ˜๋ก ์ ์  ์ž‘์•„์ง„๋‹ค

 

1-2) python๋ฒ„์ „ : GUI๋ฅผ ์ด์šฉํ•ด์„œ ๋งŒ๋“œ๋ฉด ๋”ฐ๋กœ ํŽ˜์ด์ง€๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค

import tkinter as tk
import datetime


class CountdownApp:
    def __init__(self, master):
        self.master = master
        self.master.title("์ •๋ณด์ฒ˜๋ฆฌ๊ธฐ์‚ฌ ํ•„๊ธฐ ํ•ฉ๊ฒฉ ๊ฐ€๋ณด์ž๊ณ !")
        self.end_date = datetime.datetime(2023, 5, 13)
        self.remaining_time_str = tk.StringVar(value=self.get_remaining_time())
        self.remaining_time_label = tk.Label(
            self.master,
            textvariable=self.remaining_time_str,
            font=("Arial", 64),
            fg="blue",
            bg="gray",
        )
        self.remaining_time_label.pack(pady=20)

        # Create image label
        self.image_label = tk.Label(self.master)
        self.image_label.pack(pady=10)

        self.message_label = tk.Label(
            self.master,
            text="์กฐ์ˆ˜ํ˜„ ์•„์ž์•„์ž ํ™”์ดํŒ…!",
            font=("Arial", 24),
            fg="white",
            bg="green",
        )
        self.message_label.pack(pady=10)

        # Load image and set it to the image label
        self.kakao_image = tk.PhotoImage(file="D:\chosuhyeon\school class\python\py0328\shsu.png")
        self.image_label.configure(image=self.kakao_image)

        self.countdown()

    def get_remaining_time(self):
        remaining = self.end_date - datetime.datetime.now()
        days, seconds = remaining.days, remaining.seconds
        hours = seconds // 3600
        minutes = (seconds % 3600) // 60
        seconds = seconds % 60
        remaining_time = f"{days:02}:{hours:02}:{minutes:02}:{seconds:02}"
        return remaining_time

    def countdown(self):
        self.remaining_time_str.set(self.get_remaining_time())
        if datetime.datetime.now() >= self.end_date:
            self.remaining_time_str.set("Time's up!")
            return
        self.master.after(1000, self.countdown)


if __name__ == "__main__":
    root = tk.Tk()
    app = CountdownApp(root)
    root.mainloop()

์ •๋ณด์ฒ˜๋ฆฌ๊ธฐ์‚ฌ๋ฅผ ํ•ฉ๊ฒฉํ•˜๊ณ 

์žํ•˜๋Š” ์—ผ์›์„ ๋‹ด์•„ chat gptํ•œํ…Œ ๋ฌผ์–ด๋ณด์•˜๊ณ  ์ƒ์„ธํžˆ ์•Œ๋ ค์ฃผ์‹ฌ์š”~~

๋‚˜์˜จ๊ฒฐ๊ณผ๋Š”

์ข‹์•„ํ•˜๋Š” ์ตœ๊ณ ์‹ฌ ์บ๋ฆญํ„ฐ๋ฅผ ๋„ฃ์–ด๋ณด์•˜์Šต๋‹ˆ๋‹น๐Ÿ’ฅ๐Ÿ’ฅ


2) ํŒจํ‚ค์ง€

 

2-1) ์˜๋ฏธ

  • ํด๋ž˜์Šค ํŒŒ์ผ์„ ๋ฌถ์–ด์„œ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ˆ˜๋‹จ์œผ๋กœ ํŒŒ์ผ ์‹œ์Šคํ…œ์˜ ํด๋”๋ฅผ ์ด์šฉ
  • ํŒจํ‚ค์ง€์— ์˜ํ•œ ์žฅ์ 

- ํŒจํ‚ค์ง€๋งˆ๋‹ค ๋ณ„๋„์˜ ์ด๋ฆ„ ๊ณต๊ฐ„์ด ์ƒ๊ธฐ๊ธฐ ๋•Œ๋ฌธ์— ํด๋ž˜์Šค ์ด๋ฆ„์˜ ์œ ์ผ์„ฑ์„ ๋ณด์žฅ

- ํด๋ž˜์Šค๋ฅผ ํŒจํ‚ค์ง€ ๋‹จ์œ„๋กœ๋„ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ข€ ๋” ์„ธ๋ฐ€ํ•˜๊ฒŒ ์ ‘๊ทผ ์ œ์–ด

 

2-2) ํŒจํ‚ค์ง€ ์„ ์–ธ

  • ์ฃผ์„๋ฌธ์„ ์ œ์™ธํ•˜๊ณ  ๋ฐ˜๋“œ์‹œ ์ฒซ ํ–‰์— ์„ ์–ธํ•ด์•ผ ํ•œ๋‹ค. 
  • ํŒจํ‚ค์ง€ ์ด๋ฆ„์€ ๋ชจ๋‘ ์†Œ๋ฌธ์ž๋กœ ๋ช…๋ช…ํ•˜๋Š” ๊ฒƒ์ด ๊ด€๋ก€์ด๋ฉฐ, ๋Œ€๊ฐœ ํšŒ์‚ฌ์˜ ๋„๋ฉ”์ธ ์ด๋ฆ„์„ ์—ญ์ˆœ์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค. 

2-3) import๋ฌธ

  • ํŒจํ‚ค์ง€์˜ ๊ฒฝ๋กœ๋ฅผ ๋ฏธ๋ฆฌ ์ปดํŒŒ์ผ๋Ÿฌ์—๊ฒŒ ์•Œ๋ ค์ฃผ๋Š” ๋ฌธ์žฅ
  • import ๋ฌธ์€ ์†Œ์Šค ํŒŒ์ผ์—์„œ package ๋ฌธ๊ณผ ์ฒซ ๋ฒˆ์งธ ํด๋ž˜์Šค ์„ ์–ธ๋ถ€ ์‚ฌ์ด์— ์œ„์น˜

import๋ฌธ ์˜ˆ์ œ

2-4) ์ƒ์†๊ณผ ์ ‘๊ทผ ์ œ์–ด

 

- ์ ‘๊ทผ ์ง€์ •์ž์˜ ์ ‘๊ทผ ๋ฒ”์œ„

์ ‘๊ทผ ์ง€์ •์ž ๋™์ผํด๋ž˜์Šค ๋™์ผ ํŒจํ‚ค์ง€ ์ž์‹ ํด๋ž˜์Šค ๋‹ค๋ฅธ ํŒจํ‚ค์ง€
public o o o o
protected o o o x
default(์—†์Œ) o o x x
private o x x x

์ž๋ฐ”ํ•˜๋ฉด์„œ ์ •๋ง ์ค‘์š”ํ•˜๋‹ค๊ณ  ๋ง์”€ํ•ด์ฃผ์‹  ๋ถ€๋ถ„์ด ๋ช‡ ์—†์—ˆ๋Š”๋ฐ ์ •๋ง ๊ฐ•์กฐํ•˜์‹ ๊ฑฐ ์ค‘์— ํ•˜๋‚˜์—์š”~~ ์•„์ขŒ์ขŒ ๋‹ค ์™ธ์›Œ๋ณด์žฅ

 

- ์ ‘๊ทผ ์ง€์ •์ž ์‚ฌ์šฉ ์‹œ ์ฃผ์˜ ์‚ฌํ•ญ

  • private ๋ฉค๋ฒ„๋Š” ์ž์‹ ํด๋ž˜์Šค์— ์ƒ์†๋˜์ง€ ์•Š๋Š”๋‹ค
  • ํด๋ž˜์Šค ๋ฉค๋ฒ„๋Š” ์–ด๋–ค ์ ‘๊ทผ ์ง€์ •์ž๋กœ๋„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ํด๋ž˜์Šค๋Š” protected, private์œผ๋กœ ์ง€์ •ํ•  ์ˆ˜ ์—†๋‹ค
  • ๋ฉ”์„œ๋“œ๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•  ๋•Œ ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ ๋ฉ”์„œ๋“œ๋ณด๋‹ค ๊ฐ€์‹œ์„ฑ์„ ๋” ์ข๊ฒŒ ํ•  ์ˆ˜๋Š” ์—†๋‹ค

2-5) final ํด๋ž˜์Šค

- final ๋ฉ”์„œ๋“œ๋Š” ๋” ์ด์ƒ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•  ์ˆ˜ ์—†๋Š” ์ข…๋‹จ์˜ ๋ฉ”์„œ๋“œ์ด๋‹ค

=> ๋”ฐ๋ผ์„œ ๋ถ€๋ชจ ํด๋ž˜์Šค์—์„œ ์ •์˜ํ•œ final ๋ฉ”์„œ๋“œ๋ฅผ ์ž์‹ ํด๋ž˜์Šค๋Š” ์ˆ˜์ • ์—†์ด ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜์—ฌ์•ผ ํ•œ๋‹ค.

- final ํด๋ž˜์Šค๋Š” ํด๋ž˜์Šค ๋‚ด๋ถ€์˜ ๋ชจ๋“  ๋ฉ”์„œ๋“œ๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•  ์ˆ˜ ์—†๊ณ  ํŠน์ • ๋ฉ”์„œ๋“œ๋งŒ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•˜์ง€ ์•Š๋„๋ก ํ•˜๋ ค๋ฉด final ๋ฉ”์„œ๋“œ๋กœ ์„ ์–ธํ•˜๋ฉด๋œ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•

'java' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

java ๊ธฐ์ดˆ(๋ฌธ์ž์—ด์˜ ์„ ์–ธ๊ณผ ์ƒ์„ฑ, ๋ฌธ์žฅ์—ด์˜ ๋น„๊ต, ๋ฌธ์ž์—ด์˜ ๋‹ค์–‘ํ•œ ์—ฐ์‚ฐ, String ํด๋ž˜์Šค์—์„œ ์ œ๊ณตํ•˜๋Š” ์œ ์šฉํ•œ ์ •์  ๋ฉ”์„œ๋“œ, ๋ฐฐ์—ด๊ธฐ์ดˆ)  (0) 2023.04.06
java ๊ธฐ์ดˆ (์ œ์–ด๋ฌธ, ์กฐ๊ฑด๋ฌธ, ๋ฐ˜๋ณต๋ฌธ, ๋ถ„๊ธฐ๋ฌธ...)  (0) 2023.04.02
์—ฐ์‚ฐ์ž, ์ƒ์†(์ƒ์†์˜ ํ•„์š”์„ฑ, ์ƒ์†์ด๋ž€, ์ƒ์†์˜ ์„ ์–ธ, ๋ฉ”์„œ๋“œ ์˜ค๋ฒ„๋ผ์ด๋”ฉ, ์˜ค๋ฒ„๋กœ๋”ฉ ๋น„๊ต)  (0) 2023.03.27
java ๊ธฐ์ดˆ(๋ฐฐ์—ด ์‘์šฉ, ๊ฐ€๋ณ€ ๊ฐœ์ˆ˜ ์ธ์ˆ˜, ๊ฐ์ฒด์˜ ํƒ€์ž…, ์—ด๊ฑฐ ํƒ€์ž… ), ํŠน์ˆ˜๋ฌธ์ž ์›์ฃผ์œจ(ฯ€) ์“ฐ๋Š” ๋ฒ•  (0) 2023.03.25
java ์˜ˆ์ œ ๋ฌธ์ œ ํ’€๊ธฐ(์ˆซ์ž ๋”ํ•˜๊ธฐ, ์ง์ˆ˜ ์ถœ๋ ฅํ•˜๊ธฐ, ์†Œ์ˆ˜ ๊ตฌํ•˜๊ธฐ, ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜์—ด ์ž‘์„ฑํ•˜๊ธฐ, 10์ง„์ˆ˜๋ฅผ 2์ง„์ˆ˜๋กœ ๋ฐ”๊พธ๊ธฐ)  (0) 2023.03.22

+ Recent posts