Advertisement
frentzy

ceva culori random java

Nov 14th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. package fy;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import java.math.*;
  7. import java.util.Random.*;
  8. public class fy extends Applet implements ActionListener {
  9.     Button but1, but2;
  10.     int x = 0, y = 0;
  11.  
  12.     public void init() {
  13.         but1 = new Button("Deseneaza");
  14.         add(but1);
  15.         but2 = new Button("Sterge");
  16.         add(but2);
  17.         but1.addActionListener(this);
  18.         but2.addActionListener(this);
  19.  
  20.     }
  21.  
  22.     public void actionPerformed(ActionEvent e) {
  23.         Button b = (Button) e.getSource();
  24.         if (b == but1) {
  25.        
  26.             int R = (int)(Math.random()*255);
  27.             int G = (int)(Math.random()*255);
  28.             int B = (int)(Math.random()*255);
  29.             Color variabila = new Color(R,G,B);
  30.             setBackground(variabila);
  31.             x = 50;
  32.             y = 50;
  33.             repaint();
  34.         } else if (b == but2) {
  35.             x = y = 0;
  36.             repaint();
  37.         }
  38.        
  39.     }
  40.  
  41.     public void paint(Graphics g) {
  42.         Color [] randomColors = {Color.blue,Color.white,Color.green};
  43.     //  int nrRand = (int )(Math.random() * 3);
  44.      
  45.         //System.out.println(nrRand);
  46.         //Color variabila = new Color(R,G,B);
  47.         //setBackground(variabila);
  48.         setForeground(Color.green);
  49.         if (x > 0)
  50.             g.fillOval(x, y, 100, 100);
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement