JAVA/Swing

JAVA/Swing

[JAVA] Image

package gui; import java.awt.GridLayout; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class S14_Image { public static void main(String[] args) { JFrame f = new JFrame("Image..."); JLabel image1 = new JLabel(); JLa..

JAVA/Swing

[JAVA] FlowLayout

package gui; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; public class S13_FlowLayout { public static void main(String[] args) { JFrame f = new JFrame("Flow..."); FlowLayout flow = new FlowLayout(); for (int i = 0; i < 30; ++i) { f.add(new JButton("button" + i)); } f.setLayout(flow); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setBounds(100, 100, 500..

JAVA/Swing

[JAVA] JPanel

package gui; import java.awt.BorderLayout; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class S12_JPanel { /* # JPanel - 컨테이너 역할을 하는 컴포넌트 - 레이아웃 위에 또 다른 레이아웃을 설정할 수 있다. */ public static void main(String[] args) { JFrame mainFrame = new JFrame("JPanel Test"); GridLayout grid = new GridLayout(2,2); JButton b1 = new JButton("1"..

JAVA/Swing

[JAVA] GridLayout

package gui; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; public class { public static void main(String[] args) { JFrame f = new JFrame("GridLayout Example"); GridLayout grid = new GridLayout(3, 5); // 여백 설정 grid.setHgap(5); // Horizontal gap grid.setVgap(5); // Vertical gap for (int i = 0; i < 15; ++i) { f.add(new JButton("button" + i)); } f.setLayout(grid)..

JAVA/Swing

[JAVA] JComboBox

package gui; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.JComboBox; import javax.swing.JFrame; import myobj.Prize; public class S10_JComboBox { public static void main(String[] args) { JFrame f = new JFrame("ComboBox Example"); Prize[] prizes = new Prize[] { new Prize("텀블러", 10000, 100, 0.1), new Prize("안마의자", 2000000, 1, 0.01), new Prize("손소독제", 5000,..

JAVA/Swing

[JAVA] JRadioButton

package gui; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JRadioButton; public class S09_JRadioButton { public static void main(String[] args) { JFrame f = new JFrame("Radio Button Examle"); JRadioButton btn1 = new JRadioButton("Left"); JRadioButton btn2 = new JRadioButton("Right"); btn1.setBounds(50, 100, 100, 50); btn2.setBounds(150, 100, 100, 50); // 버튼 그룹 (그룹..

JAVA/Swing

[JAVA] JCheckBox

JCheckBox - 체크할 수 있는 박스를 만드는 클래스 ItemListener listener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { System.out.println(((JCheckBox)e.getSource()).getText() + " 버튼이 방금 변경되었습니다.."); } }; addItemListener(listener) - 체크박스 컴포넌트의 상태가 변경될 때마다 발생하는 이벤트 setSelected(boolean) - 선택된 것으로 설정하기 (아이템 리스너 발동시킴) doClick() - 프로그램적으로 클릭 발생시키기 (아이템 리스너 발동..

JAVA/Swing

[JAVA] JPasswordField

JPasswordField class - 비밀번호를 입력할 때 사용하는 필드 package gui; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; public class S07_JPasswordField extends JFrame { // 비밀번호를 입력할 때 사용하는 필드 public S07_JPasswordField() { JLabel id_label = new JLabel("ID:"); JTextField id_field = new JTextField(); JLabel pw_label = new JLabel("PW:")..

로아다
'JAVA/Swing' 카테고리의 글 목록