i need to add the names of the colors to the RGB values ....this are some of the
ID: 3547514 • Letter: I
Question
i need to add the names of the colors to the RGB values ....this are some of the names...i can add the rest...i just needtoknow how to doit
import java.awt.AWTException;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.MouseInfo;
import java.awt.Robot;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;
public class ColorChooser extends JFrame {
private JPanel contentPane;
private final JPanel panel_1 = new JPanel();
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ColorChooser frame = new ColorChooser();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* @throws AWTException
*/
public ColorChooser() throws AWTException
{
final Robot r=new Robot();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 231, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
final JPanel panel = new JPanel();
panel.setBounds(0, 0, 215, 176);
contentPane.add(panel);
panel_1.setBounds(0, 187, 215, 64);
contentPane.add(panel_1);
panel_1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
JLabel lblR = new JLabel("R");
panel_1.add(lblR);
final JTextPane textPane = new JTextPane();
panel_1.add(textPane);
JLabel lblG = new JLabel("G");
panel_1.add(lblG);
final JTextPane textPane_1 = new JTextPane();
panel_1.add(textPane_1);
JLabel lblB = new JLabel("B");
panel_1.add(lblB);
final JTextPane textPane_2 = new JTextPane();
panel_1.add(textPane_2);
Thread t=new Thread()
{
public void run()
{
while(true)
{
Color c=r.getPixelColor((int)MouseInfo.getPointerInfo().getLocation().getX(), (int)MouseInfo.getPointerInfo().getLocation().getY());
panel.setBackground(c);
panel.repaint();
textPane.setText(""+c.getRed());
textPane_1.setText(""+c.getGreen());
textPane_2.setText(""+c.getBlue());
}
}
};
t.start();
}
}
Explanation / Answer
String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
ColorChooser frame = new ColorChooser();
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*
* @throws AWTException
*/
public ColorChooser() throws AWTException
{
final Robot r = new Robot();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 231, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
final JPanel panel = new JPanel();
panel.setBounds(0, 0, 215, 176);
contentPane.add(panel);
panel_1.setBounds(0, 187, 215, 64);
contentPane.add(panel_1);
panel_1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
JLabel lblR = new JLabel("R");
panel_1.add(lblR);
final JTextPane textPane = new JTextPane();
panel_1.add(textPane);
JLabel lblG = new JLabel("G");
panel_1.add(lblG);
final JTextPane textPane_1 = new JTextPane();
panel_1.add(textPane_1);
JLabel lblB = new JLabel("B");
panel_1.add(lblB);
final JTextPane textPane_2 = new JTextPane();
panel_1.add(textPane_2);
final JTextPane textPane_3 = new JTextPane();
panel_1.add(textPane_3);
textPane_3.setText("Name");
mapNames.put(new Color(0xF0F8FF), "Alice Blue");
mapNames.put(new Color(0xFAEBD7), "Antique White");
mapNames.put(new Color(0x00FFFF), "Aqua");
mapNames.put(new Color(0x7FFFD4), "Aquamarine");
mapNames.put(new Color(0xF0FFFF), "Azure");
mapNames.put(new Color(0xF5F5DC), "Beige");
mapNames.put(new Color(0xFFE4C4), "Bisque");
mapNames.put(new Color(0x000000), "Black");
mapNames.put(new Color(0xFFEBCD), "Blanched Almond");
mapNames.put(new Color(0x0000FF), "Blue");
mapNames.put(new Color(0x8A2BE2), "Blue Violet");
mapNames.put(new Color(0xA52A2A), "Brown");
mapNames.put(new Color(0xDEB887), "Burlywood");
mapNames.put(new Color(0x5F9EA0), "Cadet Blue");
mapNames.put(new Color(0x7FFF00), "Chartreuse");
mapNames.put(new Color(0xD2691E), "Chocolate");
mapNames.put(new Color(0xFFFFFF), "White");
Thread t = new Thread()
{
public void run()
{
while (true)
{
Color c = r.getPixelColor((int) MouseInfo.getPointerInfo()
.getLocation().getX(), (int) MouseInfo
.getPointerInfo().getLocation().getY());
panel.setBackground(c);
panel.repaint();
textPane.setText("" + c.getRed());
textPane_1.setText("" + c.getGreen());
textPane_2.setText("" + c.getBlue());
textPane_3.setText(mapNames.get(c));
}
}
};
t.start();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.