import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class cardlayout implements ActionListener
{
static CardLayout cl;
static JFrame jf;
static JButton[] jb = new JButton[5];
static Container ct;
public static void main(String args[])
{
/* JFrame Object instansiated */
jf=new JFrame("Maulin");
/* toolkit to get screen size */
Toolkit tk=jf.getToolkit();
Dimension dm=tk.getScreenSize();
jf.setBounds(dm.width/4,dm.width/4,dm.height/2,dm.height/2);
/* Card Layout instansiated*/
cl=new CardLayout(50,50);
/*get contentpane of JFrame which return Container */
Container ct=jf.getContentPane();
/* set Card Layout for Container */
ct.setLayout(cl);
for(int i=0;i<5;i++)
{
jb[i]=new JButton("Maulin"+i);
jb[i].addActionListener(new cardlayout());
}
for(int i=0;i<5;i++)
{
/*Adding Button to Container(JFrame)*/
ct.add(jb[i],"Maulin"+i);
}
/*First Card Display on Screen :) First Button display*/
cl.show(jf.getContentPane(),"Maulin"+2);
jf.setVisible(true);
/*Destroy the Frame*/
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
cl.next(jf.getContentPane());
}
}
No comments:
Post a Comment