Advertisement
Sax

Paleta de Colores

Sax
Sep 19th, 2011
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. /* Sax - Xavier Fernando Sánchez Díaz
  2. 1540717 - Taller de Programación Orientada a Objetos */
  3.  
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import javax.swing.*;
  7.  
  8.  
  9.  
  10. public class palette extends JFrame implements ActionListener{
  11.  
  12.     private JButton boton;
  13.     private JPanel panel;
  14.     private int i = 5;
  15.  
  16.    
  17.     public static void main(String[]args){
  18.         palette workspace = new palette(); 
  19.        
  20.         workspace.setSize(800,130);
  21.         workspace.createGUI();
  22.         workspace.setVisible(true);
  23.         }
  24.    
  25.     private void createGUI(){
  26.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  27.         Container ventana = getContentPane();
  28.         ventana.setLayout(new FlowLayout());
  29.        
  30.         panel = new JPanel();
  31.         panel.setPreferredSize(new Dimension(520, 50));
  32.         panel.setBackground(Color.white);
  33.         ventana.add(panel);
  34.        
  35.         boton = new JButton("Click it before I go buy a car, drive you to Wal-Mart and leave you there!");
  36.         ventana.add(boton);
  37.         boton.addActionListener(this);
  38.     }
  39.    
  40.    
  41.     public void actionPerformed(ActionEvent event){
  42.         Graphics lienzo = panel.getGraphics();
  43.        
  44.             lienzo.setColor(Color.black);
  45.             lienzo.fillRect(5, 10, 25, 25);
  46.             i+=40;
  47.             lienzo.setColor(Color.darkGray);
  48.             lienzo.fillRect(i, 10, 25, 25);
  49.             i+=40;
  50.             lienzo.setColor(Color.gray);
  51.             lienzo.fillRect(i, 10, 25, 25);
  52.             i+=40;
  53.             lienzo.setColor(Color.lightGray);
  54.             lienzo.fillRect(i, 10, 25, 25);
  55.             i+=40;
  56.             lienzo.setColor(Color.red);
  57.             lienzo.fillRect(i, 10, 25, 25);
  58.             i+=40;
  59.             lienzo.setColor(Color.blue);
  60.             lienzo.fillRect(i, 10, 25, 25);
  61.             i+=40;
  62.             lienzo.setColor(Color.magenta);
  63.             lienzo.fillRect(i, 10, 25, 25);
  64.             i+=40;
  65.             lienzo.setColor(Color.cyan);
  66.             lienzo.fillRect(i, 10, 25, 25);
  67.             i+=40;
  68.             lienzo.setColor(Color.yellow);
  69.             lienzo.fillRect(i, 10, 25, 25);
  70.             i+=40;
  71.             lienzo.setColor(Color.green);
  72.             lienzo.fillRect(i, 10, 25, 25);
  73.             i+=40;
  74.             lienzo.setColor(Color.pink);
  75.             lienzo.fillRect(i, 10, 25, 25);
  76.             i+=40;
  77.             lienzo.setColor(Color.orange);
  78.             lienzo.fillRect(i, 10, 25, 25);
  79.             i+=40;
  80.             lienzo.drawRect(i, 10, 25, 25);
  81.     }
  82.    
  83.  
  84. }
  85.  
  86. /*Me decepcioné bastante al ver que no puedo concatenar métodos y con strings :c
  87.   La verdad es que era más sencillo guardar los colores como cadenas en un
  88.   arreglo y luego ir pidiendo los índices desde un for... */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement