JAVA

8일차

구자룡 2021. 4. 5. 15:00

//스윙프레임만들기프로그램
import javax.swing.*;

public class Exam01 extends JFrame{
	public Exam01() {
//		setTitle("스윙프레임만들기");
		super("스윙프레임만들기");
		setSize(300,300);
		setVisible(true);
	}
	public static void main(String[] ar) {
		new Exam01();
	}
}

//프레임을 설정하고 위치를 결정하는 프로그램
import java.awt.*;
public class Exam02 {
	public static void main(String[] ar) {
		Frame f = new Frame();
		Frame f1 = new Frame("자바");
		
		f.setSize(300,200);
		f1.setSize(400,500);
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension f_size = f.getSize();
		Dimension f1_size = f1.getSize();
		
		int xpos = (int)(screen.getWidth()/2-f_size.getWidth()/2);
		int ypos = (int)(screen.getHeight()/2-f_size.getHeight()/2);
		f.setLocation(xpos,ypos);
		
		int xpos1 = (int)(screen.getWidth()/2-f1_size.getWidth()/2);
		int ypos1 = (int)(screen.getHeight()/2-f1_size.getHeight()/2);
		f1.setLocation(xpos1,ypos1);
		f.setVisible(true);
		f1.setVisible(true);

	}

}

//상속받아서 기본품을 구성하는 배치GUI프로그램.
import java.awt.*;
public class Exam03 extends Frame{
	public Exam03(String title) {
		super(title);//super은 상위 생성자를 호출한다는 뜻이다.
		super.setSize(500,300);
		
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frm = super.getSize();
		int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
		int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
		super.setLocation(xpos,ypos);
		
		super.setResizable(false);
		super.setVisible(true);		
	}
	
	public static void main(String[] ar) {
		new Exam03("제목");
		
	}

}

//상속받아서 기본품을 구성하는 배치GUI프로그램.
import java.awt.*;
public class Exam04 extends Frame{
	private Label lb = new Label("멋쟁이");
	
	public Exam04(String title) {
		super(title);//super은 상위 생성자를 호출한다는 뜻이다.
		
		this.init();
		
		super.setSize(500,300);
		
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frm = super.getSize();
		int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
		int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
		super.setLocation(xpos,ypos);
		
		super.setResizable(false);
		super.setVisible(true);		
	}
	public void init(){
		this.add(lb);//현재 화면에 lb라는 컴포넌트를 추가하는 뜻이다.
		
	}
	
	public static void main(String[] ar) {
		new Exam04("제목");
		
	}

}


//FlowLayout에 대한 배치 프로그램 예제임
import java.awt.*;
//상속받아서 기본품을 구성하는 배치GUI프로그램.
import java.awt.*;
public class Exam05 extends Frame{
	private Button bt1 = new Button("1");
	private Button bt2 = new Button("2");
	private Button bt3 = new Button("3");
	private Button bt4 = new Button("4");
	private Button bt5 = new Button("5");
	private Button bt6 = new Button("6");
	
	//컴포넌트버튼 6개를 화면에 레이아웃으로 추가하여 구성한다.
	private FlowLayout fl = new FlowLayout(FlowLayout.RIGHT);
	public Exam05(String title) {
		super(title);//super은 상위 생성자를 호출한다는 뜻이다.
		
		this.init();
		
		super.setSize(500,300);
		
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frm = super.getSize();
		int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
		int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
		super.setLocation(xpos,ypos);
		
		super.setResizable(false);
		super.setVisible(true);		
	}
	public void init() {
		this.setLayout(fl);
		this.add(bt1);
		this.add(bt2);
		this.add(bt3);
		this.add(bt4);
		this.add(bt5);
		this.add(bt6);
	}
	
	public static void main(String[] ar) {
		new Exam05("제목");
		
	}

}

//GridLayout에대한 실습예제임
import java.awt.*;
public class Exam06 extends Frame{
	private Button bt1 = new Button("1");
	private Button bt2 = new Button("2");
	private Button bt3 = new Button("3");
	private Button bt4 = new Button("4");
	private Button bt5 = new Button("5");
	private Button bt6 = new Button("6");
	
	//define...layout
	private GridLayout gl = new GridLayout(3,2,10,10);
	
	public Exam06(String title) {
		super(title);//super은 상위 생성자를 호출한다는 뜻이다.
		
		this.init();
		
		super.setSize(500,300);
		
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frm = super.getSize();
		int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
		int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
		super.setLocation(xpos,ypos);
		
		super.setResizable(false);
		super.setVisible(true);		
	}
	public void init() {
		this.setLayout(gl);
		this.add(bt1);
		this.add(bt2);
		this.add(bt3);
		this.add(bt4);
		this.add(bt5);
		this.add(bt6);
		
	}
	
	public static void main(String[] ar) {
		new Exam06("제목");
		
	}

}


//BorderLayout에대한 예제임
import java.awt.*;
public class Exam07 extends Frame{
	private Button bt1 = new Button("1");
	private Button bt2 = new Button("2");
	private Button bt3 = new Button("3");
	private Button bt4 = new Button("4");
	private Button bt5 = new Button("5");
	
	private BorderLayout bl = new BorderLayout(10,10);
	
	public Exam07(String title) {
		super(title);//super은 상위 생성자를 호출한다는 뜻이다.
		
		this.init();
		
		super.setSize(500,300);
		
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frm = super.getSize();
		int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
		int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
		super.setLocation(xpos,ypos);
		
		super.setResizable(false);
		super.setVisible(true);		
	}
	public void init() {
		this.setLayout(bl);
		this.add("North",bt1);//this.add(bt1,BorderLayout.NORTH);
		this.add("South",bt2);
		this.add("West",bt3);
		this.add("East",bt4);
		this.add("Center",bt5);
	}
	
	public static void main(String[] ar) {
		new Exam07("제목");
		
	}

}


//CardLayout에대한 예제임
import java.awt.*;
public class Exam08 extends Frame{
	private Button bt1 = new Button("1");
	private Button bt2 = new Button("2");
	private Button bt3 = new Button("3");
	private Button bt4 = new Button("4");
	private Button bt5 = new Button("5");
	
	private CardLayout cl = new CardLayout();//객체cl은 디폴트카드레이아웃입니다.
	
	public Exam08(String title) {	
		super(title);//super은 상위 생성자를 호출한다는 뜻이다.
		
		this.init();
		
		super.setSize(500,300);
		
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frm = super.getSize();
		int xpos = (int)(screen.getWidth()/2-frm.getWidth()/2);
		int ypos = (int)(screen.getHeight()/2-frm.getHeight()/2);
		super.setLocation(xpos,ypos);
		
		super.setResizable(false);
		super.setVisible(true);		
		
		try {
			Thread.sleep(2000);
			cl.show(this,"bb");
		}catch(InterruptedException e) {}
		try {
			Thread.sleep(2000);
			cl.show(this,"cc");
		}catch(InterruptedException e) {}
		try {
			Thread.sleep(2000);
			cl.show(this,"dd");
		}catch(InterruptedException e) {}
		try {
			Thread.sleep(2000);
			cl.show(this,"ee");
		}catch(InterruptedException e) {}
		try {
			Thread.sleep(2000);
			cl.show(this,"aa");
		}catch(InterruptedException e) {}
		
	}
	public void init() {
		this.setLayout(cl);
		this.add("aa",bt1);
		this.add("bb",bt2);
		this.add("cc",bt3);
		this.add("dd",bt4);
		this.add("ee",bt5);
	}
	
	public static void main(String[] ar) {
		new Exam08("제목");
		
	}

}

//스윙패키지 사용하여 구성되는 GUI예제임.
import javax.swing.*;
import java.awt.*;

public class Exam09 extends JFrame{
	public Exam09() {
		setTitle("ContentPane과JFrame");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		Container c = getContentPane();//컨텐트펜의 정보를 
		c.setBackground(Color.green);
		c.setLayout(new FlowLayout());
		
		c.add(new JButton("ok"));		
		c.add(new JButton("Cancel"));
		c.add(new JButton("Ignore"));
		c.add(new JButton("ok2"));
		c.add(new JButton("ok3"));
		c.add(new JButton("ok4"));
		
		setSize(300,400);
		setVisible(true);
	}
	
	public static void main(String[] ar) {
		Exam09 ep = new Exam09();
	}

}

//스윙패키지 사용하여 구성되는 GUI예제임.
import javax.swing.*;
import java.awt.*;

public class Exam09 extends JFrame{
	public Exam09() {
		setTitle("ContentPane과JFrame");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		Container c = getContentPane();//컨텐트펜의 정보를 
		c.setBackground(Color.green);
		c.setLayout(new FlowLayout());
		
		c.add(new JButton("ok"));		
		c.add(new JButton("Cancel"));
		c.add(new JButton("Ignore"));
		c.add(new JButton("ok2"));
		c.add(new JButton("ok3"));
		c.add(new JButton("ok4"));
		
		setSize(300,400);
		setVisible(true);
	}
	
	public static void main(String[] ar) {
		Exam09 ep = new Exam09();
	}

}

'JAVA' 카테고리의 다른 글

10일차  (0) 2021.04.07
9일차  (0) 2021.04.07
7일차  (0) 2021.03.12
6일차  (0) 2021.03.11
5일차  (0) 2021.03.10