How to use CardLAyout without using applets???
I tried it but at the compile time it throwed IllegalArgumentException.
my code is....
Code java:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
public class cards extends JFrame
{
JPanel p1,p2,cards;
JLabel l1,l2;
JButton b1,b2;
public cards()
{
//super("card1");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new CardLayout());
l1=new JLabel("card1....");
l2=new JLabel("card2....");
b1=new JButton("b1....");
b2=new JButton("b2....");
p1=new JPanel(new FlowLayout());
p2=new JPanel(new FlowLayout());
p1.add(l1);
p1.add(b1);
p2.add(l2);
p2.add(b2);
add(p1);
add(p2);
}
public static void main(String[] args)
{
cards c=new cards();
c.setSize(300,300);
c.setVisible(true);
}
}
i m jst a beginner!!!!!!!!!!!
Re: How to use CardLAyout without using applets???
How to Use CardLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
I added highlight tags for you this time, don't forget them in the future. Also, see the link in my signature on asking smart questions. What's happening in your code? What did you expect to happen? Another piece of advice- use standard naming conventions. Classes start with uppercase letters.
Re: How to use CardLAyout without using applets???
Quote:
Originally Posted by
divyarattan
I tried it but at the compile time it throwed IllegalArgumentException.
If you want help with exceptions or error messages, post the full text of the error message, complete with stack trace if present.
Re: How to use CardLAyout without using applets???
Please post in the correct forum. Thread moved to - AWT / Java Swing
Re: How to use CardLAyout without using applets???
Hi divyarattan,
You are using the CardLayout incorrectly:
setLayout(new CardLayout());
add(p1);
The correct way is:
setLayout(new CardLayout());
add(p1, "Name_of_the_card");
For each component added to the card, you should give it a name, so later you can show that card:
((CardLayout) getLayout()).show("Name_of_the_card"))
immutable objects