473,394 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

EventHandler<T extends Event> in JavaFX a class or interface.

Hi,

I have picked a basic example of printing "Hello World" on screen when the mouse is clicked The code goes like this.

Expand|Select|Wrap|Line Numbers
  1. package sample;
  2.  
  3. import javafx.application.Application;
  4. import javafx.event.ActionEvent;
  5. import javafx.event.EventHandler;
  6. import javafx.scene.Scene;
  7. import javafx.scene.control.Button;
  8. import javafx.scene.layout.StackPane;
  9. import javafx.stage.Stage;
  10.  
  11. /**
  12.  *
  13.  * @author gauravp
  14.  */
  15. public class Sample extends Application {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     Button btn = new Button("ok");
  21.     //Label l = new Label("Done");
  22.  
  23.     public static void main(String[] args) {
  24.         launch(args);
  25.     }
  26.  
  27.     @Override
  28.     public void start(Stage primaryStage) {
  29.  
  30.         primaryStage.setTitle("First Stage");
  31.  
  32.  
  33.         //Created anonymous inner class EventHandler<ActionEvent>
  34.         btn.setOnAction(new EventHandler<ActionEvent>() {
  35.  
  36.             @Override
  37.             public void handle(ActionEvent event) {
  38.  
  39.                     System.out.print("Hello World !!");
  40.  
  41.  
  42.             }
  43.         });
  44.  
  45.         StackPane root = new StackPane();
  46.         root.getChildren().add(btn);
  47.         primaryStage.setScene(new Scene(root, 300, 250));
  48.         primaryStage.show();
  49.     }
  50. }
  51.  

In documentation it is mentioned that EventHandler is an interface , but how come the interface be instantiated...

"new EventHandler<ActionEvent>()"

In a lot of confusion....please reply if you have any idea.. Here is the link

http://docs.oracle.com/javafx/2.0/api/javafx/event/EventHandler.html
Jan 20 '12 #1
0 1553

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: GrantS | last post by:
I am trying to convert the VB.Net code example povided by http://authors.aspalliance.com/JimRoss/Articles/MaintainScrollPos.aspx into C# (ASP.Net)without success. No errors are thrown in the VB...
5
by: DotNetGruven | last post by:
Hi, I have a web form which has: - Login area with - email textbox - password textbox - <enter> button to log in - search area with - string to search for textbox
3
by: rao | last post by:
Hi All, I am generating temporary xml files to bind it to tree view control. A unique xml file is generated for each user. I generating these files Using streamwriter class. Later when I try to...
3
by: danc | last post by:
I have a datagrid with a checkbox and dropdown list in each row. Both set AutoPostBack to true and ItemCommand and OnSelectedIndexChanged events for these controls works fine when DataGrid is not...
4
by: R.A.M. | last post by:
Hello, Could anyone help me to handle <asp:Image> click in behind code? I have: <asp:Image ID="DotNETImage" ImageUrl="Images/DotNET_360x280.jpeg" AlternateText="Microsoft .NET version 2.0"...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.