Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 명사 분석기
- Node.js
- 메일왕창보내는법
- C/C++
- Cross
- ror실행
- php thumbnail
- 디즈니씨
- 책이야기
- 나의 취미
- Eclipse
- 도커
- 명사 추출기
- flex3
- iBatis
- ajax
- docker
- 주식이야기
- ejb
- scala
- node.js web framework
- Lift
- 나의 프로젝트
- rss
- 베트남어
- nodejs express
- 명사 뽑아내기
- express for node.js
- php
- 스킨 스쿠버
Archives
- Today
- Total
nkdk의 세상
자바 Language 9일째 1번 본문
package inter;
public class Outer {
int a;
Inner in1; // 내부 클래스 객체 변수
public Outer() {
System.out.println("외부 클래스 생성자");
a=10;
in1=new Inner();
}
public void aa() {
System.out.println("외부 메소드: aa");
in1.cc(); // 내부 클래스 멤버 호출
System.out.println("내부 멤버 x="+in1.x);
}
public void bb() {
System.out.println("외부 메소드: bb");
}
public class Inner{ // 클래스 안에 클래스를 만든다.
int x;
public Inner(){
x=20;
}
public void cc() {
System.out.println("내부에 있는 메소드 cc");
System.out.println("x="+x);
System.out.println("외부의 a="+a);
bb();
}
}
public static void main(String[] args) {
Outer out =new Outer();
out.aa();
// Inner in2=new Inner(); 이런식으로 이너클래스는 독립적으로 생성해서 사용 할 수 없다.
Outer.Inner in2=out.new Inner(); // 이런식으로는 만들 수 있다.
System.out.println("in2.x");
}
}
package inter;
public class Saram {
String ir="박치기";
public String irum() {
return ir;
}
public void print() {
}
}
package inter;
public class gildong {
public Saram getInner() { // 내부 무명 클래스
return new Saram() {
public String irum() {
return "홍길동";
}
};
}
}
package inter;
public class gildongMain {
public static void main(String[] args) {
gildong gildong=new gildong();
Saram saram=new Saram();
System.out.println(saram.irum());
// Saram sa=new Saram();
Saram sa=gildong.getInner();
System.out.println(sa.irum());
}
}
package inter;
import java.awt.*;
import java.awt.event.*;
public class FrameEnd extends Frame{
int x,y;
int k; // 배열 인덱스로 사용
String str[]={"정지연", "오준석", "강인수","강인석","연진호","김광"};
Wevent we;
public FrameEnd() {
setSize(500,400);
setLocation(100,100);
setVisible(true);
//we=new Wevent();
//addWindowListener(we);
addWindowListener(new WindowAdapter()
{ // 내부 무명 클래스
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
addMouseListener(new Mevent()); // 마우스와 윈도우 리스너를 이용하여 프로그래밍 한다.
}
class Wevent extends WindowAdapter{
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
class Mevent extends MouseAdapter{
public void mouseClicked(MouseEvent e) {
x=e.getX();
y=e.getY();
setTitle("x="+x+" y="+y);
// graphic 라는 클래스를 이용한다.
k=(int)(Math.random()*5);
repaint(); // <- 페인트 메소드를 부른다.
}
}
public void paint(Graphics g) {
g.setColor(new Color((int)(Math.random()*255),
(int)(Math.random()*255),
(int)(Math.random()*255)));
g.setFont(new Font("굴림", Font.BOLD, (int)(Math.random()*50)+8));
g.drawString(str[k],x , y);
}
public static void main(String[] args) {
new FrameEnd();
}
}
// 313페이지 까지 끝나는 내용입니다. 상속, 인터페이스와 무명클래스 등이 끝났습니다.
public class Outer {
int a;
Inner in1; // 내부 클래스 객체 변수
public Outer() {
System.out.println("외부 클래스 생성자");
a=10;
in1=new Inner();
}
public void aa() {
System.out.println("외부 메소드: aa");
in1.cc(); // 내부 클래스 멤버 호출
System.out.println("내부 멤버 x="+in1.x);
}
public void bb() {
System.out.println("외부 메소드: bb");
}
public class Inner{ // 클래스 안에 클래스를 만든다.
int x;
public Inner(){
x=20;
}
public void cc() {
System.out.println("내부에 있는 메소드 cc");
System.out.println("x="+x);
System.out.println("외부의 a="+a);
bb();
}
}
public static void main(String[] args) {
Outer out =new Outer();
out.aa();
// Inner in2=new Inner(); 이런식으로 이너클래스는 독립적으로 생성해서 사용 할 수 없다.
Outer.Inner in2=out.new Inner(); // 이런식으로는 만들 수 있다.
System.out.println("in2.x");
}
}
package inter;
public class Saram {
String ir="박치기";
public String irum() {
return ir;
}
public void print() {
}
}
package inter;
public class gildong {
public Saram getInner() { // 내부 무명 클래스
return new Saram() {
public String irum() {
return "홍길동";
}
};
}
}
package inter;
public class gildongMain {
public static void main(String[] args) {
gildong gildong=new gildong();
Saram saram=new Saram();
System.out.println(saram.irum());
// Saram sa=new Saram();
Saram sa=gildong.getInner();
System.out.println(sa.irum());
}
}
package inter;
import java.awt.*;
import java.awt.event.*;
public class FrameEnd extends Frame{
int x,y;
int k; // 배열 인덱스로 사용
String str[]={"정지연", "오준석", "강인수","강인석","연진호","김광"};
Wevent we;
public FrameEnd() {
setSize(500,400);
setLocation(100,100);
setVisible(true);
//we=new Wevent();
//addWindowListener(we);
addWindowListener(new WindowAdapter()
{ // 내부 무명 클래스
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
addMouseListener(new Mevent()); // 마우스와 윈도우 리스너를 이용하여 프로그래밍 한다.
}
class Wevent extends WindowAdapter{
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
class Mevent extends MouseAdapter{
public void mouseClicked(MouseEvent e) {
x=e.getX();
y=e.getY();
setTitle("x="+x+" y="+y);
// graphic 라는 클래스를 이용한다.
k=(int)(Math.random()*5);
repaint(); // <- 페인트 메소드를 부른다.
}
}
public void paint(Graphics g) {
g.setColor(new Color((int)(Math.random()*255),
(int)(Math.random()*255),
(int)(Math.random()*255)));
g.setFont(new Font("굴림", Font.BOLD, (int)(Math.random()*50)+8));
g.drawString(str[k],x , y);
}
public static void main(String[] args) {
new FrameEnd();
}
}
// 313페이지 까지 끝나는 내용입니다. 상속, 인터페이스와 무명클래스 등이 끝났습니다.