Question: I have subclassed [`java.awt.Frame`](https://docs.oracle.com/javase/9/docs/api/java/awt/Frame.html) and have overridden the [`paint()`](https://docs.oracle.com/javase/9/docs/api/java/awt/Window.html#paint-java.awt.Graphics-) method as I wish to draw the entire contents of the window manually.

However, on the graphics object, (0,0) corresponds to the upper left hand corner of the window **inside** the title bar decoration, not the first drawable pixel.

Can I determine the co-ordinate of the first drawable pixel (ie, the height of the decoration) in a cross-platform manner, avoiding using a Mac OS X-specific [fudge factor](https://en.wikipedia.org/wiki/Fudge_factor)? Will I be forced to nest a [Panel](https://docs.oracle.com/javase/9/docs/api/java/awt/Panel.html) component in order to find the actual drawable area of the window?

Here, my code fails to centre the blue square inside the paintable area of the window:

```
@Override
public void paint (Graphics g) {
    g.setColor(Color.BLUE);
    g.setPaintMode();
    g.fillRect(30, 30, getWidth()-60, getHeight()-60);
}

```

Answer: 
For C++ only, you can make the parameter a reference

```
func()
{
    Object* pNext;
    func1(pNext);
}

func1(Object*& pNext)
{
    pNext = Segement->GetFirstPara(0);
}

```

What is going on here is the difference between passing parameters by value and passing by reference. C always passes by value. In order to get a value back, the value needs to be a reference value (e.g. Object\*\* refers to Object\* as a pointer). C++ adds reference parameters (signified by the &).
Pass by value only passes a copy of the data and never the actual data itself. That is why the variable used in the function call was not updated in the function.
In c, you would want:

```
func1(&pNext);
func1(Object** pNext) { *pNext = ... }

```

In C++

```
func1(pNext);
func1(Object*& pNext) { pNext = ... }

```

In either language, your example would pass an uninitialized `Object*` to `func1`, which would copy it, assign a value to the copy and then return. Note that the original pNext never gets modified (it would help if you used different names for your variables).

In both languages you need to explicitly pass references if pass-by-reference rather than pass-by-value is desired.