'컴퓨터공학부 > 고급객체지향프로그래밍(Java)' 카테고리의 다른 글

과제#3  (0) 2010.12.01
과제  (0) 2010.11.26
다음주 이어서  (0) 2010.11.17
흑흑  (0) 2010.11.01
과제2  (0) 2010.10.29

'컴퓨터공학부 > 고급객체지향프로그래밍(Java)' 카테고리의 다른 글

다음주 이어서 ~피자주문  (0) 2010.12.08
과제  (0) 2010.11.26
다음주 이어서  (0) 2010.11.17
흑흑  (0) 2010.11.01
과제2  (0) 2010.10.29

'컴퓨터공학부 > 고급객체지향프로그래밍(Java)' 카테고리의 다른 글

다음주 이어서 ~피자주문  (0) 2010.12.08
과제#3  (0) 2010.12.01
다음주 이어서  (0) 2010.11.17
흑흑  (0) 2010.11.01
과제2  (0) 2010.10.29

'컴퓨터공학부 > 고급객체지향프로그래밍(Java)' 카테고리의 다른 글

과제#3  (0) 2010.12.01
과제  (0) 2010.11.26
흑흑  (0) 2010.11.01
과제2  (0) 2010.10.29
FlowLayout  (0) 2010.10.29

'컴퓨터공학부 > 고급객체지향프로그래밍(Java)' 카테고리의 다른 글

과제  (0) 2010.11.26
다음주 이어서  (0) 2010.11.17
과제2  (0) 2010.10.29
FlowLayout  (0) 2010.10.29
CardLayout 클래스  (0) 2010.10.29

'컴퓨터공학부 > 고급객체지향프로그래밍(Java)' 카테고리의 다른 글

다음주 이어서  (0) 2010.11.17
흑흑  (0) 2010.11.01
FlowLayout  (0) 2010.10.29
CardLayout 클래스  (0) 2010.10.29
BoxLayout 클래스  (0) 2010.10.29

가장 간단한 배치 관리자로서 각 컴포넌트들은 하나의 줄에서 차례로 배치되고 더 이상 공간이 없으면 다음 줄에 배치된다. 같은 줄에서 컴포넌트들이 정렬되는 방식도 지정이 가능하다. 기본적인 정렬 방법은 중앙에 정렬하는 방법이다. 다른 정렬 방법을 사용하려면 FlowLayout 생성자에서 지정을 하여야 한다. FlowLayout은 JPanel 클래스의 디폴트 배치 관리자이다. 컨테이너의 크기가 변경되면 자동적으로 각 컴포넌트가 재배치된다.


import javax.swing.*;
import java.awt.*;

public class MyFrame extends JFrame
{
   
    public MyFrame()
    {
        this.setTitle("FlowLayoutTest");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        this.setSize(300,200);
       
        JPanel panel = new JPanel();
        panel.setLayout(new FlowLayout());
        JButton b1 = new JButton("Button1");
        JButton b2 = new JButton("Button2");
        JButton b3 = new JButton("Button3");
        JButton b4 = new JButton("Button4");
        JButton b5 = new JButton("Button4");
        panel.add(b1);
        panel.add(b2);
        panel.add(b3);
        panel.add(b4);
        panel.add(b5);
        this.add(panel);
        pack();//프레임을 패널크기에 맞추기
        this.setVisible(true);
    }

 
}

'컴퓨터공학부 > 고급객체지향프로그래밍(Java)' 카테고리의 다른 글

흑흑  (0) 2010.11.01
과제2  (0) 2010.10.29
CardLayout 클래스  (0) 2010.10.29
BoxLayout 클래스  (0) 2010.10.29
GridLayout 클래스  (0) 2010.10.29
여러 개의 카드가 쌓여 있는 형태로 컴포넌트를 배치하는 경우에 사용한다. CardLayout 클래스를 사용하였을 경우 항상 맨 위의 컴포넌트만이 보인다. 사용자는 화면에 보이는 카드를 여러 가지 CardLayout 클래스의 메소드를 사용하여 선택할 수 있다. 즉 맨 처음이나 마지막 카드, 다음 카드, 이전 카드, 특정한 이름을 갖는 카드를 지정할 수 있다.


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MyFrame4 extends JFrame
{
    public MyFrame4()
    {
        this.setTitle("CardLayoutTest");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(400,200);
       
        JPanel panel = new JPanel(new GridLayout(1,5));
        CreateButton("<<",panel);
        CreateButton("<",panel);
        CreateButton(">",panel);
        CreateButton(">>",panel);
        CreateButton("종료",panel);
       
        this.add(panel);
        this.setVisible(true);
    }
   
    private void CreateButton(String bt, JPanel panel)
    {
        JButton b = new JButton(bt);
        panel.add(b);
    }
}










import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
 * 여기?? MyFrame4 ???래스 설명??? 작성하십시오.
 *
 * @author (작성?? ???름)
 * @version (버전번호나 날짜)
 */
public class MyFrame4 extends JFrame implements ActionListener
{
    Cards cards;
    JPanel panel;
    public MyFrame4()
    {
        this.setTitle("CardLayoutTest");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(400,200);
       
        panel = new JPanel(new GridLayout(1,5));
        CreateButton("<<",panel);
        CreateButton("<",panel);
        CreateButton(">",panel);
        CreateButton(">>",panel);
        CreateButton("종료",panel);
       
        this.add(panel,BorderLayout.NORTH);
       
        cards = new Cards();
        this.add(cards, BorderLayout.CENTER);
        this.setVisible(true);
    }
   
    private void CreateButton(String bt, JPanel panel)
    {
        JButton b = new JButton(bt);
        b.addActionListener();
        panel.add(b);
    }
    class Cards extends JPanel
    {
        CardLayout cl;
        public Cards()
        {
            cl = new CardsLayout();
            setLayout(cl);
            for(int i=1;i<=10;i++)
            {
                add(new JButton("현재 카드의 번호는"+i+"입니다."),"Center");
            }
        }
    }
    public void actionPerformed(ActionEvent e)
    {
        String s = e.getActionCommand();
        if(s=="종료")
        {
            System.exit(0);
        }
        else if(s=="<<")
        {
            cards.first(cl);
        }
        else if(s=="<")
        {
            cards.previous(cl);
        }
        else if(s==">")
        {
            cards.next(cl);
        }
        else if(s==">>")
        {
            cards.last(cl);
        }
       
       
    }
}

'컴퓨터공학부 > 고급객체지향프로그래밍(Java)' 카테고리의 다른 글

과제2  (0) 2010.10.29
FlowLayout  (0) 2010.10.29
BoxLayout 클래스  (0) 2010.10.29
GridLayout 클래스  (0) 2010.10.29
BorderLayout 클래스  (0) 2010.10.29

BoxLayout은 컴포넌트를 다른 컴포넌트 위에 쌓거나 컴포넌트를 하나의 행에 배치할수 있다. BoxLayout은 FlowLayout의 하나의 버전으로 간주할 수 있으나 좀 더 기능이 많다.

import javax.swing.*;
import java.awt.*;

public class MyFrame3 extends JFrame
{

    public MyFrame3()
    {
        this.setTitle("BoxLayoutTest");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
       
/*        JButton b1 = new JButton("Button1");
        b1.setAlignmentX(JComponent.CENTER_ALIGNMENT);
        panel.add(b1);
       
      

        JButton b2 = new JButton("Button2------------");
        b2.setAlignmentX(JComponent.CENTER_ALIGNMENT);
        panel.add(b2);
       
        JButton b3 = new JButton("Button3-----");
        b3.setAlignmentX(JComponent.CENTER_ALIGNMENT);
        panel.add(b3);
        */
      
        CreateButton("Button1", panel);
        CreateButton("Button2---------------", panel);
        CreateButton("Button3----", panel);
       
       
       
        this.add(panel);
       
        this.pack();//프레임을 패널 크기에 맞추기
        this.setVisible(true);
    }
   
    private void CreateButton(String bt, JPanel panel)
    {
        JButton b = new JButton(bt);
        b.setAlignmentX(JComponent.CENTER_ALIGNMENT);
        panel.add(b);
    }
   
}

'컴퓨터공학부 > 고급객체지향프로그래밍(Java)' 카테고리의 다른 글

FlowLayout  (0) 2010.10.29
CardLayout 클래스  (0) 2010.10.29
GridLayout 클래스  (0) 2010.10.29
BorderLayout 클래스  (0) 2010.10.29
10/22 중간고사  (0) 2010.10.22
컴포넌트들을 격자 모양으로 배치한다. 모든 컴포넌트들의 크기는 같게 되며 컨테이너의 모든 공간은 컴포넌트로 채워진다. 윈도우의 크기를 바꾸면 GridLayout은 컴포넌트의 크기를 변경하여 윈도우의 크기에 맞춘다.
 

1

2

3

4

5

 

import javax.swing.*;
import java.awt.*;

public class MyFrame2 extends JFrame
{

    public MyFrame2()
    {
        this.setTitle("GridLayoutTest");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0,3));
       
        panel.add(new JButton("1"));
        panel.add(new JButton("2"));
        panel.add(new JButton("3"));
        panel.add(new JButton("4"));
        panel.add(new JButton("5"));
        this.add(panel);
       
        this.pack();//프레임을 패널 크기에 맞추기
        this.setVisible(true);
    }

   
}

+ Recent posts