Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package matrixprogressbar;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JApplet;
- /**
- *
- * @author Magi
- */
- public class MatrixProgressBar extends JApplet implements Runnable{
- private int widthRect;
- private int heightRect;
- private int counter;
- @Override
- public void init() {
- widthRect = (getWidth()-1)/5;
- heightRect = (getHeight()-1)/5;
- counter = -1;
- Thread thr = new Thread(this);
- thr.start();
- }
- @Override
- public void paint(Graphics g) {
- super.paint(g);
- widthRect = (getWidth()-1)/5;
- heightRect = (getHeight()-1)/5;
- for(int i=0; i<5; i++){
- for(int j=0; j<5; j++){
- g.setColor(Color.BLACK);
- g.drawRect(i*widthRect, j*heightRect, widthRect, heightRect);
- g.setColor(Color.YELLOW);
- g.fillRect(i*widthRect+1, j*heightRect+1, widthRect-1, heightRect-1);
- if(j==counter/5&&i==counter%5){
- g.setColor(Color.BLACK);
- g.fillRect(i*widthRect+1, j*heightRect+1, widthRect-1, heightRect-1);
- }
- }
- }
- }
- @Override
- public void run() {
- while(true){
- if(counter == 24){
- counter = 0;
- repaint();
- }
- else{
- counter ++;
- repaint();
- }
- try {
- Thread.sleep(500);
- } catch (InterruptedException ex) {
- Logger.getLogger(MatrixProgressBar.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement