// GUI : 그래픽 환경
- AWT : 자바 초창기 버전에서 사용
- SWING
- 기본적으로 JFrame ==> 빈 화면 ==> 버튼, 텍스트, 체크, 라디오 ...
package ex04.sample04;
import javax.swing.*;
public class Exam1013_3 {
static class MyGUI extends JFrame {
MyGUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 프로그램을 종료하게 한다.
setTitle("연 습");
setSize(500,500); // 픽셀 단위
setVisible(true);
}
}
public static void main(String[] args) {
new MyGUI();
}
}
package ex04.sample04;
import java.awt.*; //레이아웃 사용
import javax.swing.*;
public class Exam1013_3 {
static class MyGUI extends JFrame {
MyGUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("연 습");
this.setLayout(new FlowLayout()); // 레이아웃 설정
JButton btn1 = new JButton("버튼1"); //버튼 만들기
this.add(btn1); // 버튼 올리기
JButton btn2 = new JButton("버튼2");
this.add(btn2);
JButton btn3 = new JButton("버튼3");
this.add(btn3);
JButton btn4 = new JButton("버튼4");
this.add(btn4);
setSize(250,250);
setVisible(true);
}
}
public static void main(String[] args) {
new MyGUI();
}
}
**FlowLayout 은 화면 사이즈에 맞춰서 버튼의 배열을 자동으로 조정해준다.
package ex04.sample04;
import java.awt.*; //레이아웃 사용
import javax.swing.*;
public class Exam1013_3 {
static class MyGUI extends JFrame {
MyGUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("연 습");
this.setLayout(new FlowLayout());
ImageIcon img1 = new ImageIcon("c://image//sign1.png"); //이미지 불러오기
ImageIcon img2 = new ImageIcon("c://image//sign2.png");
JButton btn1 = new JButton("Sign1", img1); // 버튼 이미지 설정
this.add(btn1); // 버튼에 이미지 올리기
JButton btn2 = new JButton("Sign2", img2);
this.add(btn2);
JLabel lbl1 = new JLabel("레이블 1");
JLabel lbl2 = new JLabel("img2");
this.add(lbl2);
this.add(lbl2);
JCheckBox chk1 = new JCheckBox("Java");
JCheckBox chk2 = new JCheckBox("C");
JCheckBox chk3 = new JCheckBox("Python");
this.add(chk1);
this.add(chk2);
this.add(chk3);
JRadioButton rdo1 = new JRadioButton("Java");
JRadioButton rdo2 = new JRadioButton("C");
JRadioButton rdo3 = new JRadioButton("Python");
this.add(rdo1);
this.add(rdo2);
this.add(rdo3);
ButtonGroup grp = new ButtonGroup();
grp.add(rdo1);
grp.add(rdo2);
grp.add(rdo3);
setSize(1000,250);
setVisible(true);
}
}
public static void main(String[] args) {
new MyGUI();
}
}
package ex04.sample04;
import java.awt.*;
import javax.swing.*;
public class Exam1013_3 {
static class MyGUI extends JFrame {
MyGUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("연 습");
this.setLayout(new FlowLayout());
String[] language = {"C", "JavaScript", "Java", "Python", "HTML", "JSP", "Oracle"};
JList list = new JList(language);
this.add(list);
JComboBox combo = new JComboBox(language);
this.add(combo);
setSize(250,250);
setVisible(true);
}
}
public static void main(String[] args) {
new MyGUI();
}
}
package ex04.sample04;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*; //자바의 이벤트 처리
public class Exam1013_3 {
static class MyGUI extends JFrame {
MyGUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("연 습");
this.setLayout(new FlowLayout());
JButton btn1 = new JButton("Click");
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
btn1.setBackground(Color.BLUE);
}
});
this.add(btn1);
setSize(250,250);
setVisible(true);
}
}
public static void main(String[] args) {
new MyGUI();
}
}
'자바(JAVA)' 카테고리의 다른 글
[자바(Java)] 중첩 클래스, 익명 클래스 (0) | 2022.10.20 |
---|---|
[자바(Java)] 접근 지정자(제어자), Getter Setter (0) | 2022.10.18 |
[자바(Java)] 추상 클래스, 인터페이스 (0) | 2022.10.13 |
이클립스 단축키 (0) | 2022.10.11 |
[자바(Java)] 상속 (0) | 2022.10.07 |