본문 바로가기

JAVA/UI

Label 과 Panel

label호출
panel호출

 

 

Main

public class mainClass {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new WindowTest();
	}
}

 

WindowTest

라벨호출할지 패널호출 할지는 여기서 선택.

public class WindowTest extends Frame implements WindowListener {
	
	public WindowTest() {
		
		super("panel");
		
		setLayout(new GridLayout(2,1));//2행 1열 : 위아래로 나눈 꼴
		
		//Panel : Frame(Window) 위에 Frame(Window)
		//			종이 위에 종이
		
		//Label label = new Label("label");
		//add(label);//label은 윗칸에 들어감
		
		MyPanel mypanel = new MyPanel();
		add(mypanel);//클래스 밖에서 호출함
		
		//Panel
		Panel panel = new Panel();//panel은 윗칸에 들어감
		panel.setBackground(Color.blue);
		panel.setLayout(new GridLayout(1,2));//또 위아래로 나눔
		add(panel);
		
		Label label1 = new Label("label 1");
		panel.add(label1);//add(a)는 레이블에추가
		
		Button button = new Button("Button");
		panel.add(button);
		
		setBounds(0, 0, 800, 600);
		setVisible(true);
		
		addWindowListener(this);
	}
	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public void windowClosing(WindowEvent e) {
		// TODO Auto-generated method stub
		System.exit(0);
	}
	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
	}
}

Mypanel

public class MyPanel extends Panel{
	public MyPanel() {
		setLayout(new GridLayout(3,1));
		setBackground(Color.red);
		
		Label label1 = new Label("MyPanel label1");
		add(label1);
		Label label2 = new Label("MyPanel label2");
		add(label2);
		Label label3 = new Label("MyPanel label3");
		add(label3);
	}
}

'JAVA > UI' 카테고리의 다른 글

가위바위보 게임 프로그램  (0) 2020.06.12
label / 확인창 뜨게하기  (0) 2020.06.11
Observer  (0) 2020.06.11
AWT  (0) 2020.06.11
Lable  (0) 2020.06.11