CodeGym /Java Course /All lectures for KO purposes /๊ฒŒ์ž„ ์—”์ง„์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

๊ฒŒ์ž„ ์—”์ง„์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

All lectures for KO purposes
๋ ˆ๋ฒจ 1 , ๋ ˆ์Šจ 571
์‚ฌ์šฉ ๊ฐ€๋Šฅ

1. ๊ฒฝ๊ธฐ์žฅ์˜ ์„ธํฌ๋กœ ์ž‘์—…ํ•˜๊ธฐ

์šด๋™์žฅ์„ ์…€๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์šฐ๋ฆฌ๋Š” ์„ธํฌ ์ž์ฒด๋กœ ๋ฌด์—‡์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

๊ฒฝ๊ธฐ์žฅ์˜ ๊ฐ ์…€์— ๋Œ€ํ•ด ๋‹ค์Œ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์…€ ์ƒ‰์ƒ(์…€์˜ ๋ฐฐ๊ฒฝ์ƒ‰);
  • ํ…์ŠคํŠธ(ํ…์ŠคํŠธ ๋˜๋Š” ์ˆซ์ž์ผ ์ˆ˜ ์žˆ์Œ)
  • ํ…์ŠคํŠธ ์ƒ‰์ƒ;
  • ์…€ ํฌ๊ธฐ์˜ ๋ฐฑ๋ถ„์œจ๋กœ ํ‘œ์‹œ๋˜๋Š” ํ…์ŠคํŠธ ํฌ๊ธฐ.

๊ฒฝ๊ธฐ์žฅ์˜ ์„ธํฌ๋กœ ์ž‘์—…ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๊ณ ๋ คํ•ด ๋ด…์‹œ๋‹ค.

void setCellColor(int x, int y, Color color)(x, y)์ขŒํ‘œ ๊ฐ€ ์™€ ๊ฐ™์€ ์…€์˜ ์ƒ‰์ƒ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค color.

์˜ˆ:

setCellColor(0, 0, Color.RED);
setCellColor(3, 6, Color.BLACK);
setCellColor(6, 8, Color.NONE);

Color getCellColor(int x, int y)์ขŒํ‘œ๊ฐ€ ์žˆ๋Š” ์…€์˜ ์ƒ‰์ƒ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค (x, y).

์˜ˆ:

Color myColor = getCellColor(2, 0);

void setCellValue(int x, int y, String value)String value์ขŒํ‘œ๊ฐ€ ์žˆ๋Š” ์…€์— ํ…์ŠคํŠธ๋ฅผ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค (x, y).

์˜ˆ:

setCellValue(3, 3, "text");
setCellValue(0, 8, "W");
setCellValue(4, 1, "2222");
setCellValue(6, 6, "");

String getCellValue(int x, int y)์ขŒํ‘œ๊ฐ€ ์žˆ๋Š” ์…€์— ํฌํ•จ๋œ ํ…์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค (x, y).

์˜ˆ:

String s = getCellValue(3, 3);
System.out.println(getCellValue(4, 1));

void setCellTextSize(int x, int y, int size)์ขŒํ‘œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์…€์˜ ํ…์ŠคํŠธ ํฌ๊ธฐ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค (x, y). ์—ฌ๊ธฐ์„œ size๋Š” ํ…์ŠคํŠธ ๋†’์ด๋ฅผ ์…€ ๋†’์ด์˜ ๋ฐฑ๋ถ„์œจ๋กœ ๋‚˜ํƒ€๋‚ธ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์˜ˆ:

setCellTextSize(2, 0, 70); // 70% of the cell height

int getCellTextSize(int x, int y)์ขŒํ‘œ๊ฐ€ ์žˆ๋Š” ์…€์˜ ์ฝ˜ํ…์ธ  ํฌ๊ธฐ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค (x, y).

์˜ˆ:

int size = getCellTextSize(2 , 0);

void setCellNumber(int x, int y, int value)int value์ขŒํ‘œ๊ฐ€ ์žˆ๋Š” ์…€์— ๋ฒˆํ˜ธ๋ฅผ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค (x, y).

์˜ˆ:

setCellNumber(3, 3, 40);
setCellNumber(0, 8, -8);
setCellNumber(4, 1, 2222);
setCellNumber(6, 6, 0);

int getCellNumber(int x, int y)์ขŒํ‘œ๊ฐ€ ์žˆ๋Š” ์…€์— ํฌํ•จ๋œ ์ˆซ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค (x, y). ์…€์— ์ˆซ์ž๊ฐ€ ์—†์œผ๋ฉด 0์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ:

int i = getCellNumber(3, 3);
System.out.println(getCellNumber(4, 1));

void setCellTextColor(int x, int y, Color color)์ขŒํ‘œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์…€์˜ ๋‚ด์šฉ(ํ…์ŠคํŠธ) ์ƒ‰์ƒ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค (x, y).

