21.01.13

1403 ワード

3つのレイアウト
BorderLayout東南北西センターパネル付きレイアウト
レイアウトは、FlowLayoutパネルまたはフレームのサイズに応じてパネルの位置を変更できます.
Null Layoutパネルの位置とサイズのレイアウトを設定および作成できます.
JFrameデフォルトborder
JPanelデフォルトフローレイアウト
JFrameTest1
ActionEventTest
package gui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class btnTest extends JFrame {
	
	public btnTest() {
		
		setLayout(null);
		
		setTitle("버튼테스트");
		
		setSize(400,300);
		
		setLocationRelativeTo(null);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel();
		
		panel.setBounds(125,50,150,150);
		
		panel.setBackground(Color.white);
		
		panel.setLayout(null);
		
		JButton btn = new JButton("클릭");
		
		btn.setBounds(25, 25, 100, 100);
		
		btn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println("Click!!!!!!!!!!!!!");
			}
		});
		
		panel.add(btn);
		
		add(panel);
		
		setVisible(true);
	}
	
	class MyActionListener implements ActionListener {
		
		@Override
		public void actionPerformed(ActionEvent e) {
			System.out.println("Click!!!!!!!!!!!!!");
		}
	}

	public static void main(String[] args) {
		
		btnTest b = new btnTest();
	}
}