Negative number in fillRect ()

I use a negative number to fillRect()go the opposite way. It works well on my computer, but my friends do not see that it works fine. What should I do?

page.fillRect (12, 12, -5, 10);
+3
source share
2 answers

I assume that you and your freind are using 2 different versions of Java. your props are filled with a negative value, and your freind is not. (or even sdk vs jre).

what shows is that you have to write it in a different way for your applet to work on all versions.

Why not just move x -5?

if you want to do it in a more neat way

public void myfillRect(graphics page, int x, int y, int width, int height){
    if(width <0)
        x-=Math.abs(width);
    if(height <0)
        y-=Math.abs(height);

    page.rectfill(x,y,Math.abs(width), Math.abs(height));
} 
0
source

There are two schools of thought on this.

, - - 10 ?

, .

. Java , , .

:

  • , .
  • , x, y, . [10, 10, -5,5] [5, 105,5]. , . , , , , .

, , JVM.

:

public void fillRect(Graphics gc, int x, int y, int width, int height) {
    if(width <0) { x+=width;  width =-width;  }
    if(height<0) { x+=height; height=-height; }
    gc.fillRect(x,y,width,height);
    }

, .

, , - , .

+1

Source: https://habr.com/ru/post/1775587/


All Articles