如何将JFreeChart文件中的外部.jar添加到BlueJ?

时间:2014-12-08 13:43:28

标签: java jar jfreechart packages bluej

我正在做一个程序,我在其中计算三维空间中2点之间的距离。现在我需要JFreeChart来绘制XYZ轴上这两个点形成的直线。此外,该程序需要在另一台具有BlueJ的计算机上运行,​​因此我想以包的形式导入JFreeChart库。但我甚至无法将其添加为Tools \ Preferences \ Libraries中的外部.jars(,我确实重启了BlueJ)。所以请告诉我如何做到这一点,特别是作为一个包。提前致谢。我的代码的一部分如下:

String Sx1,Sx2,Sy1,Sy2,Sz1,Sz2;
                Sx1=tAX.getText();
                Sy1=tAY.getText();
                Sz1=tAZ.getText();
                Sx2=tBX.getText();
                Sy2=tBY.getText();
                Sz2=tBZ.getText();
                double mx,xi,yi,zi,x1,y1,z1,x2,y2,z2,px,py,pz,dXY,dist,c,mz,cmain,c2;
                double re1;
                boolean v1=false,v2=false,v3=false,v4=false;
                x1=Integer.parseInt(Sx1);
                y1=Integer.parseInt(Sy1);
                z1=Integer.parseInt(Sz1);
                x2=Integer.parseInt(Sx2);
                y2=Integer.parseInt(Sy2);
                z2=Integer.parseInt(Sz2);
                px=Math.abs(x2-x1);
                py=Math.abs(y2-y1);
                pz=Math.abs(z2-z1);
                dXY=Math.sqrt((px*px)+(py*py));
                dist=Math.sqrt((dXY*dXY)+(pz*pz));

                mx=py/px;
                mz=py/pz;

                c=y1-(mx*x1);
                c2=y1-(mz*z1);

                JFrame f2=new JFrame("Answers");
                f2.setSize(600,600);
                f2.setVisible(true);
                f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                Dimension dim=Toolkit.getDefaultToolkit().getScreenSize();
                f2.setLocation(dim.width/2-f2.getSize().width/2,dim.height/2-f2.getSize().height/2);

                JPanel p2=new JPanel(new GridBagLayout());

                JLabel L1=new JLabel("The distance between the two points is "+dist);
                gbc.insets=new Insets(5,5,5,5);
                gbc.gridx=0;
                gbc.gridy=1;
                p2.add(L1,gbc);

                JLabel L2=new JLabel("The slope of the line on the x axis is  "+mx);
                gbc.insets=new Insets(5,5,5,5);
                gbc.gridx=0;
                gbc.gridy=2;
                p2.add(L2,gbc);

                if(c!=0)
                {
                    JLabel L3=new JLabel("The equation of the line on the XY plane is: y="+mx+"x+"+c);
                    gbc.insets=new Insets(5,5,5,5);
                    gbc.gridx=0;
                    gbc.gridy=3;
                    p2.add(L3,gbc);
                }
                else 
                {
                    JLabel L3=new JLabel("The equation of the line on the XY plane is: y="+mx+"x");
                    gbc.insets=new Insets(5,5,5,5);
                    gbc.gridx=0;
                    gbc.gridy=3;
                    p2.add(L3,gbc);
                }

                if(c2!=0)
                {
                    JLabel L4=new JLabel("The equation of the line on the YZ plane is: y="+mz+"z+"+c2);
                    gbc.insets=new Insets(5,5,5,5);
                    gbc.gridx=0;
                    gbc.gridy=4;
                    p2.add(L4,gbc);
                }
                else 
                {
                    JLabel L4=new JLabel("The equation of the line on the YZ plane is: y="+mz+"z");
                    gbc.insets=new Insets(5,5,5,5);
                    gbc.gridx=0;
                    gbc.gridy=4;
                    p2.add(L4,gbc);
                }



                f2.add(p2);

在这里,我需要按照2个方程绘制线条。任何有关这方面的建议都会很好!

1 个答案:

答案 0 :(得分:0)

首先,您始终可以从命令提示符/终端窗口运行程序,并使用启动脚本指定外部JAR文件(此处为Windows环境中的示例):

C:> java -classpath C:\java\MyClasses\myclasses.jar utility.myapp.Cool

至于第二个选项,我不确定BlueJ是否在其目录Tools \ Preferences \ Libraries中为您启动的程序提供了库。我假设BlueJ在IDE中有一些方法可以在启动程序时将外部库(已经打包到JAR文件中)添加到Java类路径中。