问题描述
最近要把一个应用程序做成Eclipse插件,在插件actions类中的run方法调用同一项目中的上级目录中的类方法,却调用不到这是一个测试类代码packageviewtest;importjavax.imageio.ImageIO;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.WindowConstants;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Dimension;importjava.awt.Font;importjava.awt.Frame;importjava.awt.Image;importjavax.swing.JButton;importorg.jfree.chart.ChartFactory;importorg.jfree.chart.ChartPanel;importorg.jfree.chart.JFreeChart;importorg.jfree.chart.axis.NumberAxis;importorg.jfree.chart.axis.NumberTickUnit;importorg.jfree.chart.axis.ValueAxis;importorg.jfree.chart.plot.PlotOrientation;importorg.jfree.chart.plot.XYPlot;importorg.jfree.chart.renderer.xy.XYLineAndShapeRenderer;importorg.jfree.chart.title.TextTitle;importorg.jfree.data.Range;importorg.jfree.data.xy.XYDataset;importorg.jfree.data.xy.XYSeries;importorg.jfree.data.xy.XYSeriesCollection;importjava.awt.Point;importjava.io.File;importjava.io.IOException;publicclassjframeJFreechart{privatestaticfloatstart=0;privatestaticfloatend=40;privatestaticintnode=30;privateintlength=600;privateintheight=600;publicJFramejframe=null;privateJFramejFrame=null;//@jve:decl-index=0:visual-constraint="73,-5"privateJPaneljContentPane=null;privateJButtonjButton=null;//@jve:decl-index=0:visual-constraint="538,219"/***ThismethodinitializesjFrame**@returnjavax.swing.JFrame*/privateJFramegetJFrame(){if(jFrame==null){jFrame=newJFrame();jFrame.setSize(newDimension(606,327));jFrame.setContentPane(getJContentPane());jframe.setLayout(null);}returnjFrame;}/***ThismethodinitializesjContentPane**@returnjavax.swing.JPanel*/privateJPanelgetJContentPane(){if(jContentPane==null){jContentPane=newJPanel();jContentPane.setLayout(null);jContentPane.add(getJButton());jContentPane.add(getChartPanel());}returnjContentPane;}/***ThismethodinitializesjButton**@returnjavax.swing.JButton*/privateJButtongetJButton(){if(jButton==null){jButton=newJButton();jButton.setSize(newDimension(116,33));jButton.setLocation(newPoint(249,253));jButton.setText("LVOEMORE");}returnjButton;}//数据源封装privatestaticXYDatasetcreateDataset(){XYSeriesxyseries=newXYSeries("厚度曲线");//先产生XYSeries对象xyseries.add(1.0D,11.0D);xyseries.add(1.1D,12D);xyseries.add(1.2D,11D);xyseries.add(1.2D,13D);xyseries.add(2D,14D);xyseries.add(3D,10D);xyseries.add(4D,15D);xyseries.add(5D,19D);xyseries.add(6D,17D);xyseries.add(7D,14D);xyseries.add(8D,18D);//XYSeriesxyseries1=newXYSeries("Second");//xyseries1.add(1.0D,15D);//xyseries1.add(2D,17D);//xyseries1.add(3D,16D);//xyseries1.add(4D,18D);//xyseries1.add(5D,14D);//xyseries1.add(6D,14D);//xyseries1.add(7D,12D);//xyseries1.add(8D,11.0D);////XYSeriesxyseries2=newXYSeries("Third");//xyseries2.add(1D,16D);//xyseries2.add(2D,19D);//xyseries2.add(3D,14D);//xyseries2.add(4D,13D);//xyseries2.add(5D,12D);//xyseries2.add(6D,13D);//xyseries2.add(7D,16D);//xyseries2.add(8D,13D);XYSeriesCollectionxyseriescollection=newXYSeriesCollection();//再用XYSeriesCollection添加入XYSeries//对象xyseriescollection.addSeries(xyseries);//xyseriescollection.addSeries(xyseries1);//xyseriescollection.addSeries(xyseries2);returnxyseriescollection;}publicstaticJFreeChartcreateJFreeChart(){//创建图表JFreeChartchart=ChartFactory.createXYLineChart("测厚曲线","采样点","厚度值",createDataset(),PlotOrientation.VERTICAL,true,true,true);chart.addSubtitle(newTextTitle("http://www.51sensors.com",newFont("Arial",Font.BOLD,15)));//设置报表背景Imageimage=null;try{image=ImageIO.read(newFile("D:\http_imgload.jpg"));}catch(IOExceptione){e.printStackTrace();}chart.setBackgroundImage(image);//设置背景透明度:0.0--1.0chart.setBackgroundImageAlpha(0.5f);//设置非数据域颜色chart.setBackgroundPaint(Color.cyan);//设置边界线条chart.setBorderPaint(Color.RED);chart.setBorderVisible(true);//数据区设置XYPlotplot=(XYPlot)chart.getPlot();//设置背景为灰色plot.setBackgroundPaint(Color.DARK_GRAY);//X、Y轴属性设置NumberAxisrangeAxis=(NumberAxis)plot.getRangeAxis();//数据轴的数据标签(可以只显示整数标签,需要将AutoTickUnitSelection设false)rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());//是否显示零点rangeAxis.setAutoRangeIncludesZero(true);//Y轴名称的倾斜角度rangeAxis.setLabelAngle(0);//设置数据轴的数据范围rangeAxis.setRange(newRange(start,end));//设置刻度波动值,可控制刻度的个数。intnodenum=(int)((end-start)/node);if(nodenum==1){nodenum=2;}rangeAxis.setTickUnit(newNumberTickUnit(nodenum));//数据线设置//显示折点数据//LineAndShapeRendererlineandshaperenderer=(LineAndShapeRenderer)//plot//.getRenderer();//lineandshaperenderer//.setBaseItemLabelGenerator(newStandardCategoryItemLabelGenerator());//lineandshaperenderer.setBaseItemLabelsVisible(true);//设置纵轴的字体格式rangeAxis.setTickLabelFont(newFont("Arial",Font.BOLD,15));//设置坐标轴是否显示箭头ValueAxisvalueaxis=plot.getDomainAxis();valueaxis.setPositiveArrowVisible(true);//设置每个曲线的颜色(两种设置方式)XYLineAndShapeRendererrenderer=(XYLineAndShapeRenderer)plot.getRenderer();renderer.setSeriesPaint(0,Color.cyan);renderer.setSeriesPaint(1,newColor(0,100,255));renderer.setSeriesPaint(2,Color.green);returnchart;}publicChartPanelgetChartPanel(){JFreeChartchart=createJFreeChart();ChartPanelchartPanel=newChartPanel(chart);chartPanel.setPreferredSize(newDimension(length,height));//setContentPane(chartPanel);chartPanel.setSize(300,300);returnchartPanel;}publicstaticJPanelcreateDemoPanel(){//生成jfreechart对象JFreeChartjfreechart=createJFreeChart();returnnewChartPanel(jfreechart);}publicstaticvoidmain(String[]args){JFramejframe=newJFrame("testchart");//jframe.pack();jframe.setSize(700,700);jframe.getContentPane().add(jframeJFreechart.createDemoPanel());//jframe.getContentPane().add(new//jframeJFreechart().getJContentPane().add(new//jframeJFreechart().getJButton()));jframe.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);jframe.setVisible(true);}}这是插件项目actions类run方法中对上面类的调用/***Theactionhasbeenactivated.Theargumentofthemethodrepresentsthe*'real'actionsittingintheworkbenchUI.**@seeIWorkbenchWindowActionDelegate#run*/publicvoidrun(IActionaction){jfreecharttestjft=newjfreecharttest("thisisthethicknessline");jft.pack();RefineryUtilities.centerFrameOnScreen(jft);jft.setVisible(true);}运行该结果是没有反应,都不进入run方法。很无解,求大侠赐教!