0

I'm trying to write an applet that switches between cards using CardLayout, but the app is not showing anything at all and I can't figure out what's wrong. A little help would be much appreciated :)

import javax.swing.*;
import java.awt.*;

public class TEST extends JApplet{


    @Override
    public void init(){

    }

    @Override
    public void start(){

        JPanel cards = new JPanel(new CardLayout());

        JPanel main = new JPanel();
        main.setLayout(new GridLayout(3, 1, 2, 2));

        JTextField jtfEmail = new JTextField("E-mail", 10);
        main.add(jtfEmail);

        JTextField jtfPassword = new JPasswordField("Password", 10);                
        main.add(jtfPassword);

        JPanel buttons = new JPanel();

        JButton jbtLogin = new JButton("Login");        
        buttons.add(jbtLogin);

        JButton jbtRegister = new JButton("Register");
        buttons.add(jbtRegister);        
        main.add(buttons);

        cards.add(main, "Main");

        CardLayout cardLayout = (CardLayout) cards.getLayout();

        cardLayout.show(cards, "Main");
    }
}
2

1 Answer 1

1

Problem: You're not adding anything to the applet's contentPane anywhere.

Solution: Do that -- add something to the applet's contentPane so that you can see it.

Also, you will want to look for an applet tutorial on Google and have a look at it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.