У меня проблемы с регистрацией обработчика событий - PullRequest
0 голосов
/ 03 мая 2019

У меня проблемы с регистрацией обработчика событий, который должен рассчитывать общее количество введенных пользователем стоимости еды, их желаемый процент чаевых и налог с продаж.Я продолжаю получать сообщение об ошибке, в котором говорится «отсутствует тело метода или объявляется абстрактное».Кажется, нет никаких синтаксических ошибок, поэтому я не совсем уверен, в чем проблема.

Я честно застрял в этой точке и не знаю, в чем проблема.

public class TipTaxTotal extends Application
{
    //Fields
    private TextField mealCostTextField;
    private TextField tipPercentageTextField;
    private TextField salesTaxTextField;
    private Label totalLabel;

    public static void main (String[] args)
    {

        launch(args);
    }


    @Override
    public void start (Stage primaryStage)
    {
    //Meal cost, Tip percentage, and Sales tax labels & TextFields

        Label mealCostLabel = new Label ("Enter the cost of your meal");

        mealCostTextField = new TextField ();

        Label tipPercentageLabel = new Label ("Enter the desired tip percentage");

                tipPercentageTextField = new TextField ();

        Label salesTaxLabel = new Label ("Enter the sales tax percentage");

                salesTaxTextField = new TextField ();

        //This button will perform the calculation
        Button calcButton = new Button("Calculate");

        //Register the event handler
        calcButton.setOnAction(new CalcButtonHandler());

        //This label will display the total
        totalLabel = new Label ();

        //Put all the Labels and Text Fields in the Hbox spaced by 10 px
        HBox hbox = new HBox(10, mealCostLabel, mealCostTextField,
                tipPercentageLabel, tipPercentageTextField, salesTaxLabel,
                salesTaxTextField);

        //Put Hbox, CalcButton, and total Label in the Vbox
        VBox vbox = new VBox(10, hbox, calcButton, totalLabel);

        //align vbox to the center of the stage
        vbox.setAlignment(Pos.CENTER);

        //set vbox padding to 10 px
        vbox.setPadding(new Insets(10));

        //create a scene
        Scene scene = new Scene(vbox);

        //add the scene to the stage
        primaryStage.setScene(scene);

        //give the stage a title
        primaryStage.setTitle("Tip% and Sales Tax Calculator");

        primaryStage.show();

    }
    //This is where my trouble is
    //event handler
    class CalcButtonHandler implements EventHandler<ActionEvent>
    {

        @Override
        public void handle(ActionEvent event);
        {
            //get the meal cost, tip percentage, and sales tax

            double MealCost =
                    Double.parseDouble(mealCostTextField.getText());

            double TipPercentage =
                    Double.parseDouble(tipPercentageTextField.getText());

            double SalesTax =
                    Double.parseDouble(salesTaxTextField.getText());
            //calculate
            double totalTaxes = SalesTax + TipPercentage;
            double total = MealCost * totalTaxes;

            //display total

            totalLabel.setText(String.format("Total: $%,.2f ", total));
        }
    }
}

Предполагается, что calcButton получает полную стоимость питания пользователей, желаемые чаевые и налог с продаж пользователя.

1 Ответ

0 голосов
/ 03 мая 2019

Вам просто не нужно @ Override при реализации интерфейсов, потому что интерфейсы не равны абстрактным классам. Вы не можете переопределить метод интерфейса, потому что он не определен и не помечен как абстрактный.

...