일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- crud
- nodejs
- 맥
- Android
- jsp
- FastAPI
- 객체지향
- python
- spring
- 이클립스
- 자바문제
- ibatis
- Oracle
- 생활코딩
- Error
- 반복문
- 배열
- ddit
- Homebrew
- 대덕인재개발원
- 자바
- 컬렉션프레임워크
- JDBC
- html
- 단축키
- API
- Mac
- pyqt
- Java
- servlet
Archives
- Today
- Total
romworld
Python 05 - JFrame (JAVA) 본문
AWT
자바에서 실행을 시킬 때 window창 = Frame
package day04;
import java.awt.Frame;
public class AwtTest {
public static void main(String[] args) {
Frame f = new Frame();
f.setVisible(true);
f.setSize(400,600);
}
}
setVisible = 창을 보이게 하는 것
setSize = 창의 크기

Swing
package day04;
import javax.swing.JFrame;
public class SwingTest {
public static void main(String[] args) {
JFrame f = new JFrame();
f.setVisible(true);
f.setSize(300,300);
}
}
생성 - size - visible
WindowBulider
help - Eclipse Marketplace - windowBuilder 1.10.0 Install

제대로 설치가 되었다면 project를 생성할 때 다운 받아져 있는 걸 확인할 수 있다.

Swing을 실행해보자!

project에서 JFrame 생성
<Swing01.java>
package day04;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class Swing01 extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Swing01 frame = new Swing01();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Swing01() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
}
}
코드가 자동 생성 되어있다.



activate : 활성화

defalut : BorderLayout
xywh : Absolute layout
,, 이런 식으로 window창 디자인을 할 수 있다
버튼을 클릭하면 Text를 바꿔보세요!
package day04;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class Swing01 extends JFrame {
private JPanel pane;
private JButton btn;
private JLabel lbl;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Swing01 frame = new Swing01();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Swing01() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
setTitle("롬숙제");
pane = new JPanel();
pane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(pane);
pane.setLayout(null);
JLabel lbl = new JLabel("Good Morning");
lbl.setBounds(76, 37, 94, 35);
pane.add(lbl);
//lbl.setText("Good Evening");
JButton btn = new JButton("Click!");
btn.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
lbl.setText("Good Evening");
}
});
// public void actionPerformed(ActionEvent e) {
// if(lbl.getText() == "Good Morning") {
// lbl.setText("Good Evening");
// }else {
// lbl.setText("집에보내도");
// }
// }
btn.setBounds(171,43,97,23);
pane.add(btn);
}
}



실행을 시키면 버튼을 클릭했을 때 text가 바뀐다.
'Python' 카테고리의 다른 글
Python 07 - Android (JAVA) (1) | 2022.12.27 |
---|---|
Python 06 - JFrame(2) (JAVA) (0) | 2022.12.27 |
Python 04 - OOP(Object oriented Programming) 객체 지향 프로그래밍 (0) | 2022.12.26 |
Python 03 - 배열 , for문, 메소드 (0) | 2022.12.23 |
Python 02 - eclipse 설치 (전자정부프레임워크) (0) | 2022.12.23 |
Comments