1

I dont know what I messed up here. I'm doing a digital clock, and try to put some labels in it, but for some reason the height coordinates switched signs.

public void paintComponent(Graphics gr){
    super.paintComponent(gr);

    double XX=hossz*Math.sin(Math.toRadians(szogS));
    double YY=hossz*Math.cos(Math.toRadians(szogS));        
    int X=(int)XX;
    int Y=(int)YY;        
    double XXM=hossz*Math.sin(Math.toRadians(szogM));
    double YYM=hossz*Math.cos(Math.toRadians(szogM));        
    int XM=(int)XXM;
    int YM=(int)YYM;
    gr.translate(getWidth()/2, getHeight()/2);
    gr.drawLine(0, 0, -X, -Y);        
    gr.drawLine(0, 0, -XM, -YM);        
    gr.drawString("12", 0, 120); 
    gr.drawString("3", 120, 0);
    gr.drawString("6", 0, -120); 
    gr.drawString("9", -120, 0);         
}

I drew my first string (12) at x 0 y 120, however when i run the program the "6" is at the top of the clock. What did i do wrong?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • 11
    You did nothing wrong. In Swing, vertical co-ordinates increase from top to bottom, not from bottom to top. – Dawood ibn Kareem Dec 02 '14 at 09:30
  • To add, not just in Swing, but in most UI toolkits actually, because most UI toolkits layout windows like a western-script book from the top left corner. – Christian Hujer Dec 02 '14 at 09:35

0 Answers0