Question

In: Computer Science

Hello I'm currently having an error that says "main is not abstract and does not override...

Hello I'm currently having an error that says "main is not abstract and does not override abstract method" is there a way to fix the error?

import java.io.IOException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import static javafx.application.Application.launch;
import javafx.scene.layout.StackPane;
public class Main extends Application implements EventHandler<ActionEvent>{
    public static void main(String[] args){
        launch(args);
    }
    @Override
    public void Start(Stage stage){
        stage.setTitle("Test");
        Button calcButton = new Button("Steam");
      
        StackPane root = new StackPane();
        calcButton.setOnAction(this);
      
        Scene scene = new Scene(root, 100, 100);
      
        stage.setScene(scene);
        stage.setTitle("Test");      
        stage.show();

    }
    class CalcButtonHandle {
      
        public void handle(ActionEvent event) throws IOException
        {
        Main fo = new Main();
        fo.runOt("D:\\Steam\\Steam.exe");
        }
    }
  
    public void runOt(String path) throws IOException{
        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + path);
    }
}
  

Solutions

Expert Solution

If an interface is implemented by a class, it is necessary for the class to have function body for all the function definitions of the interface, unless the class is abstract or an interface itself.

The Main class implements EventHandler<ActionEvent> interface, therefore, it must also have the body of handle(ActionEvent event) function which is a function definition in EventHandler interface.

There was no need of a separate class CalcButtonHandle to wrap the handle() function. Below is the edited code (in bold), hope it helps!

Code:

import java.io.IOException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import static javafx.application.Application.launch;
import javafx.scene.layout.StackPane;
public class Main extends Application implements EventHandler<ActionEvent>{
    public static void main(String[] args){
        launch(args);
    }
    @Override
    public void Start(Stage stage){
        stage.setTitle("Test");
        Button calcButton = new Button("Steam");
      
        StackPane root = new StackPane();
        calcButton.setOnAction(this);
      
        Scene scene = new Scene(root, 100, 100);
      
        stage.setScene(scene);
        stage.setTitle("Test");      
        stage.show();

    }


    public void handle(ActionEvent event) throws IOException
{
        Main fo = new Main();
        fo.runOt("D:\\Steam\\Steam.exe");
    }

  
    public void runOt(String path) throws IOException{
        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + path);
    }
}


Related Solutions

I am having an error in this function. It says Max was not found. int height()...
I am having an error in this function. It says Max was not found. int height() const {    if (is_null()) return 0; return 1 + max(get_left_subtree().height(), get_right_subtree().height()); } The whole code is #ifndef BINARY_TREE_H #define BINARY_TREE_H #include <cstddef> #include <sstream> #include <stdexcept> #include <string> #include <algorithm> #include "BTNode.h" template<typename Item_Type> class Binary_Tree { public: Binary_Tree() : root(NULL) {} Binary_Tree(const Item_Type& the_data, const Binary_Tree<Item_Type>& left_child = Binary_Tree(), const Binary_Tree<Item_Type>& right_child = Binary_Tree()) : root(new BTNode<Item_Type>(the_data, left_child.root, right_child.root)) {} virtual ~Binary_Tree()...
can someone tell me why I'm getting the error code on Eclipse IDE: Error: Main method...
can someone tell me why I'm getting the error code on Eclipse IDE: Error: Main method is not static in class StaticInitializationBlock, please define the main method as:    public static void main(String[] args) This is what I'm working on class A { static int i; static { System.out.println(1); i = 100; } } public class StaticInitializationBlock { static { System.out.println(2); } public static void main(String[] args) { System.out.println(3); System.out.println(A.i); } }
Hello, I'm having a hard time solving these problems because I have no idea on what...
Hello, I'm having a hard time solving these problems because I have no idea on what to do with accrued interest. Help is highly appreciated! On March 1, 2015, Bowan Corporation issued 6% bonds dated February 1, 2015, the face amount of $700,000. The bonds were sold for the present value of the bonds on March 1, 2015 plus one-month accrued interest. The bonds mature on January 31, 2018. Interest is paid semiannually on July 31 and January 31. Bowan's...
I'm getting this error: Exception in thread "main" java.lang.NoSuchMethodError: main I tried using public static void...
I'm getting this error: Exception in thread "main" java.lang.NoSuchMethodError: main I tried using public static void main(String[] args){ but that negates all of the methods that I try to write. I'm just trying to make it so that I can enter values. Thanks. Code below: import java.util.Scanner; public class DataSet2 { private double value; private double sum; private int count; public void add(double value){    System.out.println("Enter values, enter -1 to finish");    Scanner scan = new Scanner(System.in);    value =...
hello, I'm having trouble understanding how to do these two problems could you show me a...
hello, I'm having trouble understanding how to do these two problems could you show me a step by step. 1)Eight sprinters have made it to the Olympic finals in the 100-meter race. In how many different ways can the gold, silver, and bronze medals be awarded? 2)Suppose that 34% of people own dogs. If you pick two people at random, what is the probability that they both own a dog? Give your answer as a decimal (to at least 3...
I'm having trouble with validating this html code. Whenever I used my validator, it says I...
I'm having trouble with validating this html code. Whenever I used my validator, it says I have a stray end tag: (tbody) from line 122 to 123. It's the last few lines. Thanks and Ill thumbs up whoever can help solve my problem. Here's my code: <!DOCTYPE html> <html lang="en"> <head> <title>L7 Temperatures Fields</title> <!--    Name:    BlackBoard Username:    Filename: (items left blank for bb reasons    Class Section: (blank)    Purpose: Making a table to demonstrate my...
In C++ what does it mean when it says: "error: stray '\226' inprogram"
In C++ what does it mean when it says: "error: stray '\226' in program"
Directional and non-directional Hello! I'm having som trouble understanding the meaning of directional and non-directional hypothesis....
Directional and non-directional Hello! I'm having som trouble understanding the meaning of directional and non-directional hypothesis. What does it mean, and how do this affect the p-value? I also heard about "negative directional alternative" but could not find any information about this Thank you!
I'm having trouble understanding the following code (a snippet of a code). What does it do?...
I'm having trouble understanding the following code (a snippet of a code). What does it do? The whole code is about comparing efficiencies of different algorithms. def partition(list,first,last): piv = list[first] lmark = first+1 rmark = last done = False while not done: while lmark <= rmark and list[lmark]<=piv: lmark=lmark+1 while list[rmark]>=piv and rmark>=lmark: rmark=rmark-1 if rmark<lmark: done = True else: temp = list[lmark] list[lmark]=list[rmark] list[rmark]=temp temp = list[first] list[first]=list[rmark] list[rmark]=temp return rmark
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT