Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fy;
- import java.applet.Applet;
- import java.awt.*;
- import java.awt.event.*;
- import java.math.*;
- import java.util.Random.*;
- public class fy extends Applet implements ActionListener {
- Button but1, but2;
- int x = 0, y = 0;
- public void init() {
- but1 = new Button("Deseneaza");
- add(but1);
- but2 = new Button("Sterge");
- add(but2);
- but1.addActionListener(this);
- but2.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e) {
- Button b = (Button) e.getSource();
- if (b == but1) {
- int R = (int)(Math.random()*255);
- int G = (int)(Math.random()*255);
- int B = (int)(Math.random()*255);
- Color variabila = new Color(R,G,B);
- setBackground(variabila);
- x = 50;
- y = 50;
- repaint();
- } else if (b == but2) {
- x = y = 0;
- repaint();
- }
- }
- public void paint(Graphics g) {
- Color [] randomColors = {Color.blue,Color.white,Color.green};
- // int nrRand = (int )(Math.random() * 3);
- //System.out.println(nrRand);
- //Color variabila = new Color(R,G,B);
- //setBackground(variabila);
- setForeground(Color.green);
- if (x > 0)
- g.fillOval(x, y, 100, 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement