How to Get Brighter Version of Current Color in Java


In this example, we will use AWT Color class to get brighter version of current color in Java.

Source Code

package com.beginner.examples;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class GetBrighterColorExample {

	public static void main(String[] args) {
		// Create the form and set the size and layout
		Frame frame = new Frame("Colour");
		frame.setBounds(100, 100, 300, 200);
		frame.setLayout(new FlowLayout());
		
		//Custom color
		Color custom = new Color(104, 22, 255);
		
		//Create a panel for which the background is a custom color
		Panel panel = new Panel();

		Label textLabel = new Label("Current RGB color");

		textLabel.setForeground(Color.WHITE);
		panel.add(textLabel);

		panel.setBackground(custom);
		//Add the panel to Fram
		frame.add(panel);
		
		//Gets a brighter version of the current color
		custom = custom.brighter();

		frame.setBackground(custom);

		frame.setVisible(true);
		
		//Add a WindowListener for the frame to close
		frame.addWindowListener(new WindowAdapter() {

			@Override
			public void windowClosing(WindowEvent e) {

				System.exit(0);
			}

		});

	}

}

Output:

![](Output.png)

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments