본문 바로가기

Java/java 기초

awt - 이미지 올리기


import java.awt.Choice;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Label;
import java.awt.Toolkit;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class WindowTest extends Frame implements WindowListener {
	
	Image img = null;
	Image pngImg = null;
	
	public WindowTest() {
		setLayout(null);

		
		Toolkit tk = Toolkit.getDefaultToolkit();
		
		img = tk.getImage("house.jpg");
//		img = tk.getImage("c:\\tmp\\pig.png");
//		img = tk.getImage("\\\\192.168.3.3\\공유\\경치.gif");
		
		pngImg = tk.getImage("bird.png");
		
		//this.getWitdh 현재 폭을 얻어온다.
		
		img.getWidth(this);
		img.getHeight(this);
		setSize(640,480);
		
//		setLocation(100, 0);
		setVisible(true);
		addWindowListener(this);
	}
	
	
	@Override
	public void paint(Graphics g) {
		// TODO Auto-generated method stub
		super.paint(g);
		
		int	imgWidth = img.getWidth(this);
		int imgHeight = img.getHeight(this);
	
		g.drawImage(img, 0, 0, this);
		g.drawImage(pngImg, 200, 200, this);
		setSize(imgWidth, imgHeight);
		
		System.out.println(imgWidth + " " + imgHeight);
		

	}


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

	}

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

	}

	@Override
	public void windowClosing(WindowEvent arg0) {
		// TODO Auto-generated method stub
		System.exit(0);

	}

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

	}

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

	}

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

	}

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

	}

}

'Java > java 기초' 카테고리의 다른 글

awt 로 채팅 프로그램 구현하기  (0) 2019.12.10
네트워크 공부  (0) 2019.12.09
awt로 가위바위보 프로그램 만들기  (0) 2019.12.05
awt - 응용  (0) 2019.12.05
awt- 버튼 클릭 이벤트  (0) 2019.12.05