Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
2.3 kB
1
Indexable
 
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class PR04 extends Applet implements ActionListener {
    Panel main,p1,p2,p3;
    Label l1,l2,l3,l4;
    CardLayout cl;
    Button f,l,p,n;
  public void init()
  {      
      setSize(400,400);
      setLayout(null);
     
      cl= new CardLayout();
      main= new Panel();
      main.setBounds(20,20,280,280);
      main.setBackground(Color.gray);
      main.setLayout(cl);
      add(main);
      p1= new Panel();
      p1.setBounds(20,20,300,300);
      p1.setBackground(Color.PINK);
      main.add(p1);
  
      
      l2=new Label("First Label");
      l2.setBounds(100,-100,250,250);
      l2.setFont(new Font("Arial",Font.BOLD,20));
      p1.add(l2);
      
      
      p2= new Panel();
      p2.setBounds(20,20,300,300);
      p2.setBackground(Color.YELLOW);
      main.add(p2);
      
      l3=new Label("Second Label");
      l3.setBounds(100,-100,250,250);
      l3.setFont(new Font("Arial",Font.BOLD,20));
      p2.add(l3);

      p3= new Panel();
      p3.setBounds(20,20,300,300);
      p3.setBackground(Color.BLUE);
      main.add(p3);
      
      l4=new Label("Three Label");
      l4.setBounds(100,-100,250,250);
      l4.setFont(new Font("Arial",Font.BOLD,20));
      p3.add(l4);
      
      //First button
      f= new Button("First");
      f.setBounds(30,340,50,30);
      f.addActionListener(this);
      add(f);
      
      n= new Button("Next");
      n.setBounds(90,340,50,30);
      n.addActionListener(this);
      add(n);
      
      p= new Button("Previous");
      p.setBounds(150,340,70,30);
      p.addActionListener(this);
      add(p);
      
      l= new Button("Last");
      l.setBounds(230,340,50,30);
      l.addActionListener(this);
      add(l);
      
  }
  
  public void actionPerformed(ActionEvent ae)
  {
        if(ae.getSource()== f)
        {
           cl.first(main);
        }
        else if(ae.getSource()== n)
        {
            cl.next(main);
        }
        else if(ae.getSource()== p)
        {
            cl.previous(main);
        }
        else if(ae.getSource()== l)
        {
            cl.last(main);
        }
    }
}  
Leave a Comment