我想绘制xy图形绘图仪

时间:2017-12-08 00:24:39

标签: graph jframe

我想使用jframe显示我的凸包,但是当我运行程序时,我得到了翻转图形,我觉得整个图形都是颠倒翻转的。

查看图片,你可以告诉我的程序显示错误

我在这里找不到问题

谢谢

flipped graph, Right graph

这是我的代码

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.Graphics.*;
import java.util.ArrayList;
import java.util.Scanner;

public class MMain extends JFrame{
public int size;
public int[] x = new int[10];
public int[] y = new int[10];

public MMain(int[] x , int[] y , int size ) {

    this.x= x;
    this.size=size;
    this.y=y;

    setTitle("Name");
    setSize(1000,1000);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

}

public void paint(Graphics s) {

         s.drawLine( 800 , 800 , 100 , 800 );
         s.drawString("x-axis", 810, 800);
         s.drawLine( 100 , 800 , 100 , 100 );
         s.drawString("y-axis", 110, 110);

         s.drawPolygon(x, y, size);

         for(int k = 0 ; k<size; k++) {

         s.drawOval(x[k] , y[k], 8, 8);
         s.fillOval(x[k], y[k], 8, 8);
         } 

     }

 public static void main(String args[])
    {
        System.out.println("Quick Hull Test");
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number of points");
        int N = sc.nextInt();

        ArrayList<Point> points = new ArrayList<Point>();

        System.out.println("Enter the coordinates of each points: <x> <y>");
        for (int i = 0; i < N; i++)
        {
            int x = sc.nextInt();
            int y = sc.nextInt();
            Point e = new Point(x, y);
            points.add(i, e);
        }

        QuickHull qh = new QuickHull();
        ArrayList<Point> p = qh.quickHull(points);
       int[] d= new int[10];
       int[] j= new int[10];
                System.out.println("The points in the Convex hull using Quick Hull are: ");
        for (int i = 0; i < p.size(); i++) {
            System.out.println("(" + p.get(i).x + ", " + p.get(i).y + ")");
            d[i]=p.get(i).x*50;
            j[i]=p.get(i).y*50;
        }

        MMain m = new MMain( d ,j , p.size() ); 
    }
}

0 个答案:

没有答案