-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorChooser.java
executable file
·43 lines (35 loc) · 1.13 KB
/
ColorChooser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import java.awt.Color;
/**
* A class to make working with a color chooser easier
* for students. It uses a JColorChooser to let the user
* pick a color and returns the chosen color object.
*
* @author Barb Ericson [email protected]
*/
public class ColorChooser
{
/**
* Method to let the user pick a color and return
* the color object.
* @return the picked color or red if no color was picked
*/
public static Color pickAColor()
{
Color color = Color.white;
// create a JFrame to be the parent of the color chooser open dialog
// if you don't do this then you may not see the dialog.
JFrame frame = new JFrame();
frame.setAlwaysOnTop(true);
// use the color chooser to pick the color
color = JColorChooser.showDialog(frame,"Pick a color",color);
return color;
}
/** Main method for testing the ColorChooser */
public static void main(String[] args)
{
Color pickedColor = ColorChooser.pickAColor();
System.out.println(pickedColor);
}
}