title: Integrating mouseListener, JRadioButton, and paintComponent into selecting then creating shapes in JPanel
body: <p>Not familiar with the MouseListener and paintComponent tools but i have to use them in creating a GUI which is able to create shapes (by selecting one first) at every mouse click location without using applets. First time here, dont know how to properly post the syntax as well.sorry.</p>
  
  <ol>
  <li><p>Create.java</p>
  
  <pre><code>public class Create extends JFrame implements ActionListener{
      static int x, y;
      static int sSelection;
      JPanel blankSlate, shapeChoice, topMenu;
      JMenuBar scBar, utilityBar;
      JMenu fileMenu, shapeMenu;
      JMenuItem menuiSave, menuiLoad, menuiNew;
      JRadioButtonMenuItem triA, rectA, circle;
  
      public Create(){
          //container block
          Container container=getContentPane();
          container.setLayout(new BorderLayout());
  
          //creation block
          topMenu=new JPanel();
          topMenu.setLayout(new GridLayout(1,3));
          blankSlate=new JPanel();
          blankSlate.setLayout(new BorderLayout());
          shapeChoice=new JPanel();
          shapeChoice.setLayout(new GridLayout(1,3));
  
          //utilities block
          utilityBar=new JMenuBar();
          setJMenuBar(utilityBar);
          fileMenu=new JMenu("File");
          menuiSave=new JMenuItem("Save");
          menuiLoad=new JMenuItem("Load");
          menuiNew=new JMenuItem("New");
          fileMenu.add(menuiNew);
          fileMenu.add(menuiSave);
          fileMenu.add(menuiLoad);
          utilityBar.add(fileMenu);
  
          //adding bars to sections block
          topMenu.add(utilityBar);
  
          //Blank Slate block
          //need to add mouselistener and paintComponent according to selection of shapes
          AL a1=new AL();
  
          //shape choice block
          scBar=new JMenuBar();
          setJMenuBar(scBar);
          shapeMenu=new JMenu("Shapes");
          triA=new JRadioButtonMenuItem("Triangle");
          circle=new JRadioButtonMenuItem("Circle");
          rectA=new JRadioButtonMenuItem("Rectangle");
          shapeMenu.add(triA);
          shapeMenu.add(circle);
          shapeMenu.add(rectA);
          ButtonGroup gr= new ButtonGroup();
          gr.add(triA);
          gr.add(circle);
          gr.add(rectA);
          triA.addActionListener(this);
          circle.addActionListener(this);
          rectA.addActionListener(this);
          scBar.add(shapeMenu);
  
          //adding bars to sections block
          shapeChoice.add(scBar);
  
  
  
          //adding sections to container
          container.add(BorderLayout.NORTH, topMenu);
          container.add(BorderLayout.CENTER,blankSlate);
          container.add(BorderLayout.SOUTH,shapeChoice);
      }
  
      public void formula()
      {
          if(sSelection==1){
              ShapeRect r1=new ShapeRect();}
          else if(sSelection ==2){}
          else if(sSelection==3){}
      }
  </code></pre></li>
  </ol>
  
  <p>and</p>
  
  <pre><code>        public void actionPerformed(ActionEvent e){
              if(e.getSource()==triA){
                  //triA formula selected                     
              }
              if(e.getSource()==circle){
                          //circ formula
              }
              if(e.getSource()==rectA){
                  //rectA formula
                  sSelection=1;
                  formula();
              }   
          }
  
          public void drawing(int xx, int yy){
              x=xx;
              y=yy;
              repaint();  
          }
  </code></pre>
  
  <p>other class</p>
  
  <pre><code>        class AL extends MouseAdapter{
              public void mouseClicked(MouseEvent e){
                  x=e.getX();
                  y=e.getY();
                  drawing(x, y);
              }
          }
      }
  </code></pre>
  
  <ol start="2">
  <li><p>Test.java</p>
  
  <pre><code>public class Test extends JFrame{       
      public static void main(String[]args){
  
          Create fr = new Create ();
          fr.setSize(500, 500);
          fr.setDefaultCloseOperation(EXIT_ON_CLOSE);
          fr.setLocationRelativeTo(null);
          fr.setTitle("Create");
          fr.setVisible(true);
      }
  }
  </code></pre></li>
  <li><p>ShapeRect</p>
  
  <pre><code>public class ShapeRect extends Shape{
      static int x, y;
      public void paintComponent(Graphics g) {
          paintComponent(g);
          g.setColor(Color.BLACK);
          g.fillRect(x, y, 20, 20);
      }
  }
  </code></pre></li>
  </ol>