Java 코드연습/인터페이스

[뉴렉처] 인터페이스를 구현하는 위치는?

양상추상츄 2021. 11. 3. 00:34

인터페이스를 구현할때 구현하는 위치는 새로운클래스에서 구현하는 경우는 많지는 않고

클래스가 필요로 하는 클래스가 있어야할 위치를 가지고 구현하게 된다.?

 

아직은 좀 이해가 안되고 더 봐야할 것 같다.

 

https://www.youtube.com/watch?v=DCDz131Qo0w&list=PLq8wAnVUcTFX4E2NplMvJfqlcgAeF_BxK&index=35 

 

 

import java.awt.Frame;
import java.awt.event.WindowListener;


public class Program {

	public static void main(String[] args) {
		GameFrame frame = new GameFrame();
//		WindowListener listener = new GameWindowListener();
//		frame.addWindowListener(listener);
//		frame.setVisible(true);

	}

}
import java.awt.Frame;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.DebugGraphics;
import javax.swing.JOptionPane;

import java.awt.Window;


public class GameFrame extends Frame implements WindowListener {
	public GameFrame() {
		//WindowListener listener = new GameWindowListener();
		addWindowListener(this);//this생략
		setVisible(true);//this생략
	}
	
	public void paint(DebugGraphics g) {
		super.paint(g);
		g.drawRect(100, 100, 200, 100);
	}
	
	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosing(WindowEvent e) {
		JOptionPane.showMessageDialog(this, "good bye");
		System.exit(0);
	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	
}
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class GameWindowListener implements WindowListener {

	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowClosing(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub

	}

}