Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.image.*;
- import javax.swing.*;
- @SuppressWarnings("serial")
- public class Applet2018a extends JApplet implements ActionListener {
- JPanel controlPanel;
- int x = 0;
- int fps = 24;
- Timer timer = new Timer(1000 / fps, this);
- JPanel drawPanel = new JPanel() {
- @Override
- public void paint(Graphics g) {
- BufferedImage image =
- new BufferedImage(drawPanel.getWidth(),
- drawPanel.getHeight(),
- BufferedImage.TYPE_INT_RGB);
- Graphics g2 = image.getGraphics();
- g2.setColor(Color.CYAN);
- g2.fillRect(0, 0, drawPanel.getWidth(), drawPanel.getHeight());
- g2.setColor(Color.BLACK);
- for (int i = 0; i < 80; i++) {
- for (int j = 0; j < 80; j++) {
- g2.fillOval(x + 5 * i, x + 5 * j, 4, 4);
- }
- }
- g.drawImage(image, 0, 0, null);
- }
- };
- @Override
- public void init() {
- // this.setLayout(new GridLayout(1, 2));
- this.add(drawPanel);
- timer.start();
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- x += 1;
- drawPanel.repaint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement