import java.awt.*; import java.awt.event.*;/** * Sample application using Frame. * * @author * @version 1.00 07/07/14 */ public class CardlayoutFrame extends Frame {
/** * The constructor. */ Panel pl = new Panel(); CardLayout cl = new CardLayout(); public CardlayoutFrame() { pl.setLayout(cl); Button b1 = new Button("1"); Button b2 = new Button("2"); pl.add(b1,"1"); pl.add(b2,"2");
class MyActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { cl.next(pl); } }
MyActionListener mal = new MyActionListener(); b1.addActionListener(mal); b2.addActionListener(mal); add(pl); MenuBar menuBar = new MenuBar(); Menu menuFile = new Menu(); MenuItem menuFileExit = new MenuItem();
import java.awt.event.*;/**
* Sample application using Frame.
*
* @author
* @version 1.00 07/07/14
*/
public class CardlayoutFrame extends Frame {
/**
* The constructor.
*/
Panel pl = new Panel();
CardLayout cl = new CardLayout();
public CardlayoutFrame() {
pl.setLayout(cl);
Button b1 = new Button("1");
Button b2 = new Button("2");
pl.add(b1,"1");
pl.add(b2,"2");
class MyActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
cl.next(pl);
}
}
MyActionListener mal = new MyActionListener();
b1.addActionListener(mal);
b2.addActionListener(mal);
add(pl);
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu();
MenuItem menuFileExit = new MenuItem();
menuFile.setLabel("File");
menuFileExit.setLabel("Exit");
// Add action listener.for the menu button
menuFileExit.addActionListener
(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
CardlayoutFrame.this.windowClosed();
}
}
);
menuFile.add(menuFileExit);
menuBar.add(menuFile);
setTitle("Cardlayout");
setMenuBar(menuBar);
setSize(new Dimension(400, 400));
// Add window listener.
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
CardlayoutFrame.this.windowClosed();
}
}
);
}
/**
* Shutdown procedure when run as an application.
*/
protected void windowClosed() {
// TODO: Check if it is safe to close the application
// Exit application.
System.exit(0);
}
}
/**
* AWT Sample application
*
* @author
* @version 1.00 07/07/14
*/
public class Cardlayout {
public static void main(String[] args) {
// Create application frame.
CardlayoutFrame frame = new CardlayoutFrame();
// Show frame
frame.setVisible(true);
}
}