title: Drawing on a panel but when adding it through another frame, nothing draws
body: <p>I'm working on a project and the general idea of my work is to do every part of it in a stand alone project, then add it when finished to the main project through libraries.</p>
  
  <p>My problem is - one part I have done was to perform a painting on a panel. 
  When I add a layer pane which connects it to the main project , there is no drawing actually happening. </p>
  
  <p>Here is my project sample code:</p>
  
  <p>In code sample 1 there is JLayeredPane which contains my panel to perform drawing.</p>
  
  <p>In code sample 2 there is a button. Its actionPerformed is to add that JLayeredPane to a panel. But the problem is that the drawing is not appearing after adding the JLayeredPane.</p>
  
  <p><strong>Code sample 1:</strong></p>
  
  <pre><code>public class GraphGui extends javax.swing.JFrame {
  
  /**
   * Creates new form GraphGui
   */
  adjacencyMatrix m = new adjacencyMatrix();
  Dfs df = new Dfs();
  int[] x = new int[df.MAX_VERTS];
  int[] y = new int[df.MAX_VERTS];
  public Graphics2D d;
  public Graphics2D doo;
  int i = 0;
  
  
  public GraphGui() {
      setlookAndFeel();
      initComponents();
      setLocationRelativeTo(null);
      DFS.setVisible(true);
      adjMatrics.setVisible(false);
  
  //display is the panel that draw over
      d = (Graphics2D) display.getGraphics();
      doo = (Graphics2D) jPanel2.getGraphics();
  
  
  }
  
  //crating an initialization  of components are done automatically 
  
  public void jButton1ActionPerformed(java.awt.event.ActionEvent evt)  {                                         
  
      df.dfs();
      doo.setFont(new Font("TimesRoman", Font.BOLD, 19));
      doo.drawString("visits: " + df.out, 5, 20);
      df.out = "";
  }                                        
  
  public void AddE1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
      String j = start1.getText();
      int k = Integer.parseInt(j) - 1;
      String c = end1.getText();
      int v = Integer.parseInt(c) - 1;
  
      df.addEdge(k, v);
      d.setFont(new Font("TimesRoman", Font.BOLD, 17));
      d.drawLine(x[k] + 30, y[k] + 20, x[v], y[v] + 19);
  }                                     
  
  public void AddV1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
      String f = ver1.getText();
      String toUpperCase = f.toUpperCase();
      char r = toUpperCase.charAt(0);
      df.addVertex(r);
      int radius = 30;
      int R = (int) (Math.random() * 256);
      int G = (int) (Math.random() * 256);
      int B = (int) (Math.random() * 256);
      x[i] = R % 320;
      y[i] = B % 167;
  
      d.setColor(new Color(R, G, B));
      d.setFont(new Font("TimesRoman", Font.BOLD, 15));
      d.drawOval(x[i], y[i], radius, radius);
      d.fillOval(x[i], y[i], radius, radius);
      d.setColor(Color.BLACK);
      d.drawString(r + "", x[i] + 10, y[i] + 20);
  d.drawOval(0, 0, radius, radius);
      i++;
  }  
  </code></pre>
  
  <p>What code sample 1 is supposed to do is shown at this link:</p>
  
  <p><a href="https://pbs.twimg.com/media/CG8INXZXAAEqthh.png:large" rel="nofollow">https://pbs.twimg.com/media/CG8INXZXAAEqthh.png:large</a></p>
  
  <p><strong>Code Sample 2</strong></p>
  
  <pre><code>{
      private void graphBTActionPerformed(java.awt.event.ActionEvent evt)  {                                        
      GraphGui gr=new GraphGui();
  
      jPanel2.removeAll();
  
      jPanel2.add(gr.DFS);
  
      MainLayer.setVisible(false);
      Displaylayer.setVisible(true);
  }         
  </code></pre>
  
  <p>}</p>
  
  <p>And at the link below is what I got after adding the panel-
  nothing draws. </p>
  
  <p><a href="https://pbs.twimg.com/media/CG8IR7rWoAA3qKG.png:large" rel="nofollow">https://pbs.twimg.com/media/CG8IR7rWoAA3qKG.png:large</a></p>