Advertisement
Guest User

PROGRES BAR IP

a guest
Nov 23rd, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. package matrixprogressbar;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. import javax.swing.JApplet;
  8.  
  9. /**
  10. *
  11. * @author Magi
  12. */
  13. public class MatrixProgressBar extends JApplet implements Runnable{
  14. private int widthRect;
  15. private int heightRect;
  16. private int counter;
  17. @Override
  18. public void init() {
  19. widthRect = (getWidth()-1)/5;
  20. heightRect = (getHeight()-1)/5;
  21. counter = -1;
  22. Thread thr = new Thread(this);
  23. thr.start();
  24. }
  25.  
  26. @Override
  27. public void paint(Graphics g) {
  28. super.paint(g);
  29. widthRect = (getWidth()-1)/5;
  30. heightRect = (getHeight()-1)/5;
  31. for(int i=0; i<5; i++){
  32. for(int j=0; j<5; j++){
  33. g.setColor(Color.BLACK);
  34. g.drawRect(i*widthRect, j*heightRect, widthRect, heightRect);
  35. g.setColor(Color.YELLOW);
  36. g.fillRect(i*widthRect+1, j*heightRect+1, widthRect-1, heightRect-1);
  37. if(j==counter/5&&i==counter%5){
  38. g.setColor(Color.BLACK);
  39. g.fillRect(i*widthRect+1, j*heightRect+1, widthRect-1, heightRect-1);
  40. }
  41. }
  42. }
  43. }
  44.  
  45. @Override
  46. public void run() {
  47. while(true){
  48. if(counter == 24){
  49. counter = 0;
  50. repaint();
  51. }
  52. else{
  53. counter ++;
  54. repaint();
  55. }
  56. try {
  57. Thread.sleep(500);
  58. } catch (InterruptedException ex) {
  59. Logger.getLogger(MatrixProgressBar.class.getName()).log(Level.SEVERE, null, ex);
  60. }
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement