Java / AWT - 카드 레이아웃

Posted 2007/11/07 10:14, Filed under: 프로그래밍/Java

import java.awt.*;
import java.awt.event.*;

public class SimpleCard extends Frame implements ItemListener
{
	private Panel body, ps[];
	private Choice choice;
	private CardLayout card;
	private int selected; //현재 선택된 패널 번호

	public SimpleCard()
	{
		super("카드 레이아웃");
		body = new Panel();
		body.setLayout(card = new CardLayout());
		MouseHandler handler = new MouseHandler();
	
		String data[] = {"First", "Second", "Third", "Fourth", "Fifth"};
		Color colors[] = {Color.YELLOW, Color.GREEN,
Color.MAGENTA, Color.WHITE, Color.CYAN}; ps = new Panel[data.length]; for (int i=0; i < ps.length; i++) { ps[i] = new Panel(); ps[i].setBackground(colors[i]); ps[i].add(new Label(data[i] + " Panel")); ps[i].addMouseListener(handler); body.add(String.valueOf(i), ps[i]); } card.show(body, "0"); selected = 0; choice = new Choice(); choice.addItemListener(this); for (int i=0; i < ps.length; i++) { choice.add(String.valueOf(i+1)); } add(choice, "East"); add(body, "Center"); addWindowListener(new WindowHandler()); setSize(300, 200); setVisible(true); } public void itemStateChanged(ItemEvent e) { Object o = e.getSource(); if (o == choice) { int index = choice.getSelectedIndex(); card.show(body, String.valueOf(index)); selected = index; } } public class MouseHandler extends MouseAdapter { public void mouseClicked(MouseEvent e) { card.next(body); selected = (selected + 1) % ps.length; choice.select(selected); } } public class WindowHandler extends WindowAdapter { public void windowClosing(WindowEvent e) { setVisible(false); dispose(); System.exit(0); } } public static void main(String args[]) { new SimpleCard(); } }
사용자 삽입 이미지
2007/11/07 10:14 2007/11/07 10:14

Trackback URL : http://mysilpir.net/trackback/272

Leave a comment

« Previous : 1 : ... 54 : 55 : 56 : 57 : 58 : 59 : 60 : 61 : 62 : ... 270 : Next »

블로그 이미지

일상의 이야기를 나누는 공간입니다.

- 실피

Calendar

    «   2009/01   »
            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

Total 157613 hit (Today 58, Yesterday 185)

Admin Write Post