Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.applet.Applet;
- import java.awt.Button;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.TextField;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class RGB16 extends Applet implements ActionListener {
- private static final long serialVersionUID = 1L;
- private TextField fred, fgreen, fblue, fhex;
- private Button a, b;
- private Color color;
- @Override
- public void init() {
- color = Color.BLACK;
- fred = new TextField("0", 4);
- add(fred);
- fgreen = new TextField("0", 4);
- add(fgreen);
- fblue = new TextField("0", 4);
- add(fblue);
- a = new Button(">");
- a.addActionListener(this);
- add(a);
- b = new Button("<");
- b.addActionListener(this);
- add(b);
- fhex = new TextField("000000", 8);
- add(fhex);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == a) {
- int red = Integer.parseInt(fred.getText());
- int green = Integer.parseInt(fgreen.getText());
- int blue = Integer.parseInt(fblue.getText());
- color = new Color(red, green, blue);
- fred.setText("" + color.getRed());
- fgreen.setText("" + color.getGreen());
- fblue.setText("" + color.getBlue());
- fhex.setText("" +
- Integer.toString(((red << 16) | (green << 8) | blue), 16));
- }
- else if (e.getSource() == b) {
- int red = (Integer.parseInt(fhex.getText(), 16) & 0xff0000) >> 16;
- int green = (Integer.parseInt(fhex.getText(), 16) & 0xff00) >> 8;
- int blue = Integer.parseInt(fhex.getText(), 16) & 0xff;
- color = new Color(red, green, blue);
- fred.setText("" + color.getRed());
- fgreen.setText("" + color.getGreen());
- fblue.setText("" + color.getBlue());
- fhex.setText("" +
- Integer.toString(((red << 16) | (green << 8) | blue), 16));
- }
- repaint();
- }
- @Override
- public void paint(Graphics g) {
- g.setColor(color);
- g.fillRect(60, 60, 180, 60);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement