在JFrame窗体上按下Jbutton时不显示导出

时间:2014-11-24 13:03:05

标签: java jframe

我在JFrame表单上有一个JButton,我需要打开一个Scatter Diagram,散点图的编码在普通的JPanel上,但是当我运行它时会出现错误。当我为JFrame JFrame做同样的事情时,它工作正常。

这里是散点图的代码:

public class X1 extends JFrame implements ActionListener {
double[] x = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.5, 2.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.5, 1.5, 1.5, 1.0, 1.0, 1.5, 1.5, 1.5, 1.5, 3, 1.5, 1.5};
double[] y = {4.9176, 5.0208, 4.5429, 4.5573, 5.0597, 3.8910, 5.8980, 5.6039, 16.4202, 14.4598, 5.8282, 5.3003, 6.2712, 5.9592, 5.0500, 5.6039, 8.2464, 6.6969, 7.7841, 9.0384, 5.9894, 7.5422, 8.7951, 6.0931, 8.3607, 8.1400, 9.1416, 12.0000};
SimpleRegression sr = new SimpleRegression();
Plot2DPanel plot = new Plot2DPanel();
JTextArea resultados = new JTextArea();
JTextArea result = new JTextArea();

public X1() {
    for (int i = 0; i < x.length; i++) {
        sr.addData(x[i], y[i]);
    }
    double[] yc = new double[y.length];
    for (int i = 0; i < x.length; i++) {
        yc[i] = sr.predict(x[i]);
    }
    plot.addLegend("South");
    plot.addScatterPlot("Data", x, y);
    plot.addLinePlot("Regression", x, yc);
    plot.setFixedBounds(0, 0, 4);
    BaseLabel Title = new BaseLabel("Regression Line", Color.BLUE, 0.5, 1.1);
    plot.addPlotable(Title);
    result.append("/ny-Intercept:" + sr.getIntercept());

    JFrame frame = new JFrame("Regression Line");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(900, 600);
    frame.add(plot, BorderLayout.CENTER);
    frame.setVisible(true);

}

public void actionPerformed(ActionEvent e) {
}

public static void main(String[] args) {
    new X1();
}
}

当我在JFrame上双击JButton

时,这是代码源
package testinggraph;

/**
 *
 * @author as776
 */
public class Graph1 extends javax.swing.JFrame {

/**
 * Creates new form Graph1
 */
public Graph1() {
    initComponents();
}   

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    new X1 ();
    X1 G1 = new X1 ();
    X1.setVisible(true);
}                                                 

这些是运行文件时出现的主要错误:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous ctor sym type: testinggraph.X1.<init>
      at testinggraph.Graph1.jButton1ActionPerformed(Graph1.java:191)
      at testinggraph.Graph1.access$000(Graph1.java:13)
    at testinggraph.Graph1.jButton1ActionPerformed(Graph1.java:191)
    at testinggraph.Graph1.access$000(Graph1.java:13)       

1 个答案:

答案 0 :(得分:0)

jButton1ActionPerformed中的代码错误: 实际上,第一行应该足够了,因为这将创建一个新的X1对象,它将自身设置为可见。第二行创建另一个实例(用于??)并将其分配给G1(请注意:在Java中,建议使用小写字符来启动变量)。然后第三行无效:它会调用类setVisible上的X1,可能您想在实例G1上调用它。

但正如我所说,如果其他方法正常工作,该方法的第一行应该足够了。