0
我用x和y軸創建了我自己的圖表。我發現目前的圖表選擇並不適合我的需求。我設法將我的圖表構建到了我的喜好中,現在我想將所有組件添加到擴展AnchorPane的對象中。最終結果是我的代碼編譯時沒有錯誤,沒有運行時錯誤,但是我沒有看到我創建的任何窗格。我想知道正確的程序是什麼擴展AnchorPane。當擴展不工作時錨定
這是我的類內擴展應用程序的代碼。工程就像一個魅力:
Vector <String[]> v = new Vector<String[]>();
double highest_high = 0;
double lowest_low = 0;
AnchorPane anchorpane = new AnchorPane();
double xaxisHeight = 20;
double yaxisWidth = 60;
double chartYAdjustment = 40;
double barGap = 3;
double bars = 15;
final Chart chart = new Chart(v, yaxisWidth, xaxisHeight, highest_high, lowest_low, chartYAdjustment, barGap);
final YAxis yaxis = new YAxis(yaxisWidth, highest_high, lowest_low);
final XAxis xaxis = new XAxis(xaxisHeight, barGap, bars);
AnchorPane.setTopAnchor(yaxis, 0.0);
AnchorPane.setRightAnchor(yaxis, 0.0);
AnchorPane.setBottomAnchor(yaxis, 20.0);
AnchorPane.setLeftAnchor(xaxis, 0.0);
AnchorPane.setRightAnchor(xaxis, 60.0);
AnchorPane.setBottomAnchor(xaxis, 0.0);
AnchorPane.setLeftAnchor(chart, 0.0);
AnchorPane.setTopAnchor(chart, 0.0);
AnchorPane.setBottomAnchor(chart, 0.0);
AnchorPane.setRightAnchor(chart, 0.0);
anchorpane.getChildren().addAll(chart, yaxis, xaxis);
Scene s = new Scene(anchorpane, 800, 400, Color.BLACK);
stage.setScene(s);
stage.show();
當我把代碼擴展AnchorPane一個類中:
public class Main extends AnchorPane{
public void Main(){
Vector <String[]> v = new Vector<String[]>();
double highest_high = 0;
double lowest_low = 0;
double xaxisHeight = 20;
double yaxisWidth = 60;
double chartYAdjustment = 40;
double barGap = 3;
double bars = 15;
final Chart chart = new Chart(v, yaxisWidth, xaxisHeight, highest_high, lowest_low, chartYAdjustment, barGap);
final YAxis yaxis = new YAxis(yaxisWidth, highest_high, lowest_low);
final XAxis xaxis = new XAxis(xaxisHeight, barGap, bars);
AnchorPane.setTopAnchor(yaxis, 0.0);
AnchorPane.setRightAnchor(yaxis, 0.0);
AnchorPane.setBottomAnchor(yaxis, 20.0);
AnchorPane.setLeftAnchor(xaxis, 0.0);
AnchorPane.setRightAnchor(xaxis, 60.0);
AnchorPane.setBottomAnchor(xaxis, 0.0);
AnchorPane.setLeftAnchor(chart, 0.0);
AnchorPane.setTopAnchor(chart, 0.0);
AnchorPane.setBottomAnchor(chart, 0.0);
AnchorPane.setRightAnchor(chart, 0.0);
getChildren().addAll(chart, yaxis, xaxis);
然後在我的類,它擴展應用,我有:
Main main = new Main();
Scene s = new Scene(main, 800, 400, Color.BLACK);
stage.setScene(s);
stage.show();
它只顯示一個黑色的窗口。