Koordinatensystem

Klingel89

Mitglied
Hey, hab das Problem das meine Y- Achse nicht richtig beschriftet wird. Hier mein Quelltext zur Klasse. Bitte um Hilfe! :)

Java:
import java.awt.*;
public class Grafik_1 extends Frame {
  public Grafik_1 () {
    super("Beispiel");
    addWindowListener(new WindowClosingAdapter());
    setLocation(new Point(100,200));
    setBackground(Color.white);
    setSize(600,600);
    setVisible(true);
  }

  public void paint(Graphics g) {
    g.setColor(Color.black);
    g.drawLine(50,300,550,300);
    int xp = 50, y0 = 300, y1 = y0 +5;
    for (int i=0;i<10;i++) {
        g.drawLine(xp,y0,xp,y1);
        xp += 50;
        g.drawString(""+i,xp-52,320);
        }
    g.drawString("x-Achse", 530, 320);

    g.drawLine(50,50,50,300);
    int a = 50, y2= 50, y3= y2+5;
        for (int i=4;i>0;i--) {
        g.drawLine(y2,a,y3,a);
        a += 50;
        g.drawString(""+i,y3,a);
        }
  }
}


hier der main-teil.

Java:
public class Test_Grafik {

  public static void main(String[] args) {
    Grafik_1 win = new Grafik_1();
  }
}
 

Quaxli

Top Contributor
Du hättest noch schreiben sollen, was Du unter "nicht richtig" verstehst. Aber die Lösung Deines Problems steht vermutlich in der API zu Graphics unter drawString(...) :D:D:D

API hat gesagt.:
Draws the text given by the specified string, using this graphics context's current font and color. The baseline of the leftmost character is at position (x, y) in this graphics context's coordinate system.
 
S

SlaterB

Gast
Java:
g.drawLine(50, 50, 50, 300);
        int a = 50, y2 = 50, y3 = y2 - 5;
        for (int i = 4; i >= 0; i--)
        {
            a += 50;
            g.drawLine(y2, a, y3, a);
            g.drawString("" + i, y3-10, a);
        }
 

Ähnliche Java Themen

Neue Themen


Oben