title: Passing data between objects attributes of an object
body: <p>Currently trying to make a graphic clock in JAVA, I'm dealing with a problem of "communication" between elements. Indeed, my architecture is visible underneath and is composed of 3 classes:</p>
  
  <p><a href="https://i.stack.imgur.com/02ABz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/02ABz.png" alt="enter image description here"></a></p>
  
  <p>The drawer is used as a "container" by grouping the various elements which concern the data (the clock class which only allows to store the current time) and the graphic (the JFrame as well as clockPanel).</p>
  
  <p>ClockPanel is the class that should allow to draw the clock (for the moment I was able to draw the static elements, as visible below).</p>
  
  <p><a href="https://i.stack.imgur.com/5KXZJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5KXZJ.png" alt="enter image description here"></a></p>
  
  <p>My problem is how to pass the clock data to ClockPanel in order to draw the clock hands.</p>
  
  <p>I was thinking of passing the clock to ClockPanel but it seems pretty obvious that this is not the solution to choose, it would make the drawer useless.</p>
  
  <p>So I can't see how to make the link between these two elements.
  I try to be as clean as possible in order to acquire the best possible reflexes for the future.</p>
  
  <p>I thought for a while that my current structure is completely wrong, which is causing my problem.</p>
  
  <p>Below are code snippets from the drawer and the paintComponent function of the clockPanel:</p>
  
  <pre><code>public void initDraw() {
          clockWindow = new JFrame();
  
          clockWindow.setTitle(getTitle());//Définit un titre pour notre fenêtre
          clockWindow.setSize(getSize(), getSize());//Définit sa taille, elle sera carrée car deux fois size en W et H
          clockWindow.setLocationRelativeTo(null);//Nous demandons maintenant à notre objet de se positionner au centre
          clockWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Termine le processus lorsqu'on clique sur la croix rouge
          clockWindow.setResizable(false);//L'utilisateur ne peux pas redimensionner la fenetre
          clockWindow.setVisible(true);//Et enfin, la rendre visible
  
          clockPanel =  new ClockPanel(m_clock);
          clockWindow.setContentPane(clockPanel);
  
  }
  </code></pre>
  
  <pre><code>public void paintComponent(Graphics g){
          super.paintComponent(g);
  
          m_radiusWhiteCircle = (getWidth()/2)-40; //on prend un rayon qui va donner un cercle qui prend quasiment toute la fenetre
          m_centerX = m_centerY = getWidth()/2; //dans le contexte actuel, la fenetre est carrée, donc qu'on prenne widh ou height c'est pareil (a separe en deux opération si on change)
          System.out.println(getHeight());
  
          this.setBackground(new Color(160, 196, 235)); //on défini le fond du JPanel
          g.setColor(Color.BLACK);// le prochaine cercle sera noir
          int[] blackCircleSquare = convertCircleCoordsToSquareCoords(m_centerX, m_centerY, m_radiusWhiteCircle + 10); //on convertit les coordonées de notre cercle afin d'obtenir ceux du coin gauche du carré qui va contenri notre cerle
          g.fillOval(blackCircleSquare[0],blackCircleSquare[1],blackCircleSquare[2],blackCircleSquare[2]);//On dessine le contour de l'horlorge en prenant le centre de la fenetre et un rayon un peu supérieur au cercle "principal"
  
          g.setColor(Color.WHITE);//le prochain cercle sera blanc
          int[] whiteCircleSquare = convertCircleCoordsToSquareCoords(m_centerX, m_centerY, m_radiusWhiteCircle);
          g.fillOval(whiteCircleSquare[0],whiteCircleSquare[1],whiteCircleSquare[2],whiteCircleSquare[2]);
  
          g.setColor(Color.GREEN);
          int[] greenCircleSquare = convertCircleCoordsToSquareCoords(m_centerX, m_centerY, 10);
          g.fillOval(greenCircleSquare[0],greenCircleSquare[1],greenCircleSquare[2],greenCircleSquare[2]);
  
          g.setColor(Color.RED);
          g.setFont(new Font("TimesRoman", Font.PLAIN,20));
          for(int i=1;i&lt;=12;i++) {
              int xHour = (int)(m_centerX+(m_radiusWhiteCircle-15)*Math.cos(i*INVARIABLE_ANGLE_HOUR - INVARIABLE_DECALAGE));
              int yHour = (int)(m_centerY+(m_radiusWhiteCircle-20)*Math.sin(i*INVARIABLE_ANGLE_HOUR - INVARIABLE_DECALAGE));
              g.drawString(String.valueOf(i),xHour,yHour);
          }
  }
  </code></pre>