0% found this document useful (0 votes)
26 views

Life Cycle Method

The document describes the creation of a registration page application with CSS styling and database connectivity using JDBC. The application contains form fields like name, email and password and a registration button. On clicking the button, the data is inserted into a database table. The registration page is styled using CSS rules for colors, fonts etc. The application demonstrates the use of JavaFX controls, layouts, event handling and JDBC for database operations.

Uploaded by

Rajeswari
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Life Cycle Method

The document describes the creation of a registration page application with CSS styling and database connectivity using JDBC. The application contains form fields like name, email and password and a registration button. On clicking the button, the data is inserted into a database table. The registration page is styled using CSS rules for colors, fonts etc. The application demonstrates the use of JavaFX controls, layouts, event handling and JDBC for database operations.

Uploaded by

Rajeswari
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 11

LIFE CYCLE METHOD:

import javafx.application.Application;

import javafx.scene.Group;

import javafx.scene.Scene;

import javafx.stage.Stage;

public class LyfCycle extends Application {

@Override

public void init()

System.out.println("Inside init() method");

public void start(Stage primaryStage) {

System.out.println("Inside start() method");

Group root = new Group();

Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle("Java Skeleton");

primaryStage.setScene(scene);

primaryStage.show();

public void stop()

System.out.println("Inside stop() method");

public static void main(String[] args) {

System.out.println("Lauching Java LifeCycle");


System.out.println("Hello World");

launch(args);

OUTPUT:
Lauching Java LifeCycle

Hello World

Inside init() method

Inside start() method

Inside stop() method

_____________________________________________________________________

DRAWING 2D SHAPES:
import javafx.application.Application;

import javafx.scene.Group;

import javafx.scene.Scene;

import javafx.scene.paint.Color;

import javafx.scene.shape.Circle;

import javafx.scene.shape.Line;

import javafx.scene.shape.Polygon;

import javafx.scene.shape.Rectangle;

import javafx.stage.Stage;

public class DrawingShapes extends Application {

@Override

public void start(Stage primaryStage) {

Line l = new Line();

l.setStartX(0);
l.setStartY(10);

l.setEndX(100);

l.setEndY(10);

l.setStrokeWidth(10);

Circle c = new Circle();

c.setCenterX(50);

c.setCenterY(50);

c.setRadius(25);

c.setFill(Color.AQUA);

Rectangle r = new Rectangle();

r.setWidth(30);

r.setHeight(30);

r.setStrokeWidth(10);

r.setFill(Color.AQUA);

Polygon p = new Polygon();

p.getPoints().addAll(new Double[] {300.0,150.0,470.0,260.0,300.0,150.0,150.0,150.0});

p.setFill(Color.AQUA);

Group root = new Group();

root.getChildren().addAll(l,c,r,p);

Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle("2D Shapes");
primaryStage.setScene(scene);

primaryStage.show();

public static void main(String[] args) {

launch(args);

_____________________________________________________________________

SMILEY ON CANVAS:
import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.canvas.Canvas;

import javafx.scene.canvas.GraphicsContext;

import javafx.scene.layout.StackPane;

import javafx.scene.shape.ArcType;

import javafx.stage.Stage;

public class SmileyCanvas extends Application {

@Override

public void start(Stage primaryStage) {

Canvas c = new Canvas(400,350);

GraphicsContext gc = c.getGraphicsContext2D();

gc.strokeOval(100, 50, 200, 200);

gc.fillOval(155, 100, 10, 20);

gc.fillOval(230, 100, 10, 20);

gc.fillRect(190, 160, 10, 10);


gc.fillArc(160, 150, 80, 60, 180, 180, ArcType.OPEN);

StackPane root = new StackPane();

root.getChildren().add(c);

Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle("Hello World!");

primaryStage.setScene(scene);

primaryStage.show();

public static void main(String[] args) {

launch(args);

_____________________________________________________________________

LOGIN PAGE CREATION WITH CSS:


import javafx.application.Application;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.Label;

import javafx.scene.control.PasswordField;

import javafx.scene.control.TextField;

import javafx.scene.layout.GridPane;

import javafx.scene.layout.HBox;

import javafx.stage.Stage;

public class LoginPage extends Application {


@Override

public void start(Stage primaryStage) {

GridPane root = new GridPane();

Label l1 = new Label("UserName");

root.add(l1, 0, 0);

TextField t1 = new TextField();

root.add(t1, 1, 0);

Label l2 = new Label("Password");

root.add(l2, 0, 1);

PasswordField pf = new PasswordField();

root.add(pf,1,1);

Button b = new Button("Login");

HBox hb = new HBox(10);

hb.setAlignment(Pos.CENTER);

hb.getChildren().add(b);

root.add(hb,1,4);

root.setStyle("-fx-background-color:linear-gradient(orange,white);");

Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle("Hello World!");

primaryStage.setScene(scene);

primaryStage.show();

public static void main(String[] args) {

launch(args);

}
}

_____________________________________________________________________

BOUNCING A BALL:
import javafx.animation.TranslateTransition;

import javafx.application.Application;

import javafx.event.EventHandler;

import javafx.scene.Group;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.input.MouseEvent;

import javafx.scene.paint.Color;

import javafx.scene.shape.Circle;

import javafx.stage.Stage;

public class BouncingBall extends Application {

@Override

public void start(Stage primaryStage) {

Circle c = new Circle();

c.setCenterX(50);

c.setCenterY(50);

c.setRadius(25);

c.setFill(Color.BLANCHEDALMOND);

Button b1 = new Button("Play");

b1.setTranslateX(125);

b1.setTranslateY(200);

Button b2 = new Button("Pause");


b2.setTranslateX(175);

b2.setTranslateY(200);

TranslateTransition tt = new TranslateTransition();

tt.setAutoReverse(true);

tt.setByX(100);

tt.setCycleCount(100);

tt.setNode(c);

EventHandler<MouseEvent> handler = new EventHandler<MouseEvent>(){

@Override

public void handle(MouseEvent event)

if(event.getSource()== b1)

tt.play();

else if(event.getSource()== b2)

tt.pause();

else if(event.getSource()== b1)

c.setFill(Color.BROWN);

else if(event.getSource()== b2)

{
c.setFill(Color.BLACK);

};

b1.setOnMouseClicked(handler);

b2.setOnMouseClicked(handler);

Group root = new Group();

root.getChildren().addAll(c,b1,b2);

Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle("Bouncing a ball");

primaryStage.setScene(scene);

primaryStage.show();

public static void main(String[] args) {

launch(args);

_____________________________________________________________________

TAX CALCULATOR:
import javafx.application.Application;

import javafx.event.*;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.control.*;

import javafx.scene.layout.*;
import javafx.stage.Stage;

public class TaxCalculator extends Application {

@Override

public void start(Stage primaryStage) {

Label l1 = new Label("Income");

Label l2 = new Label("%Tax");

Label response = new Label();

TextField t1 = new TextField();

TextField t2 = new TextField();

Button b = new Button("Calculate");

b.setOnAction(new EventHandler<ActionEvent>(){

@Override

public void handle(ActionEvent event) {

double income = Double.parseDouble(t1.getText());

double tax = Double.parseDouble(t2.getText());

double cal = (tax/100)*income;

response.setText("Tax is" +cal);

});

VBox root = new VBox();

FlowPane f1 = new FlowPane();

FlowPane f2 = new FlowPane();

root.getChildren().addAll();
f1.setAlignment(Pos.CENTER);

f2.setAlignment(Pos.CENTER);

root.setAlignment(Pos.CENTER);

f1.getChildren().addAll(l1,t1);

f2.getChildren().addAll(l2,t2);

root.getChildren().addAll(f1,f2,b,response);

Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle("Tax Calculator");

primaryStage.setScene(scene);

primaryStage.show();

public static void main(String[] args) {

launch(args);

_____________________________________________________________________

REGISTRATION PAGE WITH CSS AND JDBC:

You might also like