/*
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a=sc.nextInt(),b=sc.nextInt();
int x=sc.nextInt(),y=sc.nextInt(),z=sc.nextInt();
int map[][]=new int[200][200],map1[][]=new int[200][200];
int i,j,k,t;
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
map[i][j]=sc.nextInt();
}
}
k=sc.nextInt();
for(t=1;t<=k;t++)// k세대
{
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
map1[i][j]=map[i+1][j]+map[i-1][j]+map[i][j+1]+map[i][j-1]+map[i+1][j+1]+map[i-1][j-1]+map[i+1][j-1]+map[i-1][j+1];
}
}
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
if(map1[i][j]==x)
{
map[i][j]=1;
}
if(map1[i][j]>=z||map1[i][j]<y)
{
map[i][j]=0;
}
}
}
}
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
System.out.print(map[i][j]+" ");
}
System.out.print("\n");
}
}
}
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//기본자료형
// int a;
// float b;
// double c;
// char d;
// boolean e; //true or false
//문자 일차원배열 != 문자열
String str = "hello";
//문자열을 문자일차원배열로 변환
char arr[] = str.toCharArray();
//str=str+" world"; //문자열 붙이기
//System.out.println(str);
//System.out.println(arr[0]);
//System.out.println((char)(str.charAt(0)-32)); // not str[0]
String str1 = "hello1";
//if(str==str1) (x) 문자열끼리는 ==으로 비교 불가능!!!!
if(str.equals(str1)) {
// System.out.println("same");
}
else {
//System.out.println("not same");
}
//str.length()
String s = "hello,world hi,hello";
String sarr[] = s.split(" ");
for(int i=0;i<sarr.length;i++) {
System.out.println("sarr["+i+"] "+sarr[i]);
}
}
}
*/
/*
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String n = sc.next();
String m = sc.next();
if(n.length()>m.length())
{
System.out.println(m+" "+n);
}
else if(n.length()<m.length())
{
System.out.println(n+" "+m);
}
else
{
if(n.compareTo(m)==1)
{
System.out.println(m+" "+n);
}
else
{
System.out.println(n+" "+m);
}
}
}
}
*/
/*
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
char a[]=(sc.next()).toCharArray();
char b[]=(sc.next()).toCharArray();
char c[]=(sc.next()).toCharArray();
int a1,b1,c1;
a1=a.length-1;
b1=b.length-1;
c1=c.length-1;
if(a[a1]==b[0]&&b[b1]==c[0]&&c[c1]==a[0])
{
System.out.println("good");
}
else
{
System.out.println("bad");
}
}
}
*/
/*
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
char a[]=(sc.next()).toCharArray();
int i,sum=0,x=0;
for(i=0;i<a.length;i++)
{
x=a[i]-'0';
sum+=x;
}
if(sum%3==0)
{
System.out.println("1");
}
else
{
System.out.println("0");
}
}
}
클래스
클래스 : 틀 ( 붕어빵틀)
객체 : 물체
클래스 : 생성자(초깃값설정), 필드(변수생성), 메소드(함수)
*/
/*
import java.util.*;
class BBang{
int size ; //field
void change_size(int size1) {
size=size1;
}
void print_size() {
System.out.println("이 빵의 사이즈는 "+ size+"입니다");
}
}
class Main{
public static void main(String[] args) {
BBang a = new BBang(); //a객체생성
BBang b = new BBang();
// a.size=10; //a객체의 필드 접근
// b.size=40;
a.change_size(10); //a객체의 메소드 실행
a.print_size();
a.change_size(50);
a.print_size();
}
}
*/
/*
class Circle{
int r;
String n;
public double getArea() {
return r*r*3.14;
}
public void view() {
double area = getArea();
System.out.println(n+"의 면적은 "+area+"입니다.");
}
}
public class Main{
public static void main(String[] args) {
Circle donut;
donut = new Circle();
donut.r= 10;
donut.n= "자바도넛";
donut.view();
}
}
생성자 : 객체를 생성할때의 필드 초기값 설정
생성자의 이름은 클래스의 이름과 같다
생성자는 리턴타입이 없음.
*/
/*
import java.util.*;
class Rectangle{
//필드
int width;
int height;
//생성자
public Rectangle() {
width = 100;
height = 100;
}
public Rectangle(int width, int height) {
this.width = width;
this.height = height;
}
//메소드
public int getArea() {
return width*height;
}
}
클래스
클래스 : 틀 ( 붕어빵틀)
객체 : 물체
클래스 : 생성자(초깃값설정), 필드(변수생성), 메소드(함수)
*/
/*
import java.util.*;
class BBang{
int size ; //field
void change_size(int size1) {
size=size1;
}
void print_size() {
System.out.println("이 빵의 사이즈는 "+ size+"입니다");
}
}
class Main{
public static void main(String[] args) {
BBang a = new BBang(); //a객체생성
BBang b = new BBang();
// a.size=10; //a객체의 필드 접근
// b.size=40;
a.change_size(10); //a객체의 메소드 실행
a.print_size();
a.change_size(50);
a.print_size();
}
}
*/
/*
class Circle{
int r;
String n;
public double getArea() {
return r*r*3.14;
}
public void view() {
double area = getArea();
System.out.println(n+"의 면적은 "+area+"입니다.");
}
}
public class Main{
public static void main(String[] args) {
Circle donut;
donut = new Circle();
donut.r= 10;
donut.n= "자바도넛";
donut.view();
}
}
생성자 : 객체를 생성할때의 필드 초기값 설정
생성자의 이름은 클래스의 이름과 같다
생성자는 리턴타입이 없음.
*/
/*
import java.util.*;
class Rectangle{
//필드
int width;
int height;
//생성자
public Rectangle() {
width = 100;
height = 100;
}
public Rectangle(int width, int height) {
this.width = width;
this.height = height;
}
//메소드
public int getArea() {
return width*height;
}
}
public class Main{
public static void main(String[] args) {
Rectangle rect;
Scanner sc =new Scanner(System.in);
System.out.print(">> ");
int w =sc.nextInt();
int h =sc.nextInt();
rect = new Rectangle(w,h);
System.out.println("사가형의 면적은 "+rect.getArea());
sc.close();
}
}
*/
/*
public class Main{
int r;
String name;
public Main() {
r=1;
name="";
}
public Main(int r,String n) {
this.r=r;
name =n;
}
public double getArea() {
return 3.14*r*r;
}
public static void main(String[] args) {
Main pizza = new Main(10,"자바피자");
double area = pizza.getArea();
System.out.println(pizza.name+"의 면적은 "+area+"입니다.");
Main donut = new Main(10,"자바도넛");
area = donut.getArea();
System.out.println(donut.name+"의 면적은 "+area+"입니다.");
}
}
*/
/*
class TV{
int y,size;
String c;
public TV() {
this("미정",5000,100);
}
public TV(String c, int y, int size){
this.c=c;
this.y=y;
this.size=size;
}
public void show() {
System.out.println(c+"에서 만든 "+y+"년형 "+size+"인치 TV");
}
}
class Main{
public static void main(String[] args) {
TV myTV = new TV("LG",2017,32);
myTV.show();
TV yourTV = new TV();
yourTV.show();
}
}
*/
/*
import java.util.*;
class Grade{
int m,s,e;
public Grade(int m,int s,int e) {
this.m=m;
this.s=s;
this.e=e;
}
public int average() {
return (m+s+e)/3;
}
}
class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("수학 ,과학,영어 순으로 3개의 점수 입력>> ");
int math = sc.nextInt();
int science =sc.nextInt();
int english =sc.nextInt();
Grade me= new Grade(math,science,english);
System.out.println("평균은 "+me.average());
sc.close();
}
}
*/
/*
class Song{
int year;
String title,artist,country;
public Song(int year,String artist,String title,String country)
{
this.year=year;
this.artist=artist;
this.title=title;
this.country=country;
}
public void show()
{
System.out.println(year+"년 "+country+"국적의 "+artist+"가 부른 "+ title);
}
}
class Main{
public static void main(String[] args) {
Song info=new Song(1978,"ABBA","Dancing Queen","스웨덴");
info.show();
}
}
*/
/*
class Rectangle{
int x,y,width,height;
public Rectangle(int x,int y,int width,int height) {
this.x=x;
this.y=y;
this.width=width;
this.height=height;
}
public int square() {
return width*height;
}
public void show() {
System.out.println("("+x+","+y+")"+"에서 크기가 "+width+"x"+height+"인 사각형");
}
public boolean contains(Rectangle r) {
if(r.x+r.width<x+width && r.y+r.height<y+height && r.x>x && r.y>y) {
return true;
}
else {
return false;
}
}
}
class Main{
public static void main(String[] args) {
Rectangle r = new Rectangle(2,2,8,7);
Rectangle s = new Rectangle(5,5,6,6);
Rectangle t = new Rectangle(1,1,10,10);
r.show();
System.out.println("s의 면적은 "+s.square());
if(t.contains(r)) {
System.out.println("t는 r을 포함합니다.");
}
if(t.contains(s)) {
System.out.println("t는 s를 포함합니다.");
}
}
}
*/
/*
import java.util.*;
class Rectangle{
int x,y,width,height;
}
class Main{
public static void main(String[] args) {
int arr[] = new int[5];
arr[0]=1;
Rectangle arr1[] = new Rectangle[5];
for(int i=0;i<arr1.length;i++) {
arr1[i] = new Rectangle();
}
arr1[0].height=10;
}
}
*/
/*
class Circle{
private int r;
public Circle(int r) {
this.r=r;
}
public double getArea() {
return r*r*3.14;
}
public int getR() {
return r;
}
public void setR(int r) {
this.r=r;
}
}
class Main{
public static void main(String[] args) {
Circle[] c;
c= new Circle[5];
for(int i=0;i<c.length;i++)
{
c[i] = new Circle(i);
c[i].setR(10);
}
for(int i=0;i<c.length;i++)
{
System.out.print((int)(c[i].getArea())+" ");
}
}
}
*/
/*
import java.util.*;
class Circle{
private double x,y;
private int radius;
public Circle(double x, double y,int radius) {
this.x=x;
this.y=y;
this.radius =radius;
}
public void show()
{
System.out.print("("+x+","+y+")"+radius+"\n");
}
}
class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Circle c[]= new Circle[3];
for(int i = 0;i<c.length;i++)
{
System.out.print("x, y, radius >> ");
double x=sc.nextDouble();
double y=sc.nextDouble();
int radius=sc.nextInt();
c[i]=new Circle(x, y, radius);
}
for(int i=0;i<c.length;i++)
{
c[i].show();
}
sc.close();
}
}
*/
/*
import java.util.*;
class Circle{
private double x,y;
private int radius;
public Circle(double x, double y,int radius) {
this.x=x;
this.y=y;
this.radius =radius;
}
public int getRadius() {
return radius;
}
public void show() {
System.out.print("("+x+","+y+")"+radius);
}
}
class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Circle c[]= new Circle[3];
int max=0;
for(int i = 0;i<c.length;i++)
{
System.out.print("x, y, radius >> ");
double x=sc.nextDouble();
double y=sc.nextDouble();
int radius=sc.nextInt();
c[i]=new Circle(x, y, radius);
if(radius>c[max].getRadius())
{
max=i;
}
}
c[max].show();
sc.close();
}
}
*/
/*
import java.util.*;
class Day{
private String work;
public void set(String work) {this.work=work;}
public String get() {return work;}
public void show() {
if(work==null) System.out.println("없습니다.");
else System.out.println(work+"입니다.");
}
}
class MonthSchedule{
Scanner sc =new Scanner(System.in);
int k;
Day arr[];
public MonthSchedule(int d) {
arr = new Day[d];
}
public void input(int d) { //입력
System.out.print("할일(빈칸없이입력)?");
String work = sc.next();
arr[d] = new Day();
arr[d].set(work);
}
public void view(int day) { //보기
System.out.print(day+"일의 할일은 ");
arr[day].show();
}
public void finish() { //끝내기
System.out.println("프로그램을 종료합니다.");
System.exit(0);
}
public void run() {
while(true) {
System.out.print("할일(입력:1, 보기:2, 끝내기:3) >> ");
k=sc.nextInt();
if(k==1)
{System.out.print("날짜(1~30)?");
int d = sc.nextInt();
input(d);
}
else if(k==2)
{
System.out.print("\n날짜(1~30)?");
int d = sc.nextInt();
view(d);
}
else
{
finish();
}
}
}
}
class Main{
public static void main(String[] args) {
MonthSchedule april= new MonthSchedule(30);
april.run();
}
}
*/
/*
import java.util.*;
class Phone {
private String name;
private String tel;
public Phone(String name, String tel) {
this.name = name;
this.tel = tel;
}
public String getName() {
return name;
}
public String getTel() {
return tel;
}
}
class Main {
Phone[] arr;
public void run()
{
Scanner sc = new Scanner(System.in);
int k;
String name1;
System.out.print("인원수 >> ");
k=sc.nextInt();
arr=new Phone[100];
for(int i=0;i<k;i++)
{
System.out.print("이름과 전화번호(이름과 번호는 빈 칸 없이 입력) >> ");
String name=sc.next();
String tel=sc.next();
arr[i]=new Phone(name,tel);
}
System.out.println("저장되었습니다...");
while(true)
{
System.out.print("검색할 이름 >> ");
name1=sc.next();
if(name1.equals("그만")) break;
boolean flag=false;
for(int i=0;i<k;i++) {
if(name1.equals(arr[i].getName())) {
System.out.println(name1+"의 번호는 "+arr[i].getTel()+" 입니다.");
flag=true;
break;
}
}
if(flag==false) System.out.println("\n"+name1+" 이 없습니다.");
}
}
public static void main(String[] args) {
Main m = new Main();
m.run();
}
}
*/
/*
static 같은 클래스로 만들어진 객체들이 공유하는 공간
import java.util.*;
class Phone {
static int num=0;
private String name;
private String tel;
public Phone(String name, String tel) {
this.name = name;
this.tel = tel;
}
public static void upNum() {
num++;
//tel="hi"; static 메소드에서 non-static 필드를 접근 할 수 없다!!
}
public String getName() {
return name;
}
public String getTel() {
return tel;
}
}
class Calculator{
static int add(int a, int b) {
return a+b;
}
}
class Main{
public static void main(String[] args) {
System.out.println(Calculater.add(5, 8));
Phone p = new Phone("aaa", "111");
Phone s = new Phone("bbb", "222");
System.out.println(p.num + " "+ s.num+ " "+Phone.num);
p.upNum();
System.out.println(p.num + " "+ s.num+ " "+Phone.num);
s.upNum();
System.out.println(p.num + " "+ s.num+ " "+Phone.num);
Phone.upNum();
System.out.println(p.num + " "+ s.num+ " "+Phone.num);
}
}
*/
/*
class ArrayUtil{
public static int [] concat(int[] a,int[] b) {
int[] c = new int[a.length+b.length];
for(int i=0;i<a.length;i++)
{
c[i]=a[i];
}
for(int i=0;i<b.length;i++)
{
c[i+a.length]=b[i];
}
return c;
}
public static void print(int[] a) { for(int i=0;i<a.length;i++) System.out.print(a[i]+" "); }
}
class Main{
public static void main(String[] args) {
int [] array1= {1,5,7,9};
int [] array2= {3,6,-1,100,77};
int [] array3 =ArrayUtil.concat(array1,array2);
ArrayUtil.print(array3);
}
}
*/
/*
import java.util.*;
class Player{
Scanner sc=new Scanner(System.in);
String name;
String getWord;
int lastIndex;
static boolean flag=true;
char lastChar;
char firstChar;
public Player(String name) {
this.name=name;
lastChar=' ';
}
public void getWord(){
getWord=sc.next();
lastIndex=getWord.length()-1;
lastChar=getWord.charAt(lastIndex);
firstChar=getWord.charAt(0);
}
public void checkSuccess() {
System.out.println(name+" losed the game");
flag=false;
}
}
class Main{
Scanner sc=new Scanner(System.in);
int k;
Player[] arr;
public void run(){
System.out.println("끝말잇기 게임을 시작합니다...");
System.out.print("게임에 참가하는 인원은 몇명입니까 >> ");
k=sc.nextInt();
arr=new Player[100];
for(int i=0;i<k;i++)
{
System.out.print("참가자의 이름을 입력하세요 >> ");
String word=sc.next();
arr[i]=new Player(word);
}
System.out.println("시작하는 단어는 아버지입니다");
while(true) {
for(int i=0;i<k;i++) {
if(Player.flag==false)
{
System.exit(0);
}
else if(i==0&&arr[(i+k-1)%k].lastChar==' ')
{
System.out.print(arr[i].name+">>"); //arr[(i+k-1)%k].lastChar
arr[i].getWord();
arr[(i+k-1)%k].lastChar='지';
if(arr[i].firstChar!=arr[(i+k-1)%k].lastChar)
{
arr[i].checkSuccess();
}
}
else
{
System.out.print(arr[i].name+">>"); //arr[(i+k-1)%k].lastChar
arr[i].getWord();
if(arr[i].firstChar!=arr[(i+k-1)%k].lastChar)
{
arr[i].checkSuccess();
}
}
}
}
}
public static void main(String[] args) {
Main m = new Main();
m.run();
}
}
import java.util.*;
class Cal{
int a,b;
public void setValue(int a,int b) {
this.a=a;
this.b=b;
}
public int calculate() {
return a;
}
}
class Add extends Cal{
public int calculate() { //overriding 덮어쓰기 (재정의)
return a+b;
}
}
class Sub extends Cal{
public int calculate() {
return a-b;
}
}
class Mul extends Cal{
public int calculate(){
return a*b;
}
}
class Div extends Cal{
public int calculate() {
return a/b;
}
}
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a,b;
String c;
System.out.print("두 정수와 연산자를 입력하시오 >> ");
a=sc.nextInt();
b=sc.nextInt();
c=sc.next();
Cal ob;
if(c.equals("+")) {
ob = new Add();
}
else if(c.equals("-")) {
ob = new Sub();
}
else if(c.equals("*")) {
ob = new Mul();
}
else{
ob = new Div();
}
ob.setValue(a, b);
System.out.println(ob.calculate());
}
}
상속 : extends 확장하다
super class 수퍼클래스 부모클래스
sub class 서브클래스 자식클래스
부모클래스의 필드, 메소드는 전부 상속된다 .
*/
/*
class Person{
private int age;
String name;
String school;
public void setAge(int age)
{
this.age=age;
}
public void view() {
System.out.println(age +" "+name+" "+school);
}
}
class Student extends Person{
char grade;
}
class EStudent extends Student{
}
class Teacher extends Person{
String subject;
}
*/
/*
class Point{
private int x,y;
// public Point() {
// x=100;y=100;
// System.out.println("point의 생성자");
// }
public Point(int x,int y) {
this.x=x;
this.y=y;
}
public void showPoint() {
System.out.println("("+x+","+y+")");
}
}
class ColorPoint extends Point{
private String color;
public ColorPoint() {
super(50,50);
System.out.println("colorpoint의 생성자");
}
public void setColor(String color) {
this.color = color;
}
public void showColorPoint() {
System.out.print(color);
showPoint();
}
}
public class Main {
public static void main(String[] args) {
// Point p = new Point();
// p.showPoint();
//
// Point p1 = new Point(10,10);
// p1.showPoint();
ColorPoint cp= new ColorPoint();
cp.showPoint();
}
}
*/
/*
class Point{
private int x,y;
public Point() {
this.x=this.y=0;
}
public Point (int x,int y) {
this.x=x;
this.y=y;
}
public void showPoint() {
System.out.println("("+x+","+y+")");
}
}
class ColorPoint extends Point{
private String color;
public ColorPoint(int x,int y, String color) {
super(x,y);
this.color=color;
}
public void showColorPoint() {
System.out.print(color);
showPoint();
}
}
public class Main{
public static void main(String[] args) {
ColorPoint cp = new ColorPoint(5,6,"blue");
cp.showColorPoint();
}
}
*/
/*
class A{
public A() {
System.out.println("생성자A");
}
public A(int x) {
System.out.println("매개변수생성자A"+x);
}
}
class B extends A{
public B() {
super(30);
System.out.println("생성자B");
}
public B(int x) {
System.out.println("매개변수생성자B" +x);
}
}
public class Main{
public static void main(String[] args) {
B b;
b=new B();
}
}
*/
/*
1. super()
2. 매개변수생성자A30
생성자B
3. super 가 첫째줄에 있지 않다.
*/
/*
class TV{
private int size;
public TV(int size) {
this.size=size;
}
protected int getSize() {
return size;
}
}
class ColorTV extends TV{
int color;
public ColorTV(int size,int color) {
super(size);
this.color=color;
}
public void printProperty() {
System.out.println(getSize()+"인치 "+color+"컬러");
}
}
public class Main{
public static void main(String[] args) {
ColorTV myTV= new ColorTV(32,1024);
myTV.printProperty();
}
}
*/
/*
class TV{
private int size;
public TV(int size) {
this.size=size;
}
protected int getSize() {
return size;
}
}
class ColorTV extends TV{
private int color;
public ColorTV(int size, int color) {
super(size);
this.color=color;
}
protected int getColor() {
return color;
}
}
class IPTV extends ColorTV{
private String IP;
public IPTV(String IP,int size,int color) {
super(size,color);
this.IP=IP;
}
public void printProperty() {
System.out.println("나의 IPTV는 "+IP+" 주소의 "+getSize()+"인치 "+getColor()+"컬러");
}
}
public class Main{
public static void main(String[] args) {
IPTV iptv = new IPTV("192.1.1.2",32,2048);
iptv.printProperty();
}
}
*/
/*
class Point{
public Point(int x,int y) {
this.x=x;
this.y=y;
}
public int getX(){
return x;
}
public int getY() {
return y;
}
protected void move(int x,int y) {
this.x=x;
this.y=y;
}
}
class ColorPoint extends Point{
private String color;
private int x,y;
public ColorPoint(int x,int y,String color) {
super(x,y);
this.color=color;
}
public String getColor() {
return color;
}
public void setXY(int x,int y) {
move(x,y);
}
public void setColor(String color) {
this.color=color;
}
public String toString(){
return color+"색의"+" ("+x+","+y+")의 점";
}
}
public class Main{
public static void main(String[] args) {
ColorPoint cp = new ColorPoint(5,5,"YELLOW");
cp.setXY(10, 20);
cp.setColor("RED");
String str = cp.toString();
System.out.println(str+"입니다.");
}
}
*/
/*
class Point {
private int x,y;
public Point(int x,int y) {
this.x=x;
this.y=y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
protected void move(int x,int y) {
this.x=x;
this.y=y;
}
}
class ColorPoint extends Point{
private String color;
public ColorPoint() {
super(0,0);
color = "BLACK";
}
public ColorPoint(int x,int y) {
super(x,y);
}
public void setXY(int x,int y) {
move(x,y);
}
public void setColor(String color) {
this.color=color;
}
public String toString() {
return color+"색의 "+"("+getX()+","+getY()+")의 점";
}
}
public class Main{
public static void main(String[] args) {
ColorPoint zeroPoint = new ColorPoint();
System.out.println(zeroPoint.toString()+"입니다.");
ColorPoint cp =new ColorPoint(10,10);
cp.setXY(5, 5);
cp.setColor("RED");
System.out.println(cp.toString()+"입니다.");
}
}
추상클래스 : 슈퍼클래스로서의 역할만 수행. 객체를 생성할 수 없다.
abstract
*/
/*
abstract class Point {
private int x,y;
int a;
public Point(int x,int y) {
this.x=x;
this.y=y;
}
abstract public void setA(int a);
public int getX(){
return x;
}
public int getY() {
return y;
}
protected void move(int x,int y) {
this.x=x;
this.y=y;
}
}
class Point3D extends Point{
private int z;
public Point3D(int x,int y,int z) {
super(x,y);
this.z=z;
}
public int getZ() {
return z;
}
public void moveup() {
z++;
}
public void movedown() {
z--;
}
public String toString() {
return "("+getX()+","+getY()+","+getZ()+")의 점";
}
public void move(int x, int y, int z) {
super.move(x, y);
this.z=z;
}
}
public class Main{
public static void main(String[] args) {
Point3D p = new Point3D(1,2,3);
System.out.println(p.toString()+"입니다.");
p.moveup();
System.out.println(p.toString()+"입니다.");
p.movedown();
p.move(10, 10);
System.out.println(p.toString()+"입니다.");
p.move(100, 200, 300);
System.out.println(p.toString()+"입니다.");
}
}*/
/*
import java.util.*;
abstract class Convertor{
abstract protected double convert(double src);
abstract protected String getSrcString();
abstract protected String getDestString();
protected double ratio;
public void run() {
Scanner sc=new Scanner(System.in);
System.out.println(getSrcString()+"을 "+getDestString()+"로 바꿉니다.");
System.out.print(getSrcString()+"을 입력하세요>> ");
double val =sc.nextDouble();
double res=convert(val);
System.out.println("변환 결과: "+res+getDestString()+"입니다");
sc.close();
}
}
class Won2Dollar extends Convertor {
public Won2Dollar(double ratio) {
this.ratio=ratio;
}
@Override
protected double convert(double val) {
return val/ratio;
}
@Override
protected String getSrcString() {
return "원";
}
@Override
protected String getDestString() {
return "달러";
}
}
public class Main{
public static void main(String[] args) {
Won2Dollar toDollar = new Won2Dollar(1200);
toDollar.run();
}
}
*/
/*
import java.util.*;
abstract class Convertor{
abstract protected double convert(double src);
abstract protected String getSrcString();
abstract protected String getDestString();
protected double ratio;
public void run() {
Scanner sc = new Scanner(System.in);
System.out.println(getSrcString()+"을 "+getDestString()+"로 바꿉니다.");
System.out.print(getSrcString()+"을 입력하세요>> ");
double val=sc.nextDouble();
double res=convert(val);
System.out.println("변환 결과: "+res+getDestString()+" 입니다");
sc.close();
}
}
class Km2Mile extends Convertor{
public Km2Mile(double ratio) {
this.ratio=ratio;
}
@Override
protected double convert(double val) {
return val/ratio;
}
@Override
protected String getSrcString() {
return "Km";
}
@Override
protected String getDestString() {
return "mile";
}
}
public class Main{
public static void main(String[] args) {
Km2Mile toMile = new Km2Mile(1.6);
toMile.run();
}
}
*/
/*
interface Person{
abstract void speak();
abstract void sleep();
}
interface Korean extends Person{
abstract void hello();
}
class Student implements Korean{
@Override
public void speak() {
System.out.println("저는 학생입니다!");
}
@Override
public void sleep() {
System.out.println("학생이예요 졸려요.. ");
}
@Override
public void hello() {
}
}
*/
/*
import java.util.*;
abstract class Calc{
int a,b;
public void setvalue(int a, int b) {
this.a=a;
this.b=b;
}
public int Calculate() {
return 0;
}
}
class Add extends Calc{
public int Calculate() { return a+b;}
}
class Sub extends Calc{
public int Calculate() { return a-b;}
}
class Mul extends Calc{
public int Calculate() { return a*b;}
}
class Div extends Calc{
public int Calculate() { return a/b;}
}
public class Main{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
Calc calc;
int a,b;
String c;
System.out.print("두 정수와 연산자를 입력하시오>> ");
a=sc.nextInt();
b=sc.nextInt();
c=sc.next();
if(c.equals("+")) {
calc= new Add();
}
else if(c.equals("-")) {
calc= new Sub();
}
else if(c.equals("*")) {
calc= new Mul();
}
else
{
calc= new Div();
}
calc.setvalue(a, b);
System.out.println(calc.Calculate());
}
}
*/
/*
import java.util.*;
abstract class Shape {
private Shape next;
public Shape() { next = null; }
public void setNext(Shape obj) { next = obj; }
public Shape getNext() { return next; }
public abstract void draw();
}
class Line extends Shape{
@Override
public void draw() {
}
}
class Rect extends Shape{
@Override
public void draw() {
}
}
class Circle extends Shape{
@Override
public void draw() {
}
}
public class Main{
Scanner sc =new Scanner(System.in);
static boolean flag= true;
Shape ob;
int k;
public void input() {
System.out.print("Line(1), Rect(2), Circle(3) >> ");
k=sc.nextInt();
Shape next;
if(k==1) next = new Line();
else if(k==2) next = new Rect();
else next = new Circle();
while(ob.getNext()!=null) {
ob=ob.getNext();
}
ob.setNext(next);
}
public void delete() {
}
public void view() {
}
public void finish() {
flag= false;
System.out.println("beauty을 종료합니다.");
System.exit(0);
}
public static void main(String[] args) {
Main m= new Main();
Scanner sc =new Scanner(System.in);
String k;
System.out.println("그래픽 에디터 beauty을 실행합니다.");
while(flag==true) {
System.out.print("삽입(1), 삭제(2), 모두 보기(3), 종료(4) >> ");
k=sc.next();
if(k.equals("1")) {
m.input();
}
else if(k.equals("2")) {
m.delete();
}
else if(k.equals("3")) {
m.view();
}
else {
m.finish();
}
}
}
}
*/
/*import java.util.Scanner;
import java.util.*;
abstract class Shape {
private Shape next;
public Shape() { next = null; }
public void setNext(Shape obj) { next = obj; }
public Shape getNext() { return next; }
public abstract void draw();
}
class Line extends Shape{
@Override
public void draw() {
System.out.println("Line");
}
}
class Rect extends Shape{
@Override
public void draw() {
System.out.println("Rect");
}
}
class Circle extends Shape{
@Override
public void draw() {
System.out.println("Circle");
}
}
public class Main{
Scanner sc =new Scanner(System.in);
static boolean flag= true;
Shape st,ob;
int k;
public void input() {
System.out.print("Line(1), Rect(2), Circle(3) >> ");
k=sc.nextInt();
Shape next;
if(k==1) {next = new Line();}
else if(k==2) {next = new Rect();}
else {next = new Circle();}
if(st==null) {
st=next;
ob=next;
return ;
}
while(ob.getNext()!=null) {
ob=ob.getNext();
}
ob.setNext(next);
}
public void delete() {
System.out.print("삭제할 도형의 위치 >> ");
k=sc.nextInt();
for(int i=1;i<=k; i++) {
if(i==k) {
if(ob.getNext()==null) {System.out.println("삭제할 수 없습니다.");}
else {ob.setNext(null);}
}
}
}
public void view() {
Shape v = st;
while(v.getNext()!=null) {
v.draw();
v=v.getNext();
}
}
public void finish() {
flag= false;
System.out.println("beauty을 종료합니다.");
System.exit(0);
}
public static void main(String[] args) {
Main m= new Main();
Scanner sc =new Scanner(System.in);
String k;
System.out.println("그래픽 에디터 beauty을 실행합니다.");
while(flag==true) {
System.out.print("삽입(1), 삭제(2), 모두 보기(3), 종료(4) >> ");
k=sc.next();
if(k.equals("1")) {
m.input();
}
else if(k.equals("2")) {
m.delete();
}
else if(k.equals("3")) {
m.view();
}
else {
m.finish();
}
}
}
}
*/
/*
import java.util.*;
class Point{
int x, y;
public String toString() {
String str = x + "," +y+"의 점 입니다.";
return str;
}
public boolean equals(Object ob) { //객체를 비교할때 어떤 필드?가 같으면 객체가 같은건지 판단하고싶을때
Point o = (Point)ob;
if(x==o.x && y==o.y) return true;
else return false;
}
}
class Main{
public static void main(String[] args) {
Point p = new Point();
Point q = new Point();
q.x=10;q.y=20;
p.x=10;p.y=20;
System.out.println(Integer.toHexString(p.hashCode()));
System.out.println(p.toString());
System.out.println("equals : " + p.equals(q));
System.out.println("== : "+ (p==q));
Scanner sc =new Scanner(System.in);
String s = "hello";
String t = sc.next();
System.out.println("equals : " + s.equals(t)) System.out.println("== : "+ (s==t));
int a = 100;
String sa = Integer.toString(a); //정수 a 를 문자열 sa로 변환
System.out.println(sa+3);
int b = Integer.valueOf(sa);//문자열 sa를 정수 b로 변환
System.out.println(b+3);
double c = Double.parseDouble("3.14"); //문자열 "3.14"를 실수 3.14로 변환
System.out.println(c+0.1);
String str1;
String str = " he llo mel loj ell o ";
str1 = str.replace('l', '1');
str = str.trim();
String[] sarr = str.split(" ");
for(int i=0;i<sarr.length;i++) {
System.out.println("sarr["+i+"] : "+ sarr[i]);
double p;
p = Math.abs(-3.14);
p = Math.random()*100;
System.out.println((int)p);
p = Math.min(3.14, 2.0);
System.out.println(p);
}
}
*/
/*
import java.util.*;
ic boolean flag= true;
static int kc=0,cs=0;
public void S() {
if(kc==1) cs=1;
else if(kc==2) cs=3;
else cs=2;
checkSuccess();
}
public void R() {
if(kc==1) cs=2;
else if(kc==2) cs=1;
else cs=3;
checkSuccess();
}
public void P() {
if(kc==1) cs=3;
else if(kc==2) cs=2;
else cs=1;
checkSuccess();
}
public void finish() {
flag=false;
System.exit(0);
}
public void checkSuccess() {
if(cs==1) System.out.println("비겼습니다.");
else if(cs==2) System.out.println("철수가 이겼습니다.");
else System.out.println("컴퓨터가 이겼습니다.");
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
Main m= new Main();
int k;
String w;
while(flag==true) {
System.out.print("철수[가위(1), 바위(2), 보(3), 끝내기(4)] >> ");
k=sc.nextInt();
kc= (int)(Math.random()*3)+1;
if(kc==1) {
w="가위";
}
else if(kc==2)
{
w="바위";
}
else
{
w="보";
}
if(k==1) {
System.out.println("철수(가위) : 컴퓨터("+w+")");
m.S();
}
else if(k==2) {
System.out.println("철수(바위) : 컴퓨터("+w+")");
m.R();
}
else if(k==3) {
System.out.println("철수(보) : 컴퓨터("+w+")");
m.P();
}
else {
m.finish();
}
}
}
}
*/
/*
import java.util.*;
class Person{
Scanner sc= new Scanner(System.in);
static boolean flag=true;
private String name;
int r1,r2,r3;
String k;
public Person(String name) {
this.name=name;
}
public String getName() {
return name;
}
public void run(){
k=sc.nextLine();
System.out.print("["+getName()+"]:<Enter> ");
r1=(int)(Math.random()*3)+1;
r2=(int)(Math.random()*3)+1;
r3=(int)(Math.random()*3)+1;
if(r1==r2&&r2==r3) {
System.out.println("\n"+" "+r1+" "+r2+" "+r3+" ["+getName()+"]님이 이겼습니다!");
flag=false;
}
else {
System.out.println("\n"+" "+r1+" "+r2+" "+r3+" 아쉽군요!");
}
}
}
public class Main{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.print("1번째 선수 이름>>");
Person p1 = new Person(sc.next());
System.out.print("2번재 선수 이름>>");
Person p2 = new Person(sc.next());
while(Person.flag==true) {
p1.run();
p2.run();
}
}
}
UI User Interface
CUI
GUI Graphical User Interface
import javax.swing.*;
import java.awt.*; //container
class Main extends JFrame{
public Main() {
setTitle("GUI FRAME EXAMPLE");
setSize(500,300);
setVisible(true);
Container c = getContentPane(); //c=현재 배경 프레임
//layout 배치관리자
// c.setLayout(new FlowLayout());
//
// for(int i=0;i<10;i++) {
// JButton b1 = new JButton("button1"); //버튼 객체 생성
// c.add(b1);
// }
c.setLayout(new BorderLayout());
JButton b1 = new JButton("button1");
b1.setBackground(Color.green); //배경색 설정
b1.setForeground(Color.RED); //글자색 설정
c.add(b1,BorderLayout.CENTER);
JButton b2 = new JButton("button2");
c.add(b2,BorderLayout.EAST);
JTextField tf = new JTextField();
c.add(tf,BorderLayout.SOUTH);
// JButton b2 = new JButton("button2"); //버튼 객체 생성
// c.add(b2);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main(){
setTitle("ContentPane과 JFrame");
setSize(500,500);
Container c= getContentPane();
c.setLayout(new FlowLayout());
JButton Ok= new JButton("OK");
JButton Cancel= new JButton("Cancel");
JButton Ignore= new JButton("Ignore");
c.add(Ok);
c.add(Cancel);
c.add(Ignore);
c.setBackground(Color.orange);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main() {
setTitle("BorderLayout Sample");
Container c= getContentPane();
c.setLayout(new BorderLayout(30,20));
JButton add=new JButton("add");
JButton calculate= new JButton("Calculate");
JButton div= new JButton("div");
JButton mul= new JButton("mul");
JButton sub= new JButton("sub");
c.add(add,BorderLayout.NORTH);
c.add(calculate,BorderLayout.EAST);
c.add(sub,BorderLayout.SOUTH);
//c.add(div,BorderLayout.WEST);
//c.add(mul,BorderLayout.EAST);
JPanel p = new JPanel();
p.setLayout(null); // setSize, setLocation 필수!!
// p.setLayout(new GridLayout(3,2,2,2));
for(int i=0;i<6;i++) {
JButton b = new JButton(Integer.toString(i));
p.add(b);
b.setSize(50, 50);
b.setLocation(i*50, i*50);
}
p.setBackground(Color.orange);
c.add(p,BorderLayout.CENTER);
c.setBackground(Color.BLACK);
setSize(500,500);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main(){
setTitle("Let's study Java");
setSize(400,200);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main() {
setTitle("BorderLayout Practice");
Container c= getContentPane();
c.setLayout(new BorderLayout(5,7));
JButton North= new JButton("North");
JButton South= new JButton("South");
JButton East= new JButton("East");
JButton West= new JButton("West");
JButton Center= new JButton("Center");
c.add(North,BorderLayout.NORTH);
c.add(South,BorderLayout.SOUTH);
c.add(East,BorderLayout.EAST);
c.add(West,BorderLayout.WEST);
c.add(Center,BorderLayout.CENTER);
setSize(400,200);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main() {
setTitle("Ten Color Buttons Frame");
JPanel p= new JPanel();
Container c= getContentPane();
p.setLayout(null);
for(int i=0;i<10;i++) {
JButton b= new JButton(Integer.toString(i));
p.add(b);
b.setSize(50,800);
b.setLocation(i*50,0);
}
c.add(p,BorderLayout.CENTER);
setSize(500,800);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main() {
setTitle("Ten Color Buttons Frame");
JPanel p= new JPanel();
Container c= getContentPane();
Color[] colors = {Color.BLUE, Color.GREEN, Color.MAGENTA, Color.gray,Color.orange,Color.pink,Color.red,Color.white,Color.yellow,Color.cyan};
p.setLayout(null);
for(int i=0;i<10;i++) {
JButton b= new JButton(Integer.toString(i));
p.add(b);
b.setBackground(colors[i]);
b.setSize(50,800);
b.setLocation(i*50,0);
}
c.add(p,BorderLayout.CENTER);
setSize(500,800);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main() {
Container c= getContentPane();
c.setLayout(null);
setTitle("Random Labels");
setBackground(Color.BLUE);
for(int i=0;i<20;i++) {
JLabel Label= new JLabel(Integer.toString(i));
int x= (int)(Math.random()*200)+50;
int y= (int)(Math.random()*200)+50;
c.add(Label);
Label.setBackground(Color.blue);
Label.setLocation(x,y);
Label.setSize(10,10);
Label.setOpaque(true);
}
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/* ****************************이거 나중에 또 해야 됨******************************************
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main() {
setTitle("계산기 프레임");
Container c= getContentPane();
c.setLayout(new BorderLayout());
JPanel p1= new JPanel();
JPanel p2= new JPanel();
JPanel p3= new JPanel();
c.add(p1,BorderLayout.NORTH);
c.add(p2,BorderLayout.CENTER);
c.add(p3,BorderLayout.SOUTH);
p1.setBackground(Color.GRAY);
p2.setBackground(Color.WHITE);
p3.setBackground(Color.YELLOW);
p1.setLayout(new FlowLayout());
p2.setLayout(new GridLayout(4,4));
p3.setLayout(new FlowLayout());
p1.add(new JLabel("수식입력"));
p1.add(new JTextField(10));
p3.add(new JLabel("계산 결과"));
p3.add(new JTextField(10));
JButton b;
for(int i=0;i<10;i++)
{
b = new JButton(Integer.toString(i));
p2.add(b);
}
b = new JButton("CE"); p2.add(b);
b = new JButton("계산"); p2.add(b);
b = new JButton("+"); p2.add(b); b.setBackground(Color.CYAN);
b = new JButton("-"); p2.add(b); b.setBackground(Color.CYAN);
b = new JButton("x"); p2.add(b); b.setBackground(Color.CYAN);
b = new JButton("/"); p2.add(b); b.setBackground(Color.CYAN);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/* ****************************이거 나중에 또 해야 됨******************************************
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main() {
Container c= getContentPane();
c.setLayout(new BorderLayout());
setTitle("여러 개의 패널을 가진 프레임");
JPanel p1= new JPanel();
JPanel p2= new JPanel();
JPanel p3= new JPanel();
c.add(p1,BorderLayout.NORTH);
c.add(p2,BorderLayout.CENTER);
c.add(p3,BorderLayout.SOUTH);
p1.setBackground(Color.GRAY);
p2.setBackground(Color.WHITE);
p3.setBackground(Color.YELLOW);
p1.setLayout(new FlowLayout());
p2.setLayout(null);
p3.setLayout(new FlowLayout());
JButton open= new JButton("열기");
JButton close= new JButton("닫기");
JButton leave= new JButton("나가기");
p1.add(open);
p1.add(close);
p1.add(leave);
for(int i=0;i<20;i++) {
JLabel Label= new JLabel("*");
int x= (int)(Math.random()*200)+50;
int y= (int)(Math.random()*200)+50;
p2.add(Label);
Label.setForeground(Color.RED);
Label.setLocation(x,y);
Label.setSize(10,10);
}
JButton inputWordb= new JButton("World Input");
JTextField inputWord= new JTextField(10);
p3.add(inputWordb);
p3.add(inputWord);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
class Main extends JFrame{
public Main() {
setTitle("Open Challenge 9");
Container c =getContentPane();
c.setLayout(new BorderLayout());
JPanel p1= new JPanel();
JPanel p2= new JPanel();
p1.setBackground(Color.GRAY);
p2.setBackground(Color.LIGHT_GRAY);
c.add(p1,BorderLayout.NORTH);
c.add(p2,BorderLayout.CENTER);
p1.setLayout(new FlowLayout());
p2.setLayout(null);
String[] Bnames = {"Open","Read","Close"};
JButton[] btns = new JButton[3];
for(int i=0;i<3;i++) {
btns[i]= new JButton(Bnames[i]);
p1.add(btns[i]);
}
String[] Lnames = {"Hello","Java","Love"};
JLabel[] lbels= new JLabel[3];
for(int i=0;i<3;i++) {
int x;
int y;
lbels[i]= new JLabel(Lnames[i]);
p2.add(lbels[i]);
x=(int)(Math.random()*200);
y=(int)(Math.random()*200);
lbels[i].setLocation(x,y);
lbels[i].setSize(60,60);
}
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
event : 어떤 사건 ex) 버튼을 누른다, 버튼을 누른걸 뗐을때, 마우스로 클릭, 키보드 입력, 마우스 드래그됐을때, ....
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class Main extends JFrame{
JLabel[] lbels= new JLabel[3];
JPanel p2= new JPanel();
public Main() {
setTitle("Open Challenge 9");
Container c =getContentPane();
c.setLayout(new BorderLayout());
JPanel p1= new JPanel();
c.add(p1,BorderLayout.NORTH);
c.add(p2,BorderLayout.CENTER);
p1.setLayout(new FlowLayout());
p2.setLayout(null);
JButton btns = new JButton("Reset");
btns.addActionListener(new MyActionListener()); ///액션리스너 객체 생성해서 버튼에 붙여주기
p1.add(btns);
String[] Lnames = {"Hello","Java","Love"};
for(int i=0;i<3;i++) {
int x;
int y;
lbels[i]= new JLabel(Lnames[i]);
p2.add(lbels[i]);
x=(int)(Math.random()*150);
y=(int)(Math.random()*150);
lbels[i].setLocation(x,y);
lbels[i].setSize(60,60);
}
setSize(300,300);
setVisible(true);
}
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
for(int i=0;i<3;i++) {
lbels[i].setLocation((int)(Math.random()*150),(int)(Math.random()*150));
int ci=(int)(Math.random()*5);
Color colors[]= {Color.red,Color.orange,Color.yellow,Color.green,Color.blue,Color.CYAN};
p2.setBackground(colors[ci]);
}
//JButton b = (JButton)e.getSource();
//b.setText("clicked");
//b.setBackground(Color.red);
//System.out.println("버튼이 클릭 되었음");
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Main extends JFrame{
private JLabel la = new JLabel("Hello");
public Main() {
setTitle("Mouse 이벤트 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c= getContentPane();
c.addMouseListener(new MyMouseListener());
c.setBackground(Color.CYAN);
c.setLayout(null);
la.setSize(50,20);
la.setLocation(30,30);
c.add(la);
setSize(250,250);
setVisible(true);
}
class MyMouseListener extends MouseAdapter{
public void MousePressed(MouseEvent e) {
}
// public void mousePressed(MouseEvent e) {
// Point p = e.getPoint();
// la.setLocation(p);
// }
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame{
private JLabel [] keyMessage;
public Main() {
setTitle("keyListener 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c= getContentPane();
c.setLayout(new FlowLayout());
c.addKeyListener(new MyKeyListener());
keyMessage= new JLabel[3];
keyMessage[0]=new JLabel(" getKeyCode() ");
keyMessage[1]=new JLabel(" getKeyChar() ");
keyMessage[2]=new JLabel(" getKeyText() ");
for(int i=0;i<keyMessage.length;i++) {
c.add(keyMessage[i]);
keyMessage[i].setOpaque(true);
keyMessage[i].setBackground(Color.YELLOW);
}
setSize(300,150);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
//implements KeyListener
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int keyCode =e.getKeyCode();
char keyChar=e.getKeyChar();
keyMessage[0].setText(Integer.toString(keyCode));
keyMessage[1].setText(Integer.toString(keyChar));
keyMessage[2].setText(KeyEvent.getKeyText(keyCode));
System.out.println("KeyPressed");
}
public void keyTyped(KeyEvent e) {
System.out.println("KeyReleased");
}
public void keyReleased(KeyEvent e) {
System.out.println("KeyTyped");
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
JLabel F1= new JLabel("F1키가 입력되었음");
JLabel Percent= new JLabel("%키가 입력되었음");
Container c= getContentPane();
public Main() {
setTitle("Key Code 예제 : F1키:초록색, %키(Shift+5):노랑색");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new FlowLayout());
c.addKeyListener(new MykeyListener());
setSize(300,150);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
public static void main(String[] args) {
new Main();
}
class MykeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int keyCode= e.getKeyCode();
char keyChar=e.getKeyChar();
if(keyCode==112) {
c.remove(Percent);
c.setBackground(Color.GREEN);
c.add(F1);
c.revalidate();
}
if(keyChar=='%') {
c.remove(F1);
c.setBackground(Color.YELLOW);
c.add(Percent);
c.revalidate();
}
}
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
private JLabel point= new JLabel("");
private JLabel Hello= new JLabel("Hello");
private JButton setColor=new JButton("setColor");
int i;
Color colors []= {Color.blue,Color.CYAN,Color.RED,Color.ORANGE};
Container c= getContentPane();
public Main() {
setTitle("상,하,좌,우 키를 이용하여 텍스트를 이동시키기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(null);
c.add(Hello);
c.add(setColor);
c.add(point);
point.setSize(100, 50);
point.setLocation(800, 50);
setColor.setSize(100,50);
setColor.setLocation(500, 50);
Hello.setSize(100, 50);
Hello.setLocation(0, 0);
setColor.addActionListener(new myActionListener());
c.addKeyListener(new MyKeyListener());
setSize(1920,1080);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int keyCode= e.getKeyCode();
char keyChar= e.getKeyChar();
int x=Hello.getX();
int y=Hello.getY();
Font f = Hello.getFont();
int size = f.getSize();
System.out.println(size);
if(keyChar=='+'&&size+5<43) {
Hello.setFont(new Font("Arial",Font.PLAIN,size+5));
return ;
}
else if(keyChar=='-') {
Hello.setFont(new Font("Arial",Font.PLAIN,size-5));
return ;
}
if(keyCode==KeyEvent.VK_UP && y>0) {
Hello.setLocation(x,y-20);
}
else if(keyCode==KeyEvent.VK_DOWN && y<1060) {
Hello.setLocation(x,y+20);
}
else if(keyCode==KeyEvent.VK_LEFT&&x>0) {
Hello.setLocation(x-20,y);
}
else if(keyCode==KeyEvent.VK_RIGHT&&x<1885) {
Hello.setLocation(x+20,y);
}
point.setText("("+Hello.getX()+","+Hello.getY()+")");
}
}
class myActionListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
Hello.setForeground(Color.RED);
c.setFocusable(true);
c.requestFocus();
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
private JLabel la = new JLabel("No Mouse Event");
public Main(){
setTitle("MouseListener와 MouseMotionListener 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c= getContentPane();
c.setLayout(new FlowLayout());
MyMouseListener listener= new MyMouseListener();
c.addMouseListener(listener);
c.addMouseMotionListener(listener);
c.add(la);
setSize(300,200);
setVisible(true);
}
class MyMouseListener extends MouseAdapter implements MouseMotionListener{
public void mouseDragged(MouseEvent e) {
la.setText("MouseDragged ("+e.getX()+","+e.getY()+")");
}
public void mouseMoved(MouseEvent e) {
la.setText("MouseMoved ("+e.getX()+","+e.getY()+")");
}
public void mousePressed(MouseEvent e) {
la.setText("mousePressed ("+e.getX()+","+e.getY()+")");
}
public void mouseReleased(MouseEvent e) {
la.setText("MouseReleased ("+e.getX()+","+e.getY()+")");
}
public void mouseEntered(MouseEvent e) {
Component c= (Component)e.getSource();
c.setBackground(Color.CYAN);
}
public void mouseExited(MouseEvent e) {
Component c=(Component)e.getSource();
c.setBackground(Color.YELLOW);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class Main extends JFrame{
public Main() {
setTitle("Click and DoubleClick 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c= getContentPane();
c.addMouseListener(new MyMouseListener());
setSize(300,200);
setVisible(true);
}
class MyMouseListener extends MouseAdapter{
public void mouseClicked(MouseEvent e) {
if(e.getClickCount()==2) {
int r=(int)(Math.random()*256);
int g=(int)(Math.random()*256);
int b=(int)(Math.random()*256);
Component c= (Component)e.getSource();
c.setBackground(new Color(r,b,g));
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
JLabel Love= new JLabel("사랑해");
public Main() {
setTitle("마우스를 올리고 내릴때마다 글자 바꾸기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c= getContentPane();
c.setLayout(new FlowLayout());
c.add(Love);
Love.addMouseListener(new MyMouseListener());
setSize(500,500);
setVisible(true);
}
class MyMouseListener extends MouseAdapter{
public void mouseEntered(MouseEvent e) {
Love.setText("Love Java");
}
public void mouseExited(MouseEvent e) {
Love.setText("사랑해");
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
Container c= getContentPane();
public Main() {
setTitle("드래깅 동안 Yellow로 바꾸기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyMouseListener listener= new MyMouseListener();
addMouseMotionListener(listener);
addMouseListener(listener);
c.setBackground(Color.GREEN);
setSize(500,500);
setVisible(true);
}
class MyMouseListener extends MouseAdapter implements MouseMotionListener{
public void mouseMoved(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {
c.setBackground(Color.YELLOW);
}
public void mouseReleased(MouseEvent e) {
c.setBackground(Color.GREEN);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
JLabel LoveJava= new JLabel("Love Java");
public Main() {
setTitle("Left키로 문자열 교체");
Container c= getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.addKeyListener(new myKeyListener());
c.setFocusable(true);
c.requestFocus();
c.setLayout(new FlowLayout());
c.add(LoveJava);
setSize(500,500);
setVisible(true);
}
class myKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int keyCode= e.getKeyCode();
if(keyCode==KeyEvent.VK_LEFT) {
if(LoveJava.getText().equals("Love Java")) {
LoveJava.setText("avaJ evoL");
}
else {
LoveJava.setText("Love Java");
}
}
}
}
public static void main(String[] args) {
new Main();
}
}*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
JLabel la= new JLabel("Love Java");
int i;
public Main() {
setTitle("Left 키로 문자열 이동");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c= getContentPane();
c.setLayout(new FlowLayout());
c.add(la);
c.addKeyListener(new myKeyListener());
c.setFocusable(true);
c.requestFocus();
setSize(300,150);
setVisible(true);
}
class myKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
String str = la.getText();
String a = str.substring(1);
String b = str.substring(0, 1);
int keyCode= e.getKeyCode();
if(keyCode==KeyEvent.VK_LEFT) {la.setText(a+b);}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
JLabel la= new JLabel("Love Java");
public Main() {
setTitle("+,- 키로 폰트 크기 조절");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c= getContentPane();
c.setLayout(new FlowLayout());
c.add(la);
c.addKeyListener(new myKeyListener());
c.setFocusable(true);
c.requestFocus();
setSize(300,300);
setVisible(true);
}
class myKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int keyChar= e.getKeyChar();
Font f= la.getFont();
int size=f.getSize();
if(keyChar=='+') {la.setFont(new Font("Arial",Font.PLAIN,size+5));}
else if(keyChar=='-'&&size-5>4) {la.setFont(new Font("Arial",Font.PLAIN,size-5));}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
JLabel la = new JLabel("C");
public Main() {
setTitle("클릭 연습 용 응용프로그램");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c= getContentPane();
c.setLayout(null);
c.add(la);
la.setSize(10,10);
la.setLocation(100,100);
la.addMouseListener(new myMouseListener());
la.setFocusable(true);
la.requestFocus();
setSize(500,500);
setVisible(true);
}
class myMouseListener implements MouseListener{
@Override
public void mouseClicked(MouseEvent e) {
int x=(int)(Math.random()*470);
int y=(int)(Math.random()*470);
la.setLocation(x,y);
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
JLabel la= new JLabel("Love Java");
public Main() {
setTitle("마우스 휠을 굴려 폰트 크기 조절");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c= getContentPane();
c.setLayout(new FlowLayout());
c.add(la);
la.addMouseWheelListener(new myMouseWheelListener());
la.setFocusable(true);
la.requestFocus();
setSize(500,500);
setVisible(true);
}
class myMouseWheelListener implements MouseWheelListener{
public void mouseWheelMoved(MouseWheelEvent e) {
int n= e.getWheelRotation();
Font f= la.getFont();
int size=f.getSize();
if(n<0) {
la.setFont(new Font("Arial",Font.PLAIN,size+5));
return ;
}
else if(n>0&&size-5 >4) {
la.setFont(new Font("Arial",Font.PLAIN,size-5));
return ;
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Main extends JFrame{
public Main() {
setTitle("레이블 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c= getContentPane();
c.setLayout(new FlowLayout());
JLabel textLabel= new JLabel("사랑합니다.");
ImageIcon beauty = new ImageIcon("images/heart.png")
}
public static void main(String[] args) {
new Main();
}
}