Modify the background color of the panel

Source: Internet
Author: User

Package Button;import java.awt.*;import java.awt.event.*;import javax.swing.*;p ublic class Buttonframe extends JFrame{ Private JPanel buttonpanel;private static final int d_width=300;private static final int d_height=200;public static void M Ain (String args[]) {JFrame frame = new Buttonframe (); Frame.settitle ("Buttonframe"); Frame.setdefaultcloseoperation ( Jframe.exit_on_close); frame.setvisible (true);} Public Buttonframe () {setSize (d_width,d_height); JButton Yellowbutton = new JButton ("Yellow"); JButton BlueButton = new JButton ("Blue"); JButton Redbutton = new JButton ("Red") Buttonpanel = new JPanel (); Buttonpanel.add (Yellowbutton); Buttonpanel.add ( BlueButton); Buttonpanel.add (Redbutton); add (Buttonpanel); Coloraction yellowaction = new Coloraction (color.yellow); Coloraction blueaction = new Coloraction (Color.Blue); Coloraction redaction = new Coloraction (color.red); Yellowbutton.addactionlistener (yellowaction); Bluebutton.addactionlistener (blueaction); Redbutton.addactionlistener (redaction);} Private class Coloraction implements Actionlistener{private color Backgroundcolor;public coloraction (color c) {backgroundcolor=c;} public void actionperformed (ActionEvent event) {buttonpanel.setbackground (backgroundcolor);}}}

  

Modify the background color of the panel

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.