자바 AWT 카드레이아웃 (cardlayout) 예제
import java.awt.*;
import java.awt.event.*;
import java.awt.event.*;
public class CardLayoutTest1 extends Frame {
public static void main(String[] args) {
Frame f = new Frame("CardLayoutTest");
final Panel tabs = new Panel();
tabs.add(new Button("<<"));
tabs.add(new Button("<"));
tabs.add(new Button("Options"));
tabs.add(new Button("Settings"));
tabs.add(new Button("Preferences"));
tabs.add(new Button(">"));
tabs.add(new Button(">>"));
f.add(tabs, "North");
final CardLayout layout = new CardLayout();
final Panel cards = new Panel(layout);
cards.add(new CardPanel("Options"), "Options");
cards.add(new CardPanel("Settings"), "Settings");
cards.add(new CardPanel("Preferences"), "Preferences");
f.add(cards, "Center");
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent ev) {
String cmd = ev.getActionCommand();
if (cmd.equals("<<")) layout.first(cards);
else if (cmd.equals("<")) layout.previous(cards);
else if (cmd.equals(">")) layout.next(cards);
else if (cmd.equals(">>")) layout.last(cards);
else layout.show(cards, cmd);
}
};
for(int i=0; i<tabs.getComponentCount();i++) {
((Button)tabs.getComponent(i)).addActionListener(al);
}
f.setSize(400, 300);
f.setVisible(true);
f.addWindowListener(new WindowListenerProcessing() );
}
}
public static void main(String[] args) {
Frame f = new Frame("CardLayoutTest");
final Panel tabs = new Panel();
tabs.add(new Button("<<"));
tabs.add(new Button("<"));
tabs.add(new Button("Options"));
tabs.add(new Button("Settings"));
tabs.add(new Button("Preferences"));
tabs.add(new Button(">"));
tabs.add(new Button(">>"));
f.add(tabs, "North");
final CardLayout layout = new CardLayout();
final Panel cards = new Panel(layout);
cards.add(new CardPanel("Options"), "Options");
cards.add(new CardPanel("Settings"), "Settings");
cards.add(new CardPanel("Preferences"), "Preferences");
f.add(cards, "Center");
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent ev) {
String cmd = ev.getActionCommand();
if (cmd.equals("<<")) layout.first(cards);
else if (cmd.equals("<")) layout.previous(cards);
else if (cmd.equals(">")) layout.next(cards);
else if (cmd.equals(">>")) layout.last(cards);
else layout.show(cards, cmd);
}
};
for(int i=0; i<tabs.getComponentCount();i++) {
((Button)tabs.getComponent(i)).addActionListener(al);
}
f.setSize(400, 300);
f.setVisible(true);
f.addWindowListener(new WindowListenerProcessing() );
}
}
class CardPanel extends Panel {
CardPanel(String name) {
setLayout(new BorderLayout());
add(new Label("CardPanel : " + name, Label.CENTER),"Center");
Panel p = new Panel();
add(p, "South");
Button btn = new Button("Close");
ActionListener a1 = new ActionListener() {
public void actionPerformed(ActionEvent ev) {
String cmd = ev.getActionCommand();
if (cmd.equals("Close")) {
System.exit(0);
}
}
};
btn.addActionListener(a1);
p.add(btn);
}
}
CardPanel(String name) {
setLayout(new BorderLayout());
add(new Label("CardPanel : " + name, Label.CENTER),"Center");
Panel p = new Panel();
add(p, "South");
Button btn = new Button("Close");
ActionListener a1 = new ActionListener() {
public void actionPerformed(ActionEvent ev) {
String cmd = ev.getActionCommand();
if (cmd.equals("Close")) {
System.exit(0);
}
}
};
btn.addActionListener(a1);
p.add(btn);
}
}
class WindowListenerProcessing extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
=================================================================================
[오프라인 개강예정강좌, 오프라인교육장에 오시면 보다 자세히 배울 수 있습니다.]
오라클자바커뮤니티에서 운영하는 개발자 전문교육 ,개인80%환급(www.onjprogramming.co.kr)
[주간]
[01/06][기업100%환급]Spring ,MyBatis,Hibernate실무과정
[01/06][기업100%환급]SQL기초에서 Schema Object까지
[01/06]C#,ASP.NET마스터
[01/13]iPhone 하이브리드 앱 개발 실무과정
[01/13][기업100%환급]PL/SQL,ORACLE HINT,TUNING
[01/13][기업100%환급]자바기초에서 JDBC, Servlet/JSP까지
[01/13][기업100%환급]HTML5,JavaScript,Ajax,jQUERY,JSON
[01/16][채용확정]오라클자바실무개발자신입과정
[평일야간]
[01/07]자바기초에서JSP,Ajax,jQuery,Spring3.2,MyBatis까지
[01/07]안드로이드개발자과정
[01/08]C#,ASP.NET마스터
[01/09]iPhone하이브리드앱개발실무과정
[01/09]웹퍼블리싱 마스터
[01/09]Spring3.X, MyBatis, Hibernate실무과정
[01/24]SQL초보에서실전전문가까지
[주말]
[01/04]닷넷실무자를위한WPF개발자과정
[01/04]Spring3.X,MyBatis,Hibernate실무과정
[01/11]C#,ASP.NET마스터
[01/11]JAVA&WEB프레임워크실무과정
[01/11]안드로이드개발자과정
[01/11]SQL초보에서전문가까지
[01/18]웹퍼블리싱 마스터
오라클자바커뮤니티에서 운영하는 개발자 전문교육 ,개인80%환급(www.onjprogramming.co.kr)
[주간]
[01/06][기업100%환급]Spring ,MyBatis,Hibernate실무과정
[01/06][기업100%환급]SQL기초에서 Schema Object까지
[01/06]C#,ASP.NET마스터
[01/13]iPhone 하이브리드 앱 개발 실무과정
[01/13][기업100%환급]PL/SQL,ORACLE HINT,TUNING
[01/13][기업100%환급]자바기초에서 JDBC, Servlet/JSP까지
[01/13][기업100%환급]HTML5,JavaScript,Ajax,jQUERY,JSON
[01/16][채용확정]오라클자바실무개발자신입과정
[평일야간]
[01/07]자바기초에서JSP,Ajax,jQuery,Spring3.2,MyBatis까지
[01/07]안드로이드개발자과정
[01/08]C#,ASP.NET마스터
[01/09]iPhone하이브리드앱개발실무과정
[01/09]웹퍼블리싱 마스터
[01/09]Spring3.X, MyBatis, Hibernate실무과정
[01/24]SQL초보에서실전전문가까지
[주말]
[01/04]닷넷실무자를위한WPF개발자과정
[01/04]Spring3.X,MyBatis,Hibernate실무과정
[01/11]C#,ASP.NET마스터
[01/11]JAVA&WEB프레임워크실무과정
[01/11]안드로이드개발자과정
[01/11]SQL초보에서전문가까지
[01/18]웹퍼블리싱 마스터
홈페이지 바로가기 : http://www.oraclejavanew.kr/
댓글 없음:
댓글 쓰기