Java 用JPanel绘制x,y坐标系并绘制方程

Java 用JPanel绘制x,y坐标系并绘制方程,java,swing,jpanel,paintcomponent,Java,Swing,Jpanel,Paintcomponent,我的任务是使用JPanel绘制坐标系。然后我需要用线段绘制一个给定的方程。要求是:0.0“…我在正确使用绘制线方法时遇到问题。”--请详细描述您的问题。请包括任何有助于我们理解您的问题的内容。此外,我不会在g.drawLine(…)方法调用中硬编码或使用“幻数”。相反,我可能会根据JPanel绘图区域的大小来计算数字。@Hovercraft Full of Eels hello:-)使用JFreeChart,您可能会看到一个this或this。 public class Curve extend

我的任务是使用JPanel绘制坐标系。然后我需要用线段绘制一个给定的方程。要求是:0.0
“…我在正确使用绘制线方法时遇到问题。”
--请详细描述您的问题。请包括任何有助于我们理解您的问题的内容。此外,我不会在
g.drawLine(…)
方法调用中硬编码或使用“幻数”。相反,我可能会根据JPanel绘图区域的大小来计算数字。@Hovercraft Full of Eels hello:-)使用
JFreeChart
,您可能会看到一个this或this。
public class Curve extends JPanel
{

    // initialize variables 
    private int choice; // users choice which function to pick 
    private int lines; // number of lines for curve 

    public Curve(int choice, int lines)
    {
        this.choice = choice; // assign choice in instance variable choice
        //this.x = x; // assigns x instance variable x 
        this.lines = lines; // assigns lines in instance variable lines
    } // end Curve constructor 

    // method to draw x,y axis and ticks
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        int x = getWidth()/2;
        int y = getHeight()/2;
        int tic = getWidth() / 100;
        g.translate(x, y);
        g.setColor (Color.black);
        //g.drawLine (200, 50, 50, 50);


        g.drawLine (0, 0, x, 0);
        g.drawLine (0, -y+50, 0, y-50);

        for (int k = -x/7; k <= x; k += 33)
            g.drawLine (k, tic, k, -tic);

        // draw the tic marks along the y axis
        for (int k = -y+20; k <= y-20; k += 50)
          g.drawLine (-tic , k, tic, k);
    }



    // method to pick function based on user's choice
    public void draw()
    {
        switch ( choice ) // takes in user's choice and plugs into function
        // question 
        {
            case 1: // function 1: y = 1.0 - x: x = int1 
                break;
            case 2: 
                break;
            case 3:
                break;
            case 4:
                break;
            case 5:
                break;

        } // end switch statement
    } // end method
} // end class Curve`