Java 在JFrame中更改方向

Java 在JFrame中更改方向,java,swing,user-interface,graphics,paintcomponent,Java,Swing,User Interface,Graphics,Paintcomponent,我正在写一个简单的应用程序来绘制纽约地铁地图。我已经成功地这样做了,我的地图打印在JFrame对象中。但是,它打印在错误的一侧,因为我假设它引用了左上角的0点。如何使其引用左下角,以便以正确的方式打印 private final List<Shape> shapes; private double maxLat = 40.903125; private double maxLon = -73.755405; private double minLat = 40.512764; pri

我正在写一个简单的应用程序来绘制纽约地铁地图。我已经成功地这样做了,我的地图打印在JFrame对象中。但是,它打印在错误的一侧,因为我假设它引用了左上角的0点。如何使其引用左下角,以便以正确的方式打印

private final List<Shape> shapes;
private double maxLat = 40.903125;
private double maxLon = -73.755405;
private double minLat = 40.512764;
private double minLon = -74.251961;
private final double latLength;
private final double lonLength;

public Shapes() throws IOException {
    this.shapes = new ArrayList<Shape>();

    CSVReader in = new CSVReader(new FileReader(
            "src/charnetskaya/subwaymap/shapes.txt"));
    String[] line;
    in.readNext();
    while ((line = in.readNext()) != null) {
        double lat = Double.valueOf(line[1]);
        double lon = Double.valueOf(line[2]);
        Shape shape = new Shape(line[0], lat, lon);
        shapes.add(shape);

        this.maxLat = Math.max(this.maxLat, shape.getLat());
        this.maxLon = Math.max(this.maxLon, shape.getLon());
        this.minLat = Math.min(this.minLat, shape.getLat());
        this.minLon = Math.min(this.minLon, shape.getLon());
    }

    this.latLength = Math.abs(this.maxLat - this.minLat);
    this.lonLength = Math.abs(this.maxLon - this.minLon);
    System.out.println(latLength + " " + lonLength);

}
私有最终列表形状;
专用双maxLat=40.903125;
专用双maxLon=-73.755405;
私人双minLat=40.512764;
私有双minLon=-74.251961;
专用最终双板条长度;
私人最终双倍长度;
公共形状()引发异常{
this.shapes=new ArrayList();
CSVReader in=新CSVReader(新文件读取器(
“src/charnetskaya/subwaymap/shapes.txt”);
字符串[]行;
in.readNext();
而((line=in.readNext())!=null){
double lat=double.valueOf(第[1]行);
double lon=double.valueOf(第[2]行);
形状=新形状(线[0],纬度,经度);
形状。添加(形状);
this.maxLat=Math.max(this.maxLat,shape.getLat());
this.maxLon=Math.max(this.maxLon,shape.getLon());
this.minLat=Math.min(this.minLat,shape.getLat());
this.minLon=Math.min(this.minLon,shape.getLon());
}
this.latLength=Math.abs(this.maxLat-this.minLat);
this.lonLength=Math.abs(this.maxLon-this.minLon);
System.out.println(latLength+“”+lonLength);
}
图解法

public void paintComponent(Graphics pen) {
    System.out.println("Tring to draw");
    Graphics2D pen2D = (Graphics2D) pen;
    int width = getWidth();
    int height = getHeight();
    System.out.println(width + " | " + height);

    double minLat = this.shapes.getMinLat();
    double minLon = this.shapes.getMinLon();
    double latLength = this.shapes.getLatLength();
    double lonLength = this.shapes.getLonLength();
    List<String> shapeIds = this.shapes.getShapeIds();
    for (String shapeId : shapeIds) {

        List<Shape> list = this.shapes.getShapes(shapeId);

        Trip trip = this.trips.getTrip(shapeId);
        if (trip != null) {
            Color color = this.routes.getColor(trip.getRouteId());
            pen2D.setColor(color);
            for (int i = 1; i < list.size(); i++) {
                Shape a = list.get(i - 1);
                Shape b = list.get(i);
                int x1 = (int) ((a.getLat() - minLat) / latLength * height);
                int y1 = (int) ((a.getLon() - minLon) / lonLength * height);
                int x2 = (int) ((b.getLat() - minLat) / latLength * height);
                int y2 = (int) ((b.getLon() - minLon) / lonLength * height);

                // if ((x1 != x2) || (y1 != y2)) {
                pen2D.drawLine(x1, y1, x2, y2);
                // }
            }
        }

    }
公共组件(图形笔){
System.out.println(“Tring to draw”);
Graphics2D pen2D=(Graphics2D)笔;
int width=getWidth();
int height=getHeight();
系统输出打印LN(宽度+“|”+高度);
double minLat=this.shapes.getMinLat();
double minLon=this.shapes.getMinLon();
double latLength=this.shapes.getLatLength();
double lonLength=this.shapes.getLonLength();
List shapeIds=this.shapes.getShapeIds();
for(字符串shapeId:shapeIds){
List List=this.shapes.getShapes(shapeId);
Trip-Trip=this.trips.getTrip(shapeId);
如果(跳闸!=null){
Color Color=this.routes.getColor(trip.getRouteId());
pen2D.setColor(颜色);
对于(int i=1;i

改变

int x1 = (int) ((a.getLat() - minLat) / latLength * height);
int y1 = (int) ((a.getLon() - minLon) / lonLength * height);


对于
x2
y2
,intx1=(int)((a.getLon()-minLon)/lonLength*width);inty1=(int)(maxLat-(a.getLat())/latLength*height);intx2=(int)((b.getLon()-minLon)/lonLength*width);inty2=(int)((maxLat-b.getLat())/latLength*height);不,不像你键入的那样。你把括号放在了不同的地方,在表达式中,
y1
.thanx表示你的helf,但也许你可以帮我把北转向左上角,这张地铁地图自然是这样的,你想让它指向哪个方向?什么角度?对不起,我不是纽约人我以前从来没见过这张地图。哦,长岛湾那个灰色的吃豆人形状的东西应该是指向北方的箭头吗?
int x1 = (int) ((a.getLon() - minLon) / lonLength * width);
int y1 = (int) ((maxLat - a.getlat()) / latLength * height);