์˜ˆ:

setCellTextColor(2, 1, Color.GREEN);
setCellTextColor(0, 1, Color.NONE);

Color getCellTextColor(int x, int y)์ขŒํ‘œ๊ฐ€ ์žˆ๋Š” ์…€์˜ ๋‚ด์šฉ(ํ…์ŠคํŠธ) ์ƒ‰์ƒ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค (x, y).

์˜ˆ:

Color textColor = getCellTextColor(1, 3);

setCellValueEx()๊ท€ํ•˜์˜ ํŽธ์˜๋ฅผ ์œ„ํ•ด ๋งค๊ฐœ๋ณ€์ˆ˜ ์„ธํŠธ๊ฐ€ ๋‹ค๋ฅธ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค .

void setCellValueEx(int x, int y, Color cellColor, String value)(x, y)์ขŒํ‘œ๊ฐ€ ๊ฐ๊ฐ cellColor๋ฐ ์ธ ์…€์˜ ๋ฐฐ๊ฒฝ์ƒ‰๊ณผ ํ…์ŠคํŠธ๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค value.

์˜ˆ:

setCellValueEx(0, 2, Color.BLUE, "56");

void setCellValueEx(int x, int y, Color cellColor, String value, Color textColor)์…€์˜ ๋ฐฐ๊ฒฝ์ƒ‰, ํ…์ŠคํŠธ ๋ฐ ํ…์ŠคํŠธ ์ƒ‰์„ (x, y)๊ฐ๊ฐ cellColor, value, ์™€ textColor๊ฐ™์€ ์ขŒํ‘œ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ:

setCellValueEx(0, 2, Color.BLACK, "56", Color.GREEN);

void setCellValueEx(int x, int y, Color cellColor, String value, Color textColor, int textSize);์…€์˜ ๋ฐฐ๊ฒฝ์ƒ‰, ํ…์ŠคํŠธ, ํ…์ŠคํŠธ ์ƒ‰์ƒ ๋ฐ ํ…์ŠคํŠธ ํฌ๊ธฐ๋ฅผ (x, y)๊ฐ๊ฐ cellColor, value, textColor๋ฐ ์™€ textSize๊ฐ™์€ ์ขŒํ‘œ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ:

setCellValueEx(0, 2, Color.BLACK, "56", Color.GREEN, 70);


2. ์ƒ‰์ƒ ์ž‘์—…

CodeGym ๊ฒŒ์ž„ ์—”์ง„์—๋Š” Color148๊ฐ€์ง€ ์ƒ‰์ƒ์— ๋Œ€ํ•œ ๊ณ ์œ ํ•œ ๊ฐ’์„ ํฌํ•จํ•˜๋Š” ํŠน์ˆ˜ ์œ ํ˜•์ด ์žˆ์Šต๋‹ˆ๋‹ค. NONE๋˜ํ•œ ์ƒ‰์ƒ์ด ์—†์Œ์„ ๋‚˜ํƒ€๋‚ด๋Š” ํŠน๋ณ„ํ•œ ๊ฐ’์ด ์žˆ์Šต๋‹ˆ๋‹ค .

์ƒ‰์ƒ ์ž‘์—…์˜ ์˜ˆ

Color myColor = Color.WHITE;  // The color white is assigned to the myColor variable.
Color redColor = Color.RED; // The color red is assigned to the redColor variable.
Color blueColor = Color.BLUE; // The color blue is assigned to the blueColor variable.

๋‹ค์Œ ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์—ฌ ์…€์„ ๋นจ๊ฐ„์ƒ‰์œผ๋กœ ์ฑ„์ƒ‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

setCellColor(0, 2, Color.RED);

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์œผ๋กœ ์…€์ด ํŠน์ • ์ƒ‰์ƒ์ธ์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

if (getCellColor(0,2) == Color.GREEN)
{
}

๋•Œ๋กœ๋Š” ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ์ƒ‰์ƒ์˜ ๋ฐฐ์—ด์„ ๊ฐ€์ ธ์™€์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒํ•˜๋ ค๋ฉด values()๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

์˜ˆ:

// An array containing every available color is assigned to the colors variable.
Color[] colors = Color.values();

์ƒ‰์ƒ ํŒ”๋ ˆํŠธ์—์„œ ์ƒ‰์ƒ ์ธ๋ฑ์Šค๋ฅผ ์–ป๋Š” ๊ฒƒ์€ ๋งค์šฐ ์‰ฝ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ordinal()๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

Color color = Color.RED;
int redIndex = color.ordinal(); // Index of the color red

int blueIndex = Color.BLUE.ordinal(); // Index of the color blue

์ƒ‰์ธ์œผ๋กœ ์ƒ‰์ƒ์„ ์‰ฝ๊ฒŒ ์–ป์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

 // The color whose index is 10 in the Color enum is assigned to the color variable.
