Add background image to jpanl in NetBeans understanding of code--Anonymous inner class inherits parent class

Source: Internet
Author: User
Tags netbeans

This test is designed to emulate the execution of code that adds a background image to jpanl in NetBeans

The data type of the car class is defined in Jpdemo, but the anonymous inner class is used when assigning the object, inherits the car class, is its subclass, and overrides the parent class's Run method, because the parent class's constructor automatically executes the Run method, the output sun run, proves that the rewrite succeeds, Then execute Super.run again, calling the parent class not overriding the Run method, so the output fater run.

The code to add a background graph to jpanl is similar to this:

New Javax.swing.JPanel () {    protectedvoid  paintcomponent (java.awt.Graphics g) {         Super. paintcomponent (g);        G.drawimage (new Javax.swing.ImageIcon (GetClass () getresource ("/reg/images/login.png")). GetImage (), 0,0,1070,85,null);}    ;


Create an anonymous inner class to inherit jpanl, then rewrite the Paintcomponent method, then call the parent class Paintcomponent method and send back the G parameter representing a background graph, you can load the picture when printing

Add background image to jpanl in NetBeans understanding of code--Anonymous inner class inherits parent class

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.