본문 바로가기

Java/java 기초

awt - Panel

package awtSample04;

import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class WindowTest extends Frame implements WindowListener {
	
	public WindowTest() {
		//Panel == 종이위에 종이
		setLayout(new GridLayout(2, 1));
		
		// 1abel -> 위 부분
//		Label label = new Label("label");
//		add(label);
		
		MyPanel myP = new MyPanel();
		add(myP);
		
		// Panel
		Panel panel = new Panel();
		panel.setBackground(Color.GRAY);
		panel.setLayout(new GridLayout(1, 2));
		add(panel);
		
		Label label1 = new Label("label1");
		panel.add(label1);
		
		Button button = new Button("button");
		
		panel.add(button);
		
		
		
		setSize(640, 480);
		setLocation(0, 0);
		
		setVisible(true);
		
		addWindowListener(this);
	}
	
	@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

	}

}

 

 

 

package awtSample04;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;

public class MyPanel extends Panel {
	public MyPanel() {
		setLayout(new GridLayout(3, 1));
		setBackground(Color.yellow);
		
		Label l1 = new Label("myPanel lable1");
		Label l2 = new Label("myPanel lable2");
		Label l3 = new Label("myPanel lable3");
		
		add(l1);
		add(l2);
		add(l3);
//		setLayout(new );
	}
}

 

package awtSample04;

public class mainClass {
	public static void main(String[] args) {
		WindowTest wt = new WindowTest();
	}
}

 

 

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

awt - 응용  (0) 2019.12.05
awt- 버튼 클릭 이벤트  (0) 2019.12.05
awt - label 및 button  (0) 2019.12.05
이클립스 (eclipse) 기준으로 awt의 글씨가 깨질때  (0) 2019.12.05
awt - label  (0) 2019.12.05