Java learning notes -- show of the card layout manager

Source: Internet
Author: User

Aha, returning to school is efficient ~ But I want to review it again, but I sat down in front of the computer and started to read the program again. No way, I can't ...... I am working on a chat software recently. Do I have to log on to it. I want to create a cardlayout for the login interface, but the problem arises. Now we can take it out and paste several images to record it.

Basic jframe display program:

Import java. AWT .*;
Import javax. Swing .*;

Class demo ...{
Public static void main (string [] ARGs )...{

Cardlayout card = new cardlayout ();
Jframe frame = new jframe ("cardlayout layout test ");
Frame. setdefaclocloseoperation (jframe. exit_on_close );
Jlabel label1 = new jlabel ("lable1 ");
Jlabel label2 = new jlabel ("label2 ");
Frame. setlayout (card );

Frame. Add (label1, "L1 ");
Frame. Add (label2, "L2 ");
Frame. setsize (100,100 );
Container con = frame. getcontentpane ();
Card. Show (con, "L2 ");
Frame. setvisible (true );
}
}

I don't need to paste this interface, but the skin is not very comfortable ...... Let's take a look at the container above the show of the card in the program, or the first parameter con of the show. I did not write this statement in my program, but it does not exist in creating the iner. However, if the first parameter is put in the frame, compilation will pass, but exception will be thrown:

First, yes.Wrong parent for cardlayoutIt seems that there is a problem with the cardlayout. Show (parent, string) parameter. After reading JDK, this show is such a show (container, string). That is to say, the previous parameter is container !! Let's look at the inheritance tree of a class:

See it. Father of jframe's father, that is, Grandpa's father is Java. AWT. container! That is to say, jframe is a container. Why is it impossible to place the jframe that belongs to the iner here? People can eat. Men and women belong to people and can eat. Eunuch is a child of a man's inheritance class and can eat, but eunuch without a mouth is a child of eunuch's inheritance class. Although they are all human beings, he/she/he cannot eat because he/she has no mouth. In another thought, isn't jframe having a getcontentpane () method? Why is it a container. Now that this method is used, it is impossible to return this! It seems that there is nothing to prove through an example that is not rigorous, but most of the operations on jframe in many programs call a getcontentpane () and do some operations on the container, why do I need to call this one more? I was waiting for me here. Also, swing and AWT are originally the relationships that are constantly being broken, so it's hard to get SWT back ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.