我正在尝试用Java制作3D图。对此我使用jmathplot
。我有搜索找到一种方法来为我的污点添加标题,并且发现使用如下BaseLabel
应该有效。但是,当我尝试运行我的程序时,我得到java.lang.ArrayIndexOutOfBoundsException: 2 out of bound exception
。我无法弄清楚为什么会这样。看起来好像它是摆动面板而不是图形。当删除将BaseLabel添加到我的绘图的行时,代码工作正常。希望你们中的一些人能够提供帮助。
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.*; //JFrame;
import org.math.plot.Plot3DPanel;
import org.math.plot.plotObjects.BaseLabel;
public class plotFrame1
{
private JFrame frame = new JFrame("tester plot");
private JPanel panel = new JPanel();
public plotFrame1()
{
double[][] xyz = new double[4][3];
double[][] widths = new double[4][3];
int ds = 0;
for(int i = 0; i < xyz.length; i++)
{
xyz[i][0] = ds;
xyz[i][1] = ds;
xyz[i][2] = ds;
ds += 1;
widths[i][0] = 1;
widths[i][1] = 1;
widths[i][2] = 1;
}
Plot3DPanelPackage plot = new Plot3DPanelPackage();
BaseLabel title = new BaseLabel("...My nice plot...", Color.BLACK, 0.5, 1.1);
plot.addPlotable(title);
String n = "test";
Color c = Color.black;
plot.addPackagePlot(xyz,widths,c,n);
panel.setLayout(new BorderLayout());
panel.add(plot);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
class Plot3DPanelPackage extends Plot3DPanel
{
public int addPackagePlot(double[][] _xyz, double[][] _measures, Color c, String n)
{
return addPlot(new PackagePlot3D(_xyz,_measures,c,n));
}
}
public static void main(String args[]) {
plotFrame1 ny = new plotFrame1();
}
}
整个错误如下:
线程“AWT-EventQueue-0”中的异常 java.lang.ArrayIndexOutOfBoundsException:2 at org.math.plot.render.Projection.screenProjectionBase(未知来源) 在org.math.plot.render.AWTDrawer.drawTextBase(未知来源)at at org.math.plot.plotObjects.BaseLabel.plot(未知来源)at org.math.plot.canvas.PlotCanvas.paint(未知来源)at javax.swing.JComponent.paintChildren(未知来源)at javax.swing.JComponent.paint(未知来源)at javax.swing.JComponent.paintChildren(未知来源)at javax.swing.JComponent.paint(未知来源)at javax.swing.JComponent.paintChildren(未知来源)at javax.swing.JComponent.paint(未知来源)at javax.swing.JComponent.paintChildren(未知来源)at javax.swing.JComponent.paint(未知来源)at javax.swing.JLayeredPane.paint(未知来源)at javax.swing.JComponent.paintChildren(未知来源)at javax.swing.JComponent.paintToOffscreen(未知来源)at javax.swing.RepaintManager中的$ PaintManager.paintDoubleBuffered(未知 来自)javax.swing.RepaintManager $ PaintManager.paint(未知 来源)在javax.swing.RepaintManager.paint(未知来源)at javax.swing.JComponent.paint(未知来源)at java.awt.GraphicsCallback $ PaintCallback.run(未知来源)at sun.awt.SunGraphicsCallback.runOneComponent(未知来源)at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)at java.awt.Container.paint(未知来源)at java.awt.Window.paint(未知来源)at javax.swing.RepaintManager $ 4.run(未知来源)at javax.swing.RepaintManager $ 4.run(未知来源)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(未知 来源)在javax.swing.RepaintManager.paintDirtyRegions(未知 来源)在javax.swing.RepaintManager.paintDirtyRegions(未知 来自)javax.swing.RepaintManager.prePaintDirtyRegions(未知 来源)在javax.swing.RepaintManager.access $ 1200(未知来源)at javax.swing.RepaintManager $ ProcessingRunnable.run(未知来源)at java.awt.event.InvocationEvent.dispatch(未知来源)at java.awt.EventQueue.dispatchEventImpl(未知来源)at java.awt.EventQueue.access $ 500(未知来源)at java.awt.EventQueue $ 3.run(未知来源)at java.awt.EventQueue $ 3.run(未知来源)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(未知 来自)java.awt.EventQueue.dispatchEvent(未知来源)at java.awt.EventDispatchThread.pumpOneEventForFilters(未知来源) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 在java.awt.EventDispatchThread.pumpEventsForHierarchy(未知 来自java.awt.EventDispatchThread.pumpEvents(未知来源) at java.awt.EventDispatchThread.pumpEvents(Unknown Source)at java.awt.EventDispatchThread.run(未知来源)