JAVA JLabel Custom subclasses cannot be displayed

Source: Internet
Author: User

1 Importjava.awt.*;2 ImportJava.util.Scanner;3 4 Importjavax.swing.*;5 6  Public classTest_16_13extendsjframe{7 8  Publictest_16_13 () {9ImageIcon im =NewImageIcon ("Image/slide1.jpg");TenString s = "Jlabel_mine"; OneJLabel1 J1 =NewJLabel1 (s);  A Add (J1);  -         //Add (New JLabel ("JLabel label")); - } the  -  Public Static voidMain (string[] args) { -Test_16_13 frame =Newtest_16_13 (); -Frame.setsize (800, 600); +Frame.settitle ("Exercise15_8"); - frame.setdefaultcloseoperation (jframe.exit_on_close); +Frame.setlocationrelativeto (NULL);//Center the frame AFrame.setvisible (true);  at }    - classJLabel1extendsjlabel{ -     PrivateImageIcon IC; -     PrivateString S; -      PublicJLabel1 (ImageIcon ic) { -          This. IC =IC; in     } -      PublicJLabel1 (String s) { to          This. S =s; +     } -     } the}
View Code

The code above, I in the main class test_16_13 inside custom a JLabel subclass JLabel1, and then added in the JFrame constructor, but can not be displayed in the JFrame, excuse me why?

Answer:

Just now the class and the parent class to see the tutorial again, think of the next, I have a new sub-class has one of the biggest problems. That is, the constructor for the parent class is not overloaded. My constructors are all custom constructors that are used.
Therefore, my subclass cannot be recognized. Here is the constructor of the JLabel1 I modified:

class extends jlabel{//      private ImageIcon IC; //       private String s;         Public JLabel1 (ImageIcon ic) {            super(IC);        }          Public JLabel1 (String s) {//          this.s = s;            Super (s);        }        }

  

JAVA JLabel Custom subclasses cannot be displayed

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.