Color color = Color.values()[10];


3. ๋Œ€ํ™” ์ƒ์ž

๊ฒŒ์ž„์ด ๋๋‚˜๋ฉด ํ”Œ๋ ˆ์ด์–ด์—๊ฒŒ ์ŠนํŒจ๋ฅผ ์•Œ๋ ค์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ์™€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ๋ฅผ ์œ„ํ•ด CodeGym ๊ฒŒ์ž„ ์—”์ง„์—๋Š” ๋ฉ”์‹œ์ง€ void showMessageDialog(Color cellColor, String message, Color textColor, int textSize)๊ฐ€ ํฌํ•จ๋œ ๋Œ€ํ™” ์ƒ์ž๋ฅผ ํ‘œ์‹œํ•˜๋Š” ํŠน๋ณ„ํ•œ ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค message.
์ด ๋ฉ”์„œ๋“œ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • cellColor๋Œ€ํ™” ์ƒ์ž์˜ ๋ฐฐ๊ฒฝ์ƒ‰์ž…๋‹ˆ๋‹ค.
  • message๋ฉ”์‹œ์ง€์˜ ํ…์ŠคํŠธ์ž…๋‹ˆ๋‹ค
  • textColor๋ฉ”์‹œ์ง€ ํ…์ŠคํŠธ์˜ ์ƒ‰์ƒ์ž…๋‹ˆ๋‹ค.
  • textSize๋ฉ”์‹œ์ง€ ํ…์ŠคํŠธ์˜ ํฌ๊ธฐ์ž…๋‹ˆ๋‹ค.

์‚ฌ์šฉ์ž๊ฐ€ ์ŠคํŽ˜์ด์Šค ๋ฐ”๋ฅผ ๋ˆ„๋ฅด๊ฑฐ๋‚˜ ๋งˆ์šฐ์Šค๋กœ ๋Œ€ํ™” ์ƒ์ž๋ฅผ ํด๋ฆญํ•˜๋ฉด ๋Œ€ํ™” ์ƒ์ž๊ฐ€ ์ž๋™์œผ๋กœ ๋‹ซํž™๋‹ˆ๋‹ค.

์ด ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ์˜ˆ:

// Display a dialog box with a message
showMessageDialog(Color.BLACK, "EPIC FAIL", Color.RED, 80);


4. ํ™œ์šฉ ๋ฐฉ๋ฒ•

๊ฒŒ์ž„์„ ์ž‘์„ฑํ•  ๋•Œ ๋‚œ์ˆ˜๋ฅผ ์ž์ฃผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋‚œ์ˆ˜๋ฅผ ๋” ์‰ฝ๊ฒŒ ์–ป๊ธฐ ์œ„ํ•ด ๊ฒŒ์ž„ ์—”์ง„์˜ ์œ ํ‹ธ๋ฆฌํ‹ฐ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

int getRandomNumber(int max)0๋ฒ”์œ„ ์—์„œ ๋‚œ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค (maxโ€“1).

int getRandomNumber(int min, int max)min๋ฒ”์œ„ ์—์„œ ๋‚œ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค (maxโ€“1).


5. JDK 11+

IntelliJ IDEA์—์„œ ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰ํ•  ๋•Œ Game ํด๋ž˜์Šค๋ฅผ ์ƒ์†ํ•˜๋Š” ํด๋ž˜์Šค์—์„œ ๋‹ค์Œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Error: JavaFX runtime components are missing, and are required to run this application

์ด ๊ฒฝ์šฐ ์ด๋Ÿฌํ•œ ๊ฐ ํด๋ž˜์Šค์— ๋Œ€ํ•ด ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ํ•œ ๋ฒˆ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  1. ์‹คํ–‰ ์—ด๊ธฐ โ†’ ๊ตฌ์„ฑ ํŽธ์ง‘
  2. VM ์˜ต์…˜ ๊ฐ’์œผ๋กœ ๋‹ค์Œ์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
    --module-path ./lib/javafx-sdk-16/lib --add-modules=javafx.controls,javafx.fxml,javafx.base

    ์ฃผ๋ชฉ:

    ์ตœ์‹  ๋ฒ„์ „์˜ IntelliJ IDEA์—์„œ๋Š” "VM ์˜ต์…˜" ํ•„๋“œ๊ฐ€ ๊ธฐ๋ณธ์ ์œผ๋กœ ํ‘œ์‹œ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ‘œ์‹œํ•˜๋ ค๋ฉด ALT+V๋ฅผ ๋ˆ„๋ฅด์‹ญ์‹œ์˜ค.

  3. ๋ˆ„๋ฅด๊ธฐ: ์ ์šฉ โ†’ ํ™•์ธ
  4. ๊ฒŒ์ž„์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
์ฝ”๋ฉ˜ํŠธ
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION