6월, 2018의 게시물 표시

JAVA2 - Day4 - GridBagLayout, Canvas

<기본적인 프레임 틀 복습하기> package com.layout; public class Main { public static void main(String[] args) { MyFrame my=new MyFrame("AWT",300,300); my.setVisible(true); } } ------------------------------------------------------------------------------------ package com.layout; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class MyFrame extends Frame{ public MyFrame(String title, int width, int height) { //title setTitle(title); //size  setSize(width, height); //window event // - local inner class /* class MyWindow extends WindowAdapter{ @Override public void windowClosing(WindowEvent e) { System.exit(0); } } MyWindow win=new MyWindow(); addWindowListener(win); */ // -anonymous class /* WindowAdapter win=new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { Syst...

JAVA2 - Day3 - anonymous, Inner class, FlowLayout

<anonymous> package com.annonymous; public class Main { public static void main(String[] args) { //2- 4 anonymous class , 익명 클래스 // - 이름이 없다. // - 클래스의 선언과 객체의 생성을 동시에 하는 클래스 // - 일회용, 단 하나의 객체만 생성. // - 단하나의 클래스를 상속받거나 또는 하나의 인터페이스를 구현. //Shape클래스를 상속받는 이름없는 클래스 // -> 객체생성!! (Shape rect) Shape rect = new Shape() { @Override void draw() { info(); System.out.println("Rect"); } void info() { System.out.println("ㅎㅎ"); } }; rect.draw(); // rect.info(); //접근이 안됨. Shape circle = new Shape() { @Override void draw() { System.out.println("Circle"); } }; circle.draw(); System.out.println("----------------------------------"); //Monster 인터페이스를 구현하는 익명클래스 Monster cat = new Monster() { @Override public void attack() { System.out.println("cat 공격!"); } @Override public void move() {...