Saturday 30 June 2012

program to create a two level card deck that allows a user to select an operating system where windows based operating systems are displayed in one card and other programming operating system in other card in java.


import java.awt.*;
import java.awt.event.*;
import java.applet.*;
 /*
  <applet code="clayout" width=300 height=100>
  </applet>
 */
  public class clayout extends Applet implements ActionListener,MouseListener
{
  Checkbox Win98,winNT,solaris,mac;
  Panel osCards;
  CardLayout cardLO;
  Button Win,Other;

  public void init()
  {
    Win = new Button("Windows");
    Other = new Button("Other");
    add(Win);
    add(Other);
    cardLO = new CardLayout();
    osCards = new Panel();
    osCards.setLayout(cardLO); //set panel layout to card layout
    Win98 = new Checkbox("Windows 98/xp",null,true);
    winNT = new Checkbox("Windows NT/2000");
    solaris = new Checkbox("Solaris");
    mac = new Checkbox("MacOS");



    //add windows check boxes to a panel
    Panel winPan = new Panel();
    winPan.add(Win98);
    winPan.add(winNT);

    // add other os check boxes to a panel
    Panel otherPan = new Panel();
    otherPan.add(solaris);
    otherPan.add(mac);

    //add panels to card deck apnel
    osCards.add(winPan,"Windows");
    osCards.add(otherPan,"Other");

    //add cards to main applet panel
    add(osCards);

    //register to receive action events
    Win.addActionListener(this);
    Other.addActionListener(this);

    //register mouse events
    addMouseListener(this);
  }
   // Cycle through panels.
   public void mousePressed(MouseEvent me)
    {
      cardLO.next(osCards);
    }

    // provide empty implementations for the other maouselistener methods.
    public void mouseClicked(MouseEvent me)
     {
     }
    public void mouseEntered(MouseEvent me)
     {
     }
    public void mouseExited(MouseEvent me)
     {
     }
    public void mouseReleased(MouseEvent me)
     {
     }
    public void actionPerformed(ActionEvent ae)
     {
       if(ae.getSource() == Win)
       {
        cardLO.show(osCards,"Windows");
       }
       else
       {
        cardLO.show(osCards,"Other");
       }
     }
 }

No comments:

Post a Comment