PROG24178 Lecture 12: Event Handler Lecture Notes

35 views7 pages
27 Jul 2016
Course
Professor
Event Handler Lecture Notes
Event Handling Example
-it is something done by the user to the GUI, ie upon event like a button click or a resizing or mouse over
it causes a message to be sent to an object like an alert box
-using event handling is referred to as event-driven programming
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package eventhandlingexample;
//import eventhandlingexample.EventHandlingExample.AddCircle;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
//import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 7 pages and 3 million more documents.

Already have an account? Log in
* @author PalomaDS
*/
public class EventHandlingExample extends Application { //this is my javafx application
private HBox pane = new HBox();//creates a new object called pane in the hbox
private Button btnCircle = new Button("Add Circle");//import the button predefined class and create a
new button object and give it the text add cir in the constructor
@Override
public void start(Stage primaryStage) {
pane.setSpacing(20);//my spacing is 20px
pane.getChildren().add(new TheCircle(100));//the constructor now has a width of 100px for
TheCircle
Scene scene = new Scene(pane, 800, 250); //root, 800 on x, 250 on y
pane.getChildren().add(btnCircle);//add the button to the pane
btnCircle.setOnAction(new AddCircle());//on click add the circle that we created, the new one
primaryStage.setTitle("Event Handling Example");//the title of the primary stage
primaryStage.setScene(scene);//set the scene to the scene object
primaryStage.show();//show the elements
}
public class TheCircle extends StackPane { //add a class called thecircle that is a subclass of stackpane,
we call this an inner class
private int radius;//my field variiable radius
/* public int getradius(int radius) {
return radius;
//assign radius to getradius
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 7 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$10 USD/m
Billed $120 USD annually
Homework Help
Class Notes
Textbook Notes
40 Verified Answers
Study Guides
1 Booster Class
Class+
$8 USD/m
Billed $96 USD annually
Homework Help
Class Notes
Textbook Notes
30 Verified Answers
Study Guides
1 Booster Class