Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. public class GraphicsFrame
  5. {
  6. private final int LIST_MAX = 500;
  7. private int endOfList;
  8. private Drawable[] drawList;
  9.  
  10. private JFrame f;
  11. private DrawPanel drawPan;
  12.  
  13. public GraphicsFrame()
  14. {
  15. endOfList = -1; // list empty
  16. drawList = new Drawable[ LIST_MAX ];
  17.  
  18. f = new JFrame("Draw Stuff!");
  19. drawPan = new DrawPanel();
  20. f.add( drawPan );
  21. f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  22. f.setSize(800,800);
  23. f.setVisible( true );
  24. }
  25.  
  26. public void add( Drawable d )
  27. {
  28. if (endOfList + 1 < LIST_MAX)
  29. {
  30. endOfList++;
  31. drawList[endOfList] = d;
  32. }
  33. else
  34. {
  35. System.out.println("Draw list full");
  36. }
  37.  
  38. drawPan.repaint();
  39. }
  40.  
  41. public void redraw()
  42. {
  43. drawPan.repaint();
  44. }
  45.  
  46.  
  47. private class DrawPanel extends JPanel
  48. {
  49. public void paintComponent( Graphics g )
  50. {
  51. for( int i=0; i <= endOfList; i++ )
  52. {
  53. drawList[ i ].draw( g );
  54. }
  55. }
  56. }// end of DrawPanel
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement