/*
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int i,j;
int[][] arr = new int[n][n];
for(i=0; i<n; i++)
{
arr[i][0] = sc.nextInt();
}
for(i=1; i<n; i++)
{
for(j=1; j<=i; j++)
{
arr[i][j] = arr[i][j-1] - arr[i-1][j-1];
}
}
for(i=0; i<n; i++)
{
for(j=0; j<=i; j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println(" ");
}
}
}
*/
/*
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int i,sum=0;
for(i=a; i<=b; i++)
{
if(i%2==0)
{
sum -= i;
}
else
{
sum += i;
}
}
System.out.println(sum);
}
}
*/
/*
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int i,j,k,sum=0,dec=0;
for(k=a; k<=b; k++)
{
for(i=1; i<=9; i++)
{
System.out.println(k+"*"+i+"="+(k*i));
}
}
}
}
20220918
클래스 : 틀 ( 필드 + 생성자 + 메소드)
객체 : 틀로 찍어낸 물체
import java.util.*;
class Person{
//field 필드
int age;
String name;
//method 메소드 (함수)
void view() {
System.out.println("나이는 "+ age+"이고, 이름은 "+ name+"입니다.");
}
//constructor 생성자 - 객체를 생성할때 필드 값의 초기값을 정해주는 용도
Person(){
age=5000;
name="noname";
}
Person(int a){
age=a;
name="noname";
}
Person(int a, String n){
age=a;
name=n;
}
}
public class Main {
public static void main(String[] args) {
//Scanner sc = new Scanner(System.in);
Person s;
s = new Person();
Person p = new Person(100,"tom");
Person t = new Person(50);
t.view();
p.view();
s.view();
p.age=10; p.name="hello";
s.age=900; s.name="hi";
p.view();
s.view();
//System.out.println("나이는"+ p.age+"이고, 이름은 "+ p.name+"입니다.");
//System.out.println("나이는"+ s.age+"이고, 이름은 "+ s.name+"입니다.");
}
}
*/
/*
class Circle
{
int radius;
String name;
public double getArea()
{
return 3.14*radius*radius;
}
Circle(int r, String n){
radius=r;
name=n;
}
}
class Main{
public static void main(String[] args)
{
// Circle pizza;
// pizza = new Circle();
// pizza.radius = 10;
// pizza.name = "자바피자";
// double area = pizza.getArea();
// System.out.println(pizza.name+"의 면적은"+area);
Circle donut = new Circle(2,"자바도넛");
double area = donut.getArea();
System.out.println(donut.name+"의 면적은"+area);
}
}
*/
/*
import java.util.*;
class Circle {
int radius;
String name;
public Circle() {
radius = 1; name = "";
}
public Circle(int r, String n) {
radius = r; name = n;
}
public double getArea() {
return 3.14*radius*radius;
}
}
class Main{
public static void main(String[]args) {
Circle pizza = new Circle(10, "자바피자");
double area = pizza.getArea();
System.out.println(pizza.name + "의 면적은 " + area);
Circle donut = new Circle();
donut.name = "도넛피자";
area = donut.getArea();
System.out.println(donut.name + "의 면적은 " + area);
}
}
private 다른 클래스에서 접근 할 수 없는 필드, 메소드가 된다
*/
/*
class Song {
private String title;
public Song(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
}
class Main {
public static void main(String[] args) {
Song mySong = new Song("Nessun Dorma");
Song yourSong = new Song("공주는 잠 못 이루고");
System.out.println("내 노래는 " + mySong.getTitle());
System.out.println("너 노래는 " + yourSong.getTitle());
}
}
*/
/*
class Phone {
private String name, 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 {
public static void main(String[] args) {
Phone
}
}
*/
/*
import java.util.*;
class TV {
private String name;
int year;
int size;
public TV(String name,int year,int size)
{
this.name = name;
this.year = year;
this.size = size;
}
public void show()
{
System.out.println(name+"에서 만든 "+year+"년형 "+size+"인치 TV");
}
}
class Main{
public static void main(String [] args)
{
TV myTV = new TV("LG", 2017, 32);
myTV.show();
}
}
*/
/*
import java.util.*;
class Grade {
private int math;
private int science;
private int english;
public Grade(int math,int science,int english)
{
this.math = math;
this.science = science;
this.english = english;
}
public int average()
{
return (math+science+english)/3;
}
}
class Main {
public static void main(String [] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("수학, 과학, 영어 순으로 3개의 정수 입력>>");
Grade me = new Grade(scanner.nextInt(), scanner.nextInt(), scanner.nextInt());
System.out.println("평균은 " + me.average());
}
}
*/
/*
import java.util.*;
class Song {
private String title;
private String country;
private String artist;
private int year;
public Song(int year)
{
this(year,"미정","미정","미정");
}
public Song(int year,String title,String country,String artist)
{
this.title = title;
this.country = country;
this.artist = artist;
this.year = year;
}
public void show()
{
System.out.println(year+"년 "+country+"국적의 "+artist+"가 부른 "+title);
}
}
class Main {
public static void main(String [] args)
{
Song mySong = new Song(1978,"Dancing Queen","스웨덴","ABBA");
Song yourSong = new Song(1945);
mySong.show();
}
}
*/
/*
import java.util.*;
class Book {
String title;
String author;
void show() { System.out.println(title + " " + author); }
public Book() {
this("", "");
System.out.println("생성자 호출됨");
}
public Book(String title) {
this(title, "작자미상");
}
public Book(String title, String author) {
this.title = title;
this.author = author;
}
}
class Main {
public static void main(String [] args) {
Book littlePrince = new Book("어린왕자","생텍쥐페리");
Book loveStory = new Book("춘향전");
Book emptyBook = new Book();
loveStory.show();
}
}
*/
/*
class Samp {
int id;
public Samp(int x) {
this.id = x;
}
public Samp() {
this(0);
System.out.println("생성자 호출");
}
}
class ConstructorExample{
//필드
int x;
//메소드
public void setx(int x) { this.x = x; }
public int getx() { return x; }
//생성자
public ConstructorExample() {
}
public static void main(String [] args) {
ConstructorExample a = new ConstructorExample();
int n = a.getx();
}
}
객체 배열을 생성할때는
1. 레퍼런스 배열의 레퍼런스 생성
2. 레퍼런스 배열 생성
3. 객체 생성해서 레퍼런스에 연결
class Person{
String name;
int age;
}
class Main{
public static void main(String[] args) {
// Person p ;//레퍼런스변수 생성
// p = new Person(); //객체 생성
Person[] arr = new Person[10];
for(int i=0;i<arr.length;i++) {
arr[i] = new Person();
}
arr[0].name="민혁";
}
}
*
*/
/*
import java.util.*;
class Circle {
int radius;
public Circle(int radius) {
this.radius = radius;
}
public double getArea() {
return 3.14*radius*radius;
}
}
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);
for(int i=0; i<c.length; i++)
System.out.println((int)(c[i].getArea()) + " ");
}
}
*/
/*
import java.util.Scanner;
class Book {
String title,author;
public Book(String title,String author) {
this.title = title;
this.author = author;
}
}
class Main{
public static void main(String[] args) {
Book [] book = new Book[2];
Scanner scanner = new Scanner(System.in);
for(int i=0; i<book.length; i++) {
System.out.print("제목>>");
String title = scanner.nextLine();
System.out.print("저자>>");
String author = scanner.nextLine();
book[i] = new Book(title, author);
}
for(int i=0; i<book.length; i++)
System.out.print("(" + book[i].title + ", " + book[i].author + ")");
}
}
*/
/*
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.println("("+x+", "+y+")"+radius);
}
}
class Main {
public static void main(String[] args) {
Scanner scanner = 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 = scanner.nextDouble();
double y = scanner.nextDouble();
int radius = scanner.nextInt();
c[i] = new Circle(x, y, radius);
}
for(int i=0; i<c.length; i++)
c[i].show();
scanner.close();
}
}
import java.util.Scanner;
class Dictionary {
private static String [] kor = { "사랑","아기","돈","미래","희망" };
private static String [] eng = { "love","baby","monry","future", "hope"};
public static String kor2Eng(String word) {
for(int i=0;i<kor.length;i++) {
if(kor[i].equals(word))
return eng[i];
}
return " 저의 사전에 없습니다.";
}
}
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("한영 단어 검색 프로그램입니다.");
while(true) {
System.out.print("한글 단어?");
String name = sc.next();
if(name.equals("그만")) {
return ;
}
else {
System.out.println(name+"는 " +Dictionary.kor2Eng(name));
}
}
}
}
부모클래스 - 자식클래스
슈퍼클래스 - 서브클래스
class Person{
int age;
String name;
}
class Student extends Person{
String school;
char grade;
void speak() {
System.out.println("안녕하세요, 저는 학생입니다.");
System.out.println("나이는 "+age+"살 이고, 이름은 "+name+"입니다");
}
}
class Teacher extends Person{
String school;
String major;
void speak() {
System.out.println("안녕하세요, 저는 선생님입니다.");
System.out.println("나이는 "+age+"살 이고, 이름은 "+name+"입니다");
}
}
class ComTeacher extends Teacher{
}
class Main{
public static void main(String[] args) {
Student s = new Student();
Teacher t = new Teacher();
s.speak();
}
}
*/
/*
import java.util.*;
class Point {
private int x,y;
public void set(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;
void setColor(String color) {
this.color = color;
}
public void showColorPoint() {
System.out.print(color);
showPoint();
}
}
class Main{
public static void main(String [] args) {
Point p = new Point();
p.set(1,2);
p.showPoint();
ColorPoint cp = new ColorPoint ();
cp.set(3,4);
cp.setColor("red");
cp.showColorPoint();
}
}
import java.util.*;
class Pen {
protected int amount;
public int getAmount() { return amount; }
public void setAmount(int amount) { this.amount = amount; }
}
class SharpPencil extends Pen {
private int width;
}
class BallPen extends Pen {
private String color;
public String getColor() { return color; }
public void setColor(String color ) { this.color = color; }
}
class FountainPen extends BallPen {
public void refill(int n) {
amount = n;
}
}
상속-생성자
class A{
int n;
public A() {
System.out.println("A의 기본 생성자");
}
public A(int n) {this.n = n;}
}
class B extends A{
int m;
public B() {
System.out.println("B의 기본 생성자");
}
public B(int m) {
super(20);
this.m = m;
System.out.println("B의 1번 생성자");
}
}
class Main{
public static void main(String[] args) {
//A x = new A(10);
B y = new B(10);
}
}
*/
/*
import java.util.*;
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();
}
}
class Main {
public static void main(String[] args) {
ColorPoint cp = new ColorPoint(5, 6, "blue");
cp.showColorPoint
();
}
}
*/
/*
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;
}
public void printProperty() {
System.out.print(getSize()+"인치 "+Color+"컬러");
}
}
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.print("나의 IPTV는 "+IP+" 주소의 "+getSize()+"인치 "+getColor()+"컬러");
}
}
class Main {
public static void main(String[]args) {
IPTV iptv = new IPTV("192.1.1.2", 32, 2048);
iptv.printProperty();
}
}
*/
/*
import java.util.*;
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(int x,int y,String Color) {
super(x,y);
this.Color = Color;
}
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() +")"+"의 점";
}
}
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 + "입니다.");
}
}
*/
/*
import java.util.*;
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);
this.Color = "BLACK";
}
public ColorPoint(int x,int y) {
super(x,y);
this.Color = "BLACK";
}
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() + ")" + "의 점";
}
}
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() + "입니다.");
}
}
*/
/*
import java.util.*;
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 Point3D extends Point {
private int z;
public Point3D(int x,int y,int z) {
super(x,y);
this.z = z;
}
public void moveUp() {
z = z+1;
}
public void moveDown() {
z--;
}
public void move(int x, int y,int z) {
super.move(x, y);
this.z = z;
}
public String toString() {
return "("+ getX() + "," + getY() + "," + z +")" + "의 점";
}
}
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() + "입니다.");
}
}
클래스
1. 필드 (변수 ,속성)
2. 메소드 (기능, 행동)
3. 생성자(객체 생성시 필드값 초기화)
추상클래스 : 일부만 작성 == 일부는 작성 x
*/
/*
abstract class Person{
int age;
String name;
void introduce() { //일반 메소드
System.out.println("I'm "+age+"years old. My name is "+name+".");
}
abstract void speak(); //추상메소드 ( 이 클래스를 상속받은 모든 클래스는 이 메소드를 구현)
}
class Student extends Person{
void speak() {
System.out.println("I'm Student.");
}
}
class Teacher extends Person{
void speak() {
System.out.println("I'm Teacher");
}
}
class Main{
public static void main(String[] args) {
Student s = new Student();
}
}
*/
/*
abstract class Calculator {
public abstract int add(int a,int b);
public abstract int subtract(int a,int b);
public abstract double average (int[] a);
}
class GoodCalc extends Calculator {
public int add(int a,int b) {
return a + b;
}
public int subtract(int a,int b) {
return a-b;
}
public double average(int[] a) {
double sum = 0;
for(int i=0; i<a.length; i++)
sum += a[i];
return sum/a.length;
}
}
class Main {
public static void main(String[] args) {
GoodCalc c = new GoodCalc();
System.out.println(c.add(2,3));
System.out.println(c.subtract(2,3));
System.out.println(c.average(new int [] { 2, 3, 4 }));
}
}
*/
/*
import java.util.*;
abstract class Converter {
abstract protected double convert(double src);
abstract protected String getSrcString();
abstract protected String getDestString();
protected double ratio;
public void run() {
Scanner scanner = new Scanner(System.in);
System.out.println(getSrcString()+"을 "+getDestString()+"로 바꿉니다.");
System.out.println(getSrcString()+"을 입력하세요>> ");
double val = scanner.nextDouble();
double res = convert(val);
System.out.println("변환 결과: "+res+getDestString()+"입니다.");
}
}
class Won2Dollar extends Converter {
public Won2Dollar(int i) {
}
@Override
protected double convert(double src) {
return src/1200;
}
@Override
protected String getSrcString() {
return "원";
}
@Override
protected String getDestString() {
return "달러";
}
}
class Main{
public static void main(String[] args) {
Won2Dollar toDollar = new Won2Dollar(1200);
toDollar.run();
}
}
*/
/*
import java.util.*;
abstract class Converter {
abstract protected double convert(double src);
abstract protected String getSrcString();
abstract protected String getDestString();
protected double ratio;
public void run() {
Scanner scanner = new Scanner(System.in);
System.out.println(getSrcString()+"을 "+getDestString()+"로 바꿉니다.");
System.out.println(getSrcString()+"을 입력하세요>> ");
double val = scanner.nextDouble();
double res = convert(val);
System.out.println("변환 결과: "+res+getDestString()+"입니다.");
}
}
class Km2Mile extends Converter {
public Km2Mile(double i) {
ratio=i;
}
protected double convert(double src) {
return src/ratio;
}
protected String getSrcString() {
return "Km";
}
protected String getDestString() {
return "mile";
}
}
class Main {
public static void main(String[] args) {
Km2Mile toMile = new Km2Mile(1.6);
toMile.run();
}
}
*/
/*
import java.util.*;
abstract class PairMap {
protected String keyArray [];
protected String ValueArray [];
abstract String get(String key);
abstract void put(String key, String value);
abstract String delete(String key);
abstract int length();
}
class Dictionary extends PairMap {
public Dictionary(int i) {
}
String get(String key) {
return "";
}
void put(String key, String value) {
}
String delete(String key) {
return null;
}
int length() {
return 0;
}
}
class Main {
public static void main(String[] args) {
Dictionary dic = new Dictionary(10);
dic.put("황기태", "자바");
dic.put("이재문", "파이선");
dic.put("이재문", "C++");
System.out.println("이재문의 값은 " + dic.get("이재문"));
System.out.println("황기태의 값은 " + dic.get("황기태"));
dic.delete("황기태");
System.out.println("황기태의 값은 " + dic.get("황기태"));
}
}
*/
/*
import java.util.*;
interface PairMap {
abstract String get(String key);
abstract void put(String key, String value);
abstract String delete(String key, String value);
abstract int length();
}
class Dictionary implements PairMap {
@Override
public String get(String key) {
// TODO Auto-generated method stub
return null;
}
@Override
public void put(String key, String value) {
// TODO Auto-generated method stub
}
@Override
public String delete(String key, String value) {
// TODO Auto-generated method stub
return null;
}
@Override
public int length() {
// TODO Auto-generated method stub
return 0;
}
}
class Main {
public static void main(String[] args) {
Dictionary dic = new Dictionary();
dic.put("황기태", "자바");
dic.put("이재문", "파이선");
dic.put("이재문", "C++");
System.out.println("이재문의 값은 " + dic.get("이재문"));
System.out.println("황기태의 값은 " + dic.get("황기태"));
dic.delete("황기태");
System.out.println("황기태의 값은 " + dic.get("황기태"));
}
}
*/
/*
interface Shape {
final double PI = 3.14;
void draw();
double getArea();
default public void redraw() {
System.out.print("--- 다시 그립니다. ");
draw();
}
}
class Circle implements Shape{
int r;
public Circle(int r) {
this.r = r;
}
public void draw() {
System.out.println("반지름이 " + r + "인 원입니다.");
}
public double getArea() {
return r*r*PI;
}
}
class Main {
public static void main(String [] args) {
Shape donut = new Circle(10);
donut.redraw();
System.out.println("면적은 " + donut.getArea());
}
}
interface MouseDriver {
final int BUTTONS = 3;
//int VERSION;
void move();
public int click();
int out();
void drag();
default void drop() {
System.out.println("drop");
}
}
GUI : 그림으로 보여지는것
컨테이너 container : 종이 판 (다른 것들을 포함한다)
컴포넌트 component : 스티커 (컨테이너 위에 올라간다)
import java.awt.*;
import javax.swing.*;
class Main extends JFrame{
public Main() {
setTitle("example1"); // 창 제목 정하기 (필수아님)
setSize(500, 300); //가로500, 세로 300으로 크기 셋팅 (필수)
Container c = getContentPane(); // c = 현재 배경
c.setLayout(new FlowLayout()); //레이아웃 설정 (나중에)
JButton b = new JButton("버튼"); //버튼 생성
c.add(b); //버튼 추가
JLabel la = new JLabel("레이블컴포넌트입니다");
c.add(la);
setVisible(true); // 프레임이 보이게 설정 (필수)
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import javax.swing.*;
class Main extends JFrame{
public Main() {
setTitle("ContentPane과 JFrame");
setSize(500,300);
Container c = getContentPane();
//c.setLayout(new FlowLayout());
c.setLayout(new BorderLayout(5,10));
c.setBackground(Color.black); //배경색 설정
JButton b = new JButton("OK");
b.setBackground(Color.white);
b.setForeground(Color.black);
c.add(b,BorderLayout.NORTH);
// JButton b1 = new JButton("Cancel");
// b1.setBackground(Color.white);
// b1.setForeground(Color.black); //전경색 (글자색) 설정
// c.add(b1, BorderLayout.CENTER);
JButton b2 = new JButton("Ignore");
b2.setForeground(Color.black);
c.add(b2, BorderLayout.CENTER);
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.setBackground(Color.black);
c.add(p,BorderLayout.EAST);
JButton b3 = new JButton("Cancel");
p.add(new JButton("Cancel"));
p.add(b3);
b3.setForeground(Color.blue);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import javax.swing.*;
class Main extends JFrame{
public Main() {
setTitle("Let's study Java");
setSize(400,200);
Container c = getContentPane();
c.setLayout(new BorderLayout(5,7));
JButton b = new JButton("Center");
c.add(b, BorderLayout.CENTER);
JButton b1 = new JButton("East");
c.add(b1, BorderLayout.EAST);
JButton b2 = new JButton("West");
c.add(b2, BorderLayout.WEST);
JButton b3 = new JButton("North");
c.add(b3, BorderLayout.NORTH);
JButton b4 = new JButton("South");
c.add(b4, BorderLayout.SOUTH);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setTitle("GridLayour Sample");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout grid = new GridLayout(4, 2);
grid.setVgap(5);
Container c = getContentPane();
c.setLayout(grid);
c.add(new JLabel(" 이름"));
c.add(new JTextField(""));
c.add(new JLabel(" 학번"));
c.add(new JTextField(""));
c.add(new JLabel(" 학과"));
c.add(new JTextField(""));
c.add(new JLabel(" 과목"));
c.add(new JTextField(""));
setSize(300, 200);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setTitle("Null Container Sample");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
JLabel la = new JLabel("Hello, Press Buttons!");
la.setLocation(130, 50);
la.setSize(200, 20);
c.add(la);
for(int i=1; i<=9; i++) {
JButton b = new JButton(Integer.toString(i));
//***********************
//random
//
//************************
int x = (int) Math.random()*200;
int y = (int) Math.random()*300;
b.setLocation(x, y);
b.setSize(50,20);
c.add(b);
}
setSize(300, 200);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setTitle("Ten Color Buttons Frame");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout grid = new GridLayout(1, 10);
Container c = getContentPane();
c.setLayout(grid);
Color[] clr = {Color.red, Color.orange, Color.yellow, Color.green, Color.cyan, Color.blue, Color.magenta, Color.darkGray, Color.pink, Color.gray };
for(int i=0; i<10; i++) {
JButton b = new JButton(Integer.toString(i));
b.setBackground(clr[i]);
b.setSize(50,20);
c.add(b);
}
setSize(600, 250);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setTitle("4x4 Color Frame");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout grid = new GridLayout(4, 4);
Container c = getContentPane();
c.setLayout(grid);
Color[] clr = {Color.red,Color.orange,Color.yellow,Color.green,Color.cyan,Color.blue,Color.magenta,Color.darkGray,Color.pink,Color.gray,Color.red,Color.orange,Color.yellow,Color.green,Color.cyan,Color.blue};
for(int i=0; i<16; i++) {
JButton b = new JButton(Integer.toString(i));
b.setBackground(clr[i]);
b.setSize(50,20);
c.add(b);
}
setSize(600, 250);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setTitle("Random Labels");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
for(int i=0; i<20; i++)
{
JLabel la = new JLabel(Integer.toString(i));
int x = (int)(Math.random()*200) + 50;
int y = (int)(Math.random()*200) + 50;
la.setLocation(x,y);
la.setSize(15, 15);
la.setBackground(Color.blue);
la.setForeground(Color.white);
la.setOpaque(true);
c.add(la);
}
}
public static void main(String[] args) {
new Main();
}
}
event : 모든 변화 ex) 마우스 클릭, 버튼 클릭, 버튼에 마우스 올려놓기, 키보드 a 누르기 .....
action event
key event
mouse evet
change event
...
event listener : 이벤트를 어떻게 처리할지 적어놓는 곳
import javax.swing.*;
import java.awt.*;
import java.awt.event.*; // event를 처리하는 부분
public class Main extends JFrame {
Container c = getContentPane();
JPanel nor = new JPanel();
JPanel cen = new JPanel();
JButton b = new JButton("set black");
JButton b1 = new JButton("set red");
JButton b2 = new JButton("set pink");
public Main() {
setTitle("Open Challenge 9");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new BorderLayout(3,3));
nor.setLayout(new FlowLayout());
nor.setBackground(Color.LIGHT_GRAY);
cen.setLayout(null);
//액션리스너 붙여주기
b.addActionListener(new MyActionListener());
b1.addActionListener(new MyActionListener());
b2.addActionListener(new MyActionListener());
nor.add(b);
nor.add(b1);
nor.add(b2);
JLabel l = new JLabel("Hello");
l.setLocation(50,150);
l.setSize(30, 30);
cen.add(l);
JLabel l1 = new JLabel("Java");
l1.setLocation(250,80);
l1.setSize(30, 30);
cen.add(l1);
JLabel l2 = new JLabel("Love");
l2.setLocation(70,50);
l2.setSize(30, 30);
cen.add(l2);
c.add(cen, BorderLayout.CENTER);
c.add(nor, BorderLayout.NORTH);
setSize(300,300);
setVisible(true);
}
//액션리스너 클래스 작성하기
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
JButton bb = (JButton)e.getSource(); // 이벤트가 일어난 버튼을 bb
if(bb==b) cen.setBackground(Color.black);
else if(bb==b1) cen.setBackground(Color.red);
else cen.setBackground(Color.pink);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame {
public Main() {
setTitle("Action 이벤트 리스너 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
JButton btn = new JButton("Action");
btn.addActionListener(new MyActionListener());
c.add(btn);
setSize(350,150);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
class MyActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
JButton b = (JButton)e.getSource();
if(b.getText().equals("Action"))
b.setText("액션");
else
b.setText("Action");
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public 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.setLayout(null);
la.setSize(50, 20);
la.setLocation(30, 30);
c.add(la);
setSize(250, 250);
setVisible(true);
}
//implements MouseListener
class MyMouseListener extends MouseAdapter {
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
// public void mousePressed(MouseEvent e) {
// int x = e.getX();
// int y = e.getY();
// la.setLocation(x, y);
// }
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame {
private JLabel la = new JLabel("Love Java");
public Main() {
setTitle("마우스 올리기 내리기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
la.addMouseListener(new MyMouseListener());
c.setLayout(null);
la.setSize(100, 20);
la.setLocation(140, 30);
c.add(la);
setSize(350, 250);
setVisible(true);
}//implements MouseListener
class MyMouseListener extends MouseAdapter {
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
la.setText("Love Java");
}
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
la.setText("사랑해");
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame {
Container c = getContentPane();
public Main() {
setTitle("드래깅동안 YELLOW");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.addMouseMotionListener(new MyMouseMotionListener());
setSize(350, 250);
setVisible(true);
}
class MyMouseMotionListener extends MouseAdapter{
public void mouseDragged(MouseEvent e) {
c.setBackground(Color.YELLOW);
}
public void mouseMoved(MouseEvent e) {
c.setBackground(Color.GREEN);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
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(" getKeyCode() ");
keyMessage[2] = new JLabel(" getKeyCode() ");
for(int i=0; i<keyMessage.length; i++)
{
c.add(keyMessage[i]);
keyMessage[i].setOpaque(true);
keyMessage[i].setBackground(Color.CYAN);
}
setSize(300, 150);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
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(Character.toString(keyChar));
keyMessage[2].setText(KeyEvent.getKeyText(keyCode));
System.out.println("KeyPressed");
}
public void keyReleased(KeyEvent e) {
System.out.println("KeyReleased");
}
public void keyTyped(KeyEvent e) {
System.out.println("KeyTyped");
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame {
private JLabel keyMessage;
Container c = getContentPane();
public Main() {
setTitle("Key Code 예제 : F1키:초록색, %키:노랑색");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new FlowLayout());
c.addKeyListener(new MyKeyListener());
keyMessage = new JLabel("키가 입력되었음");
c.add(keyMessage);
setSize(300, 150);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
class MyKeyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
char keyChar = e.getKeyChar();
keyMessage.setText(Character.toString(keyChar)+"키가 입력되었음");
if(e.getKeyChar()=='%')
{
c.setBackground(Color.yellow);
}
if(e.getKeyCode()==KeyEvent.VK_F1)
{
c.setBackground(Color.green);
}
System.out.println("KeyPressed");
}
public void keyReleased(KeyEvent e) {
System.out.println("KeyReleased");
}
public void keyTyped(KeyEvent e) {
System.out.println("KeyTyped");
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame {
private JLabel la = new JLabel("HELLO");
public Main() {
setTitle("상,하,좌,우 키를 이용하여 텍스트 움직이기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
c.addKeyListener(new MyKeyListener());
la.setLocation(50, 50);
la.setSize(50,50);
c.add(la);
setSize(300, 300);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
class MyKeyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
int x = la.getX();
int y = la.getY();
if(e.getKeyCode()==KeyEvent.VK_UP)
{
la.setLocation(x,y-10);
}
else if(e.getKeyCode()==KeyEvent.VK_DOWN)
{
la.setLocation(x,y+10);
}
else if(e.getKeyCode()==KeyEvent.VK_LEFT)
{
la.setLocation(x-10,y);
}
else if(e.getKeyCode()==KeyEvent.VK_RIGHT)
{
la.setLocation(x+10,y);
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public 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.event.*;
import java.awt.*;
public class Main extends JFrame {
private JLabel la = new JLabel("Love Java");
public Main() {
setTitle("Left 키로 문자열 교체");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
c.addKeyListener(new MyKeyListener());
c.add(la);
la.setSize(100,100);
la.setLocation(110,0);
setSize(300, 150);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
class MyKeyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_LEFT)
{
String latext = la.getText();
if(latext.equals("Love Java")) {
la.setText("avaJ evoL");
}
else
{
la.setText("Love Java");
}
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame {
private JLabel la = new JLabel("Love Java");
public Main() {
setTitle("Left 키로 문자열 이동");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
c.addKeyListener(new MyKeyListener());
c.add(la);
la.setSize(100,100);
la.setLocation(110,0);
setSize(300, 150);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
class MyKeyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_LEFT)
{
String text = la.getText();
String aftertext = text.substring(1) + text.substring(0,1);
la.setText(aftertext);
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame {
private JLabel la = new JLabel("Love Java");
public Main() {
setTitle("+,- 키로 폰트 크기 조절");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
c.addKeyListener(new MyKeyListener());
c.add(la);
la.setSize(400,100);
la.setLocation(110,0);
la.setFont(new Font("Arial", Font.PLAIN, 10));
setSize(400, 300);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
class MyKeyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
Font f = la.getFont();
int size = f.getSize();
if(e.getKeyChar() == '+'&&size+5<100)
{
la.setFont(new Font("Arial", Font.PLAIN, size+5));
}
else if(e.getKeyChar() == '-'&&size-5>5)
{
la.setFont(new Font("Arial", Font.PLAIN, size-5));
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame {
private JLabel la = new JLabel("C");
public Main() {
setTitle("클릭 연습 용 응용프로그램");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
la.addMouseListener(new MyMouseListener());
la.setSize(100,100);
la.setLocation(100, 100);
c.add(la);
setSize(300, 250);
setVisible(true);
}
class MyMouseListener extends MouseAdapter{
public void mousePressed(MouseEvent e) {
int x = (int)(Math.random()*250);
int y = (int)(Math.random()*200);
la.setLocation(x, y);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame {
private JLabel la = new JLabel("Love Java");
public Main() {
setTitle("마우스 휠을 굴려 폰트 크기 조절");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
la.addMouseWheelListener(new MyMouseWheelListener());
c.add(la);
la.setSize(500,300);
la.setLocation(210, -50);
c.setLayout(null);
la.setFont(new Font("Arial", Font.PLAIN, 10));
setSize(500, 250);
setVisible(true);
}
class MyMouseWheelListener extends MouseAdapter{
public void mouseWheelMoved(MouseWheelEvent e) {
Font f = la.getFont();
int size = f.getSize();
int n = e.getWheelRotation();
if(n<0&&size-5>5)
{
la.setFont(new Font("Arial", Font.PLAIN, size-5));
}
else if(n>0&&size+5<100)
{
la.setFont(new Font("Arial", Font.PLAIN, size+5));
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setTitle("레이블 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
JLabel textLabel = new JLabel("사랑합니다.");
ImageIcon heart = new ImageIcon("images/heart.png");
JLabel imageLabel = new JLabel(heart);
ImageIcon phone = new ImageIcon("images/phone.png");
JLabel label = new JLabel("보고싶으면 전화하세요",
phone, SwingConstants.CENTER);
c.add(textLabel);
c.add(imageLabel);
c.add(label);
setSize(400,200);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setTitle("이미지 버튼 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
ImageIcon normalIcon = new ImageIcon("images/phone.png");
ImageIcon rolloverIcon = new ImageIcon("images/incoming-call.png");
ImageIcon pressedIcon = new ImageIcon("images/conversation.png");
JButton btn = new JButton("call~~", normalIcon);
btn.setPressedIcon(pressedIcon);
btn.setRolloverIcon(rolloverIcon);
c.add(btn);
setSize(250,150);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setTitle("체크박스 만들기 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
ImageIcon cherryIcon = new ImageIcon("images/cherries.png");
ImageIcon selectedCherryIcon = new ImageIcon("images/berry.png");
JCheckBox apple = new JCheckBox("사과");
JCheckBox pear = new JCheckBox("배");
JCheckBox cherry = new JCheckBox("체리", cherryIcon);
c.add(apple);
c.add(pear);
c.add(cherry);
cherry.setSelectedIcon(selectedCherryIcon);
cherry.setBorderPainted(true);
setSize(300,250);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame {
private JCheckBox [] fruits = new JCheckBox [3];
private String [] names = {"사과","배","체리"};
private JLabel sumLabel;
public Main() {
setTitle("첵크박스와 ItemEvent 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
c.add(new JLabel("사과 100원, 배 500원 , 체리 20000원"));
for(int i=0; i<fruits.length; i++)
{
fruits[i] = new JCheckBox(names[i]);
fruits[i].addItemListener(new MyItemListener());
fruits[i].setBorderPainted(true);
c.add(fruits[i]);
}
sumLabel = new JLabel("현재 0원 입니다.");
c.add(sumLabel);
setSize(250,200);
setVisible(true);
}
class MyItemListener implements ItemListener {
private int sum = 0;
public void itemStateChanged(ItemEvent e)
{
if(e.getStateChange() == ItemEvent.SELECTED) {
if(e.getItem() == fruits[0])
sum += 100;
else if(e.getItem() == fruits[1])
sum += 500;
else
sum += 20000;
}
else {
if(e.getItem() == fruits[0])
sum -= 100;
else if(e.getItem() == fruits[1])
sum -= 500;
else
sum -= 20000;
}
sumLabel.setText("현재 " + sum + "원 입니다.");
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setTitle("라디오버튼 만들기 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
ImageIcon cherryIcon = new ImageIcon("images/cherries.png");
ImageIcon selectedCherryIcon = new ImageIcon("images/berry.png");
ButtonGroup g = new ButtonGroup();
JRadioButton apple = new JRadioButton("사과");
JRadioButton pear = new JRadioButton("배");
JRadioButton cherry = new JRadioButton("체리", cherryIcon);
cherry.setBorderPainted(true);
cherry.setSelectedIcon(selectedCherryIcon);
g.add(apple);
g.add(pear);
g.add(cherry);
c.add(apple);
c.add(pear);
c.add(cherry);
setSize(250,150);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame {
private JRadioButton [] radio = new JRadioButton [3];
private String [] text = {"사과","배","체리"};
private ImageIcon [] image = {
new ImageIcon("images/apple.png"),
new ImageIcon("images/pear.png"),
new ImageIcon("images/berry.png")
};
private JLabel imageLabel = new JLabel();
public Main() {
setTitle("라디오버튼 Item Event 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new BorderLayout());
JPanel radioPanel = new JPanel();
radioPanel.setBackground(Color.gray);
ButtonGroup g = new ButtonGroup();
for(int i=0; i<radio.length; i++)
{
radio[i] = new JRadioButton(text[i]);
g.add(radio[i]);
radioPanel.add(radio[i]);
radio[i].addItemListener(new MyItemListener());
}
radio[2].setSelected(true);
c.add(radioPanel, BorderLayout.NORTH);
c.add(imageLabel, BorderLayout.CENTER);
imageLabel.setHorizontalAlignment(SwingConstants.CENTER);
setSize(250,150);
setVisible(true);
}
class MyItemListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == e.DESELECTED)
return;
if(radio[0].isSelected())
imageLabel.setIcon(image[0]);
else if(radio[1].isSelected())
imageLabel.setIcon(image[1]);
else
imageLabel.setIcon(image[2]);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setTitle("텍스트필드 만들기 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
setLayout(new FlowLayout());
c.add(new JLabel("이름 "));
c.add(new JTextField(20));
c.add(new JLabel("힉과 "));
c.add(new JTextField("컴퓨터공학과", 20));
c.add(new JLabel("주소"));
c.add(new JTextField("서울시", 20));
setSize(250,150);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame {
private JTextField tf = new JTextField(20);
private JTextArea ta = new JTextArea(7,20);
public Main() {
setTitle("텍스트 영역 만들기 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
setLayout(new FlowLayout());
// JButton b = new JButton("Delete");
// b.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// ta.setText("");
// }
// });
c.add(new JLabel("입력 후 <Enter> 키를 입력하세요."));
c.add(tf);
c.add(new JScrollPane(ta));
// c.add(b);
tf.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JTextField t = (JTextField)e.getSource();
ta.append(t.getText() + "\n");
t.setText("");
}
});
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/