按下按钮时功能不起作用

时间:2014-01-19 15:43:22

标签: java javafx

以下是我的代码。问题是当按下ABOUT按钮时,它不起作用。我试着调用about()方法。不知怎的,它不起作用。为了让它发挥作用我应该做些什么改变?

package welcomepage;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;

public class WelcomePage extends Application {

@Override
public void start(Stage stage) {

    BorderPane border = new BorderPane();

    border.setTop(addVBox());
    border.setLeft(addVBox1());

    Scene scene = new Scene(border,700,450);
    stage.setScene(scene);
    stage.setResizable(false);
    stage.show();

}

private VBox addVBox() {

    VBox vbox = new VBox();
    vbox.setPadding(new Insets(5, 12, 5, 20));
    vbox.setSpacing(10);
    vbox.setStyle("-fx-background-color: #336699;");

    Label lb1=new Label("    C - MARK AND ATTENDANCE CALCULATOR");
    lb1.setAlignment(Pos.CENTER);
    lb1.setFont(Font.font("Calibri",FontWeight.BOLD,28));
    lb1.setTextFill(Color.BLACK);
    lb1.setGraphic(new ImageView(image));

    vbox.getChildren().addAll(lb1);

    return vbox;
}

private VBox addVBox1()
{
    VBox vbox1=new VBox();
    vbox1.setPadding(new Insets(20, 2, 15, 20));
    vbox1.setSpacing(20);

    Button btnl1=new Button();
    btnl1.setText("CREATE ACCOUNT");
    btnl1.setFont(Font.font("Calibri",FontWeight.BOLD,16));
    btnl1.setPrefSize(300,40);
    btnl1.setStyle(" -fx-base: #006633;");

    final Tooltip tooltip1 = new Tooltip();
    tooltip1.setText("Create a new account\nfor new user.");
    btnl1.setTooltip(tooltip1);

    Button btnl2=new Button("SIGN IN");
    btnl2.setFont(Font.font("Calibri",FontWeight.BOLD,16));
    btnl2.setPrefSize(300,40);
    btnl2.setStyle(" -fx-base: #006633;");

    final Tooltip tooltip2 = new Tooltip();
    tooltip2.setText("If you have an account,\nSign in here.");
    btnl2.setTooltip(tooltip2);

    Button btnl3=new Button("CONTACT US");
    btnl3.setFont(Font.font("Calibri",FontWeight.BOLD,16));
    btnl3.setPrefSize(300,40);
    btnl3.setStyle(" -fx-base: #006633;");

    final Tooltip tooltip3 = new Tooltip();
    tooltip3.setText("Contact us via\nour email ID.");
    btnl3.setTooltip(tooltip3);

    Button btnl4=new Button("HELP");
    btnl4.setFont(Font.font("Calibri",FontWeight.BOLD,16));
    btnl4.setPrefSize(300,40);
    btnl4.setStyle(" -fx-base: #006633;");

    final Tooltip tooltip4 = new Tooltip();
    tooltip4.setText("Get help content\nabout this software.");
    btnl4.setTooltip(tooltip4);

    Button btnl5=new Button("ABOUT");
    btnl5.setFont(Font.font("Calibri",FontWeight.BOLD,16));
    btnl5.setPrefSize(300,40);
    btnl5.setStyle(" -fx-base: #006633;");

    final Tooltip tooltip5 = new Tooltip();
    tooltip5.setText("Know about\nthis software.");
    btnl5.setTooltip(tooltip5);

    btnl5.setOnAction(new EventHandler<ActionEvent>() {
     @Override
     public void handle(ActionEvent e) {
      about();
     }
     });

    Button btnl6=new Button("EXIT");
    btnl6.setFont(Font.font("Calibri",FontWeight.BOLD,16));
    btnl6.setPrefSize(300,40);
    btnl6.setStyle(" -fx-base: #006633;");

    final Tooltip tooltip6 = new Tooltip();
    tooltip6.setText("Exit if you had\nfinished your works.");
    btnl6.setTooltip(tooltip6);

    btnl6.setOnAction(new EventHandler<ActionEvent>() {
     @Override
     public void handle(ActionEvent e) {
      System.exit(0);
     }
     });

    vbox1.getChildren().addAll(btnl1,btnl2,btnl3,btnl4,btnl5,btnl6);

    return vbox1;
}


public void about() {


    BorderPane border = new BorderPane();

    HBox hbox11 = addHBox();
    border.setTop(hbox11);
    border.setCenter(addVBox12());
    border.setBottom(addHBox12());

    Scene scene = new Scene(border,700,450);
    stage.setScene(scene);
    stage.setResizable(false);
    stage.show();
}

private HBox addHBox() {

    HBox hbox11 = new HBox();
    hbox11.setPadding(new Insets(15, 12, 15, 320));
    hbox11.setSpacing(10);
    hbox11.setStyle("-fx-background-color: #336699;");

    Label lb1=new Label("ABOUT");
    lb1.setAlignment(Pos.CENTER);
    lb1.setFont(Font.font("Trebuchet MS",FontWeight.BOLD,20));

    hbox11.getChildren().addAll(lb1);

    return hbox11;
}

private VBox addVBox12() {

    VBox vbox11 = new VBox();
    vbox11.setPadding(new Insets(20));
    vbox11.setSpacing(5);

    Label l1=new Label("C - MARK AND ATTENDANCE CALCULATOR");
    l1.setFont(Font.font("Calibri",FontWeight.BOLD,20));
    l1.setTextFill(Color.GREEN);

    Label l2=new Label("\nSoftware to calculate C-mark and attendance easily.\n"
            + "Supported in Windows XP or above.\n"
            + "Developed using Java.\n"
            + "Advantages : Simple user interface, Easy usage.\n\n"
            + "Developed by :\n"
            + "\t\t Adarsh P.S \n"
            + "\t\t Akhilnath A.R \n"
            + "\t\t Arjun P Das \n"
            + "\t\t Tomin Jacob ");
    l2.setFont(Font.font("Calibri",FontWeight.BOLD,18));
    l2.setTextFill(Color.GREEN);

    vbox11.getChildren().addAll(l1,l2);
    return vbox11;
}

private HBox addHBox12()
{
   HBox hbox12 = new HBox();
   hbox12.setPadding(new Insets(15, 12, 15, 300));

   Button btn1=new Button("BACK");
   btn1.setFont(Font.font("Calibri",FontWeight.BOLD,18));
   btn1.setPrefSize(100,40);

   hbox12.getChildren().addAll(btn1);
    return hbox12;
}


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

}

1 个答案:

答案 0 :(得分:0)

在尝试调用其上的任何操作之前定义变量stage

Stage stage = new Stage();