title: Java. Problem with drawing shapes by button click
body: <p>Good day.</p>
  
  <p>I develop program which must show few shapes when user clicks the button. At least it doesn't show it. What is wrong?
  Code is:</p>
  
  <pre><code>public class ShowFrame extends JFrame
  {
      public ShowFrame()
      {
          this.setTitle("Show data");                                             //Title
          this.setSize( DEF_WIDTH, DEF_HEIGHT );                                  //Size of frame
          this.setResizable(false); 
  
      //...                                     
  
      JButton testButton = new JButton("Test");
      buttonPanel.add(testButton);
      this.add(buttonPanel, BorderLayout.SOUTH);
  
  
      testButton.addActionListener( new ActionListener() {                    //Add listener
          public void actionPerformed(ActionEvent e) {              
              DrawStuff stuff = new DrawStuff();                              //Create class which draws shapes
              add(stuff, BorderLayout.CENTER);
              System.out.println("Test Button");
          }
      } );
     }
  
  public static final int DEF_WIDTH  = 600;                                   
  public static final int DEF_HEIGHT = 400;                                   
  
  private JPanel buttonPanel = new JPanel();
  }
  </code></pre>
  
  <p>Class which draws shapes:</p>
  
  <pre><code>public class DrawStuff extends JComponent
  {
      public void paintComponent( Graphics g )
      {
          Graphics2D g2 = (Graphics2D) g;
          //...
          Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height);
          Line2D line      = new Line2D.Double(leftX, topY, 0, 0);
          //...
          g2.draw(rect);
          g2.draw(line);
          //...
      }
  
  }
  </code></pre>