home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1996 December
/
PCWKCD1296.iso
/
vjplusb
/
msdev
/
samples
/
sun
/
cardtest
/
cardtest.java
< prev
next >
Wrap
Text File
|
1996-07-10
|
4KB
|
114 lines
/*
* @(#)CardTest.java 1.7 95/08/23 Arthur van Hoff
*
* Copyright (c) 1994-1995 Sun Microsystems, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
* without fee is hereby granted.
* Please refer to the file http://java.sun.com/copy_trademarks.html
* for further important copyright and trademark information and to
* http://java.sun.com/licensing.html for further important licensing
* information for the Java (tm) Technology.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*
* THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
* CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
* PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
* NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
* SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
* SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
* PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). SUN
* SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
* HIGH RISK ACTIVITIES.
*/
import java.awt.*;
import java.applet.Applet;
class CardPanel extends Panel {
Panel create(LayoutManager layout) {
Panel p = new Panel();
p.setLayout(layout);
p.add("North", new Button("one"));
p.add("West", new Button("two"));
p.add("South", new Button("three"));
p.add("East", new Button("four"));
p.add("Center", new Button("five"));
return p;
}
CardPanel() {
setLayout(new CardLayout());
add("one", create(new FlowLayout()));
add("two", create(new BorderLayout()));
add("three", create(new GridLayout(2, 2)));
add("four", create(new BorderLayout(10, 10)));
add("five", create(new FlowLayout(FlowLayout.LEFT, 10, 10)));
add("six", create(new GridLayout(2, 2, 10, 10)));
}
public Dimension preferredSize() {
return new Dimension(200, 100);
}
}
public class cardtest extends Applet {
CardPanel cards;
public cardtest() {
setLayout(new BorderLayout());
add("Center", cards = new CardPanel());
Panel p = new Panel();
p.setLayout(new FlowLayout());
add("South", p);
p.add(new Button("first"));
p.add(new Button("next"));
p.add(new Button("previous"));
p.add(new Button("last"));
Choice c = new Choice();
c.addItem("one");
c.addItem("two");
c.addItem("three");
c.addItem("four");
c.addItem("five");
p.add(c);
}
public boolean action(Event evt, Object arg) {
if (evt.target instanceof Choice) {
((CardLayout)cards.getLayout()).show(cards,(String)arg);
} else {
if ("first".equals(arg)) {
((CardLayout)cards.getLayout()).first(cards);
} else if ("next".equals(arg)) {
((CardLayout)cards.getLayout()).next(cards);
} else if ("previous".equals(arg)) {
((CardLayout)cards.getLayout()).previous(cards);
} else if ("last".equals(arg)) {
((CardLayout)cards.getLayout()).last(cards);
} else {
((CardLayout)cards.getLayout()).show(cards,(String)arg);
}
}
return true;
}
public static void main(String args[]) {
Frame f = new Frame("CardTest");
cardtest cardTest = new cardtest();
cardTest.init();
cardTest.start();
f.add("Center", cardTest);
f.resize(300, 300);
f.show();
}
}