여러 개의 카드가 쌓여 있는 형태로 컴포넌트를 배치하는 경우에 사용한다. 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);
    }

   
}

BorderLayout은 아래 그림처럼 컨테이너를 5개의 영역으로 구분하고 각각의 영역에 컴포넌트를 배치할수 있다.
 

Page Start

Line Start

Center

Line End

Page End

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

public class MyFrame extends JFrame
{

    public MyFrame()
    {
        this.setTitle("BorderLayout");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
       
        panel.add(new JButton("E"),BorderLayout.EAST);
        panel.add(new JButton("W"),BorderLayout.WEST);
        panel.add(new JButton("S"),BorderLayout.SOUTH);
        panel.add(new JButton("N"),BorderLayout.NORTH);
        panel.add(new JButton("C"),BorderLayout.CENTER);
        this.add(panel);
       
        this.pack();//프레임을 패널 크기에 맞추기
        this.setVisible(true);
    }

}


이번주 한일

 작성일 :       2010-10-29

 작성자 :         김 동영

날 짜

학습내용

예상소요시간

실제소요시간

10/25 월요일

API 1

(윈도우즈 프로그래밍)

3시간

3시간(100%)

10/27 수요일

API 2

(첫 번째 예제)

3시간

3시간(80%)

10/28 목요일

API 3

(출력)

3시간

 

 

화요일에 학과행사로 인해 참여를 못하여 수요일에 보고서 작성을

전달받아 1장의 공부내용을 정리하느냐고 계획했던 3장을 학습하지

못하였습니다. 1장에서 윈도우 프로그래밍의 특징과 역사를 알게되었고,

2장에서는 기본틀에 대해 알게 되었습니다.

신세계를 접하여 흥미를 가지고

공부중입니다.

'기타 > API' 카테고리의 다른 글

창 크기 알아오기  (0) 2011.02.07
wchar->double ,char->double 캐스팅  (1) 2011.02.07
주소록  (0) 2011.01.10
똑딱이  (0) 2011.01.05
[예비 21기 김동영] 주간 계획서 1차  (0) 2010.10.27

'컴퓨터공학부 > 소프트웨어설계론' 카테고리의 다른 글

실습  (0) 2010.11.17
과제#2  (0) 2010.11.15
StateChart Diagram  (0) 2010.11.08
중간고사  (0) 2010.10.11
레스토랑 Activity Diagram  (0) 2010.10.06

주간 보고서

 작성일 :       2010-10-27

 작성자 :         김 동영

날 짜

학습내용

예상소요시간

실제소요시간

10/25 월요일

API 1

(윈도우즈 프로그래밍)

3시간

3시간

10/27 수요일

API 2

(첫 번째 예제)

3시간

 

10/28 목요일

API 3

(출력)

3시간

 

 

 

본격적으로 API를 공부하기 앞서 25일에는 윈도우즈 프로그래밍이 무엇인지 기초부터 다져서 꼼꼼히 공부를 하고 27일에는 API예제를 통하여 API를 접해보고 28일에는 나아가 출력부분에 대해 공부할 계획입니다.

 

 

 

'기타 > API' 카테고리의 다른 글

창 크기 알아오기  (0) 2011.02.07
wchar->double ,char->double 캐스팅  (1) 2011.02.07
주소록  (0) 2011.01.10
똑딱이  (0) 2011.01.05
[예비 21기 김동영] 주간 과제물 1차  (0) 2010.10.28

'ISLab' 카테고리의 다른 글

간단한 API 예제  (0) 2010.11.23
API란  (0) 2010.11.03
연구실 PPT폼  (0) 2010.10.27

'ISLab' 카테고리의 다른 글

간단한 API 예제  (0) 2010.11.23
API란  (0) 2010.11.03
매직아이 어플리케이션  (0) 2010.10.27

+ Recent posts