- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Gitis implements ActionListener{
JFrame frame;
public static void main(String[] args) {
Gitis gitis = new Gitis();
gitis.go();
}
public void go(){
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Next Color");
button.addActionListener(this);
MyDrawPanel panel = new MyDrawPanel();
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.setSize(500, 500);
frame.setVisible(true);
frame.setTitle("Paint Oval");
}
public void actionPerformed(ActionEvent event){
frame.repaint();
}
}
class MyDrawPanel extends JPanel{
public void paintComponent(Graphics g){
g.fillRect(0, 0, this.getWidth(),this.getHeight());
int one = (int) (Math.random() * 255);
int two = (int) (Math.random() * 255);
int three = (int) (Math.random() * 255);
Color color = new Color(one, two, three);
g.setColor(color);
g.fillOval(40, 70 , 50, 50);
}
}
Комментарии (0) RSS
Добавить комментарий