티스토리 뷰
import javax.swing.JFrame;
// ClI (Command Line Interface) : 콘솔창과 같은 인터페이스
// GUI (Graphic User Interface) : 이클립스와 같은 인터페이스
// JAVA프로그램에서 GUI를 만드는 방법
// 1) AWT패키지의 클래스를 사용
// 2) javax.swing 패키지의 클래스를 사용
public class GUI1 {
public static void main(String[] args) {
JFrame frame = new JFrame(); // 이 방법보다는 상속을 이용하여 사용함
frame.setTitle("프레임");
frame.setSize(300, 300);
frame.setLocation(0, 100); // 화면 왼쪽 상단 모서리 위치 0,0
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 창이 닫히면 자바 프로그램도 종료됨
frame.setVisible(true); // 창을 보여줌
}
}
import javax.swing.JFrame;
class MyFrame1 extends JFrame{
public MyFrame1(){
setTitle("나의 프레임");
setSize(300,300);
setLocation(700,0);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
public class GUI2 {
public static void main(String[] args) {
MyFrame1 myFrame = new MyFrame1();
}
}
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
// 컨테이너 클래스 : Frame, Panel, Applet
// 컴포넌트 클래스 : Button, Label, textField, textArea
class MyFrame2 extends JFrame{
JButton b = new JButton("버튼");
public MyFrame2(){
setLayout(new FlowLayout());
add(b);
setTitle("나의 프레임");
setSize(300,300);
setLocation(700,0);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
public class GUI3 {
public static void main(String[] args) {
new MyFrame2();
}
}
import javax.swing.JFrame;
class MyFrameE extends JFrame{
public MyFrameE(){
setTitle("나의 프레임");
setSize(300,300);
setLocation((1600-300)/2, (900-300)/2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
public class GUI예제1 {
public static void main(String[] args) {
MyFrameE myFrameE = new MyFrameE();
}
}
'JAVA > PRIMER' 카테고리의 다른 글
| [JAVA] GUI - 배치관리자 (0) | 2018.04.19 |
|---|---|
| [JAVA] GUI - JPanel, JLabel, JButton (0) | 2018.04.19 |
| [JAVA] 파일입출력 - FileInputStream, FileOutputStream (0) | 2018.04.19 |
| [JAVA] 파일입출력 - BufferedReader, BufferedWriter (0) | 2018.04.19 |
| [JAVA] 파일입출력 - FileReader, FileWriter (0) | 2018.04.19 |
댓글