title: How do i change the size of my drawing using a button (java)?
body: <p>I'm drawing flowers and I need the 'head' to double in size when I press the 'fertilize' button and then to reset to their original size when I press the 'reset size' button. I'm using Netbeans. Nothing I've tried so far has worked sooo....help? :)</p>
  
  <p><img src="https://i.stack.imgur.com/Haa4c.png" alt="enter image description here"></p>
  
  <p>Code for Panel:</p>
  
  <pre><code>package Versie4;
  import java.awt.Color;
  import java.awt.Graphics;
  
  public class PanelFlowers extends javax.swing.JPanel {
  
      private int amount, size;
      private String color = "";
  
      public PanelFlowers() {
          initComponents();
          repaint();
      }
  
      @Override
      public void paintComponent(Graphics g){
          super.paintComponent(g);
  
          int teller;
  
          g.setColor(Color.RED);  //flowerpot
          g.fillRect(300, 350, 500, 100);
  
          int x = 1;
          int size = 40;
          for (teller=1; teller &lt;= amount ;teller++) { 
  
              //Flower 1
          g.setColor(Color.GREEN);  //stem
          g.fillRect(320 + x, 250, 10, 100);
  
  
              switch (color) {            //Colours of petals
                  case "red":
                      g.setColor(Color.red);
                      break;
                  case "blue":
                      g.setColor(Color.blue);
                      break;
                  case "yellow":
                      g.setColor(Color.yellow);
                      break;
                  case "orange":
                      g.setColor(Color.orange);
                      break;
                  case "pink":
                      g.setColor(Color.PINK);
                      break;
                  case "purple":
                      g.setColor(new Color(102, 0, 204));
                      break;
              }
  
          g.fillOval(304 + x, 190, size, size); //petals
          g.fillOval(330 + x, 210, size, size);
          g.fillOval(320 + x, 240, size, size);
          g.fillOval(290 + x, 240, size, size);
          g.fillOval(280 + x, 210, size, size);
  
  
          g.setColor(Color.YELLOW);  //pistil
          g.fillOval(312 + x, 225, 25, 25);
  
          x = teller * 80;
  
          }
  
  
  
      }
  
  
      @SuppressWarnings("unchecked")
      // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
      private void initComponents() {
  
          lblamount = new javax.swing.JLabel();
          txtamount = new javax.swing.JTextField();
          lblcolor = new javax.swing.JLabel();
          txtcolor = new javax.swing.JTextField();
          btngrow = new javax.swing.JButton();
          btnreset = new javax.swing.JButton();
          btnfertilize = new javax.swing.JButton();
  
          lblamount.setText("Amount: ");
  
          txtamount.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  txtamountActionPerformed(evt);
              }
          });
  
          lblcolor.setText("Color: ");
  
          txtcolor.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  txtcolorActionPerformed(evt);
              }
          });
  
          btngrow.setText("Grow!");
          btngrow.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  btngrowActionPerformed(evt);
              }
          });
  
          btnreset.setText("Reset Size");
  
          btnfertilize.setText("Fertilize");
          btnfertilize.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  btnfertilizeActionPerformed(evt);
              }
          });
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
          this.setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(lblamount)
                  .addGap(18, 18, 18)
                  .addComponent(txtamount, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(41, 41, 41)
                  .addComponent(lblcolor)
                  .addGap(18, 18, 18)
                  .addComponent(txtcolor, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(18, 18, 18)
                  .addComponent(btngrow)
                  .addGap(18, 18, 18)
                  .addComponent(btnfertilize)
                  .addGap(18, 18, 18)
                  .addComponent(btnreset)
                  .addContainerGap(185, Short.MAX_VALUE))
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(lblamount)
                      .addComponent(txtamount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(lblcolor)
                      .addComponent(txtcolor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(btngrow)
                      .addComponent(btnreset)
                      .addComponent(btnfertilize))
                  .addContainerGap(412, Short.MAX_VALUE))
          );
      }// &lt;/editor-fold&gt;                        
  
      private void txtamountActionPerformed(java.awt.event.ActionEvent evt) {                                          
  
      }                                         
  
      private void txtcolorActionPerformed(java.awt.event.ActionEvent evt) {                                         
          // TODO add your handling code here:
      }                                        
  
      private void btngrowActionPerformed(java.awt.event.ActionEvent evt) {                                        
      amount = Integer.parseInt(txtamount.getText());
      color = this.txtcolor.getText();
      repaint();
  
      }                                       
  
      private void btnfertilizeActionPerformed(java.awt.event.ActionEvent evt) {                                             
         size = size * 2;
      }                                            
  
      // Variables declaration - do not modify                     
      private javax.swing.JButton btnfertilize;
      private javax.swing.JButton btngrow;
      private javax.swing.JButton btnreset;
      private javax.swing.JLabel lblamount;
      private javax.swing.JLabel lblcolor;
      private javax.swing.JTextField txtamount;
      private javax.swing.JTextField txtcolor;
      // End of variables declaration                   
  }
  </code></pre>
  
  <p>Code for Frame:</p>
  
  <pre><code>package Versie4;
  
  
  public class FrameFlowers extends javax.swing.JFrame {
  
  
      public FrameFlowers() {
          initComponents();
          setSize(900, 600);
          setContentPane(new PanelFlowers());
      }
  
  
      @SuppressWarnings("unchecked")
      // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
      private void initComponents() {
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 400, Short.MAX_VALUE)
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 300, Short.MAX_VALUE)
          );
  
          pack();
      }// &lt;/editor-fold&gt;                        
  
      /**
       * @param args the command line arguments
       */
      public static void main(String args[]) {
          /* Set the Nimbus look and feel */
          //&lt;editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "&gt;
          /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
           * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
           */
          try {
              for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                  if ("Nimbus".equals(info.getName())) {
                      javax.swing.UIManager.setLookAndFeel(info.getClassName());
                      break;
                  }
              }
          } catch (ClassNotFoundException ex) {
              java.util.logging.Logger.getLogger(FrameFlowers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (InstantiationException ex) {
              java.util.logging.Logger.getLogger(FrameFlowers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex) {
              java.util.logging.Logger.getLogger(FrameFlowers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
              java.util.logging.Logger.getLogger(FrameFlowers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          }
          //&lt;/editor-fold&gt;
  
          /* Create and display the form */
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  new FrameFlowers().setVisible(true);
              }
          });
      }
      // Variables declaration - do not modify                     
      // End of variables declaration                   
  }
  </code></pre>