0% found this document useful (0 votes)
46 views45 pages

Java Programming: Lab Assessment - 5

This document contains code snippets and outputs from Java programming lab assessments. It discusses three activities - Activity 7, 8 and 9 involving multithreading concepts like threads, synchronization. Activity 7 creates two threads - OddThread and EvenThread that print odd and even numbers respectively using synchronization. Activity 8 deletes an item from array, updates corresponding value in another array and displays item details using threads and synchronization. Activity 9 implements producer-consumer problem using threads where one thread adds items to a list and other thread removes items from list.

Uploaded by

Varanasi Mounika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views45 pages

Java Programming: Lab Assessment - 5

This document contains code snippets and outputs from Java programming lab assessments. It discusses three activities - Activity 7, 8 and 9 involving multithreading concepts like threads, synchronization. Activity 7 creates two threads - OddThread and EvenThread that print odd and even numbers respectively using synchronization. Activity 8 deletes an item from array, updates corresponding value in another array and displays item details using threads and synchronization. Activity 9 implements producer-consumer problem using threads where one thread adds items to a list and other thread removes items from list.

Uploaded by

Varanasi Mounika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

JAVA PROGRAMMING

LAB ASSESSMENT – 5
Name: Mounika
Reg No.: 20BCE2963
Slot: L31+L32
Faculty: Prof. Jabanjalin Hilda J
Date: 18/04/2022
ACTIVITY – 7
Q1)
Code:
package act7q1;
class OddThread extends Thread{
int limit;
sharedPrinter printer;
public OddThread(int limit,sharedPrinter printer){
this.limit=limit;
this.printer=printer;
}
public void run(){
int oddnumber=1;
while(oddnumber<=limit){
printer.printOdd(oddnumber);
oddnumber=oddnumber+2;
}
}
}
class EvenThread extends Thread{
int limit;
sharedPrinter printer;
public EvenThread(int limit,sharedPrinter printer){
this.limit=limit;
this.printer=printer;
}
public void run(){
int evenNumber=2;
while(evenNumber<=limit){
printer.printEven(evenNumber);
evenNumber =evenNumber+2;
}
}
}
class sharedPrinter{
boolean isOddPrinted = false;
synchronized void printOdd(int number){
while(isOddPrinted){
try{
wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
}
System.out.println(Thread.currentThread().getName()+":"+number);
isOddPrinted=true;
try{
Thread.sleep(1000);
}
catch(InterruptedException e){
e.printStackTrace();
}
notify();
}
synchronized void printEven(int number){
while(!isOddPrinted)
{
try{
wait();
}
catch (InterruptedException e){
e.printStackTrace();
}
}
System.out.println(Thread.currentThread().getName()+":"+number);
isOddPrinted=false;
try{
Thread.sleep(1000);
}
catch(InterruptedException e){
e.printStackTrace();
}
notify();
}
}
public class Act7q1 {
public static void main(String args[]){
sharedPrinter printer = new sharedPrinter();
OddThread oddThread = new OddThread(10, printer);
oddThread.setName("Odd-Thread");
EvenThread evenThread = new EvenThread(10, printer);
evenThread.setName("Even-Thread");
oddThread.start();
evenThread.start();
System.out.println("Mounika 20BCE2963");
}
}
Output:

ACTIVITY – 8
Q1)
Code:
package act8q1;
class items{
int array[] = {15,5,6,30,10};
String array2[] = {"Pen","Pencil","Eraser","Sketch","Paper"};
int temp=-1;
synchronized void delete(String n) throws InterruptedException{
for (int i = 0; i < 5; i++) {
if(array2[i].compareTo(n)==0){
temp=i;
}
}
System.out.println(array2[temp]+" Deleted.");
array2[temp]="";
notify();
}
synchronized void delete2() throws InterruptedException{
if(temp==-1)
try {
wait();
} catch (Exception e) {
}
array[temp]=-1;
notify();
}
synchronized void disp(String n) throws InterruptedException{
for (int i = 0; i < 5; i++) {
if(array2[i].compareTo(n)==0){
temp=i;
}
}
System.out.println(array2[temp]+" "+array[temp]);
}
}
public class Act8q1 {
public static void main(String[] args) {
System.out.println("20BCE2963 Mounika\n");
items t = new items();
Thread t1 = new Thread(new Runnable(){
public void run() {
try {
t.delete("Pen");
} catch (InterruptedException ex) {}
}
});
Thread t2 = new Thread(new Runnable(){
public void run() {
try {
t.delete2();
} catch (InterruptedException ex) {}
}
});
Thread t3 = new Thread(new Runnable(){
public void run() {
try {
t.disp("Paper");
} catch (InterruptedException ex) {}
}
});
t1.start();
t2.start();
t3.start();
}
}
Output:

Q2)
Code:
package act8q2;
class registration
{
String bus_name;
public int seats;
registration(String a,int b)
{
bus_name=a;
seats=b;
}
public synchronized void registr_seat() throws InterruptedException
{
if (seats==0)
{
System.out.println("waiting...");
wait();
}
System.out.println("registering the seat");
seats=seats-1;

}
public synchronized void allot_seats(int m)
{
System.out.println("Alloting 60 seats");
this.seats=this.seats+m;
System.out.println("Notifying seats");
notify();
}
void print_seats()
{
System.out.println("Remaing Seats : " +seats);
}
}
public class Act8Q2 {
public static void main(String[] args) throws InterruptedException {
System.out.println("20BCE2963 Mounika\n");
registration r= new registration("red bus",0);
Thread t1 = new Thread(()->{
try {
r.registr_seat();
} catch (InterruptedException ex) {
}
});
Thread t2 = new Thread(()->{
try {
r.registr_seat();
} catch (InterruptedException ex) {

}
});
Thread t3 = new Thread(()->{
r.allot_seats(60);
});
Thread t4 = new Thread(()->{
r.print_seats();
});
t1.start();
t2.start();
t3.start();
t1.join();
t2.join();
t3.join();
t4.start();
t4.join();

}
}
Output:

Q3)
Code:
package act8q31;

import java.util.LinkedList;
public class BakeryShop {
LinkedList<Integer> list = new LinkedList<>();
int capacity = 10;
public void produce() throws InterruptedException {
int value = 0;
while (true) {
synchronized (this) {
while (list.size() == capacity) {
wait();
}
System.out.println("Cake Baked:" + value);
list.add(value++);
notify();
Thread.sleep(1000);
}
}
}
public void consume() throws InterruptedException {
while (true) {
synchronized (this) {
while (list.isEmpty())
wait();
}
int val = list.removeFirst();
System.out.println("Customer Bought Cake:" + val);
notify();
Thread.sleep(1000);
}
}
}
class Main {
public static void main(String[] args) {
System.out.println("20BCE2963");
final BakeryShop bs = new BakeryShop();
Thread t1 = new Thread(new Runnable() {
public void run() {
try {
bs.produce();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
try {
bs.consume();
} catch (InterruptedException e) {
}
}
});
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Output:
Activity – 9
Files:
Q1)
Code:
package act9q11;
import java.io.*;
public class Act9q11 {
public static void main(String[] args) {
System.out.println("20BCE2963");
try {
FileOutputStream fos=new FileOutputStream("Test.txt");
String s="Mounika Varanasi";
byte b[]=s.getBytes();
fos.write(b);
fos.close();
System.out.println("Success!");
}catch(Exception e) {System.out.println(e);}
try {
FileInputStream fis=new FileInputStream("Test.txt");
StringBuffer sb=new StringBuffer();
int i=0;
while((i=fis.read())!=-1){
sb.append((char)i);
}
sb.reverse();
System.out.println("Reversed content: "+sb);
fis.close();
}catch(Exception e) {System.out.println(e);}
}
}
Output:

Q2)
Code:
package act9q12;
import java.io.*;
public class Act9q12 {
public static void main(String[] args) {
System.out.println("20BCE2963");
try {
FileWriter fw=new FileWriter("Test.txt");
String s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
fw.write(s);
fw.close();
System.out.println("English alphabets(A-Z) written to file");
}catch(Exception e) {System.out.println(e);}
try {
FileReader fr=new FileReader("Test.txt");
int i;
System.out.print("Reading file: ");
while((i=fr.read())!=-1){
System.out.print((char)i);
}
fr.close();
}catch(Exception e) {System.out.println(e);}
}
}
}
}
Output:

Files and Multithreading:


Q1)
package act9q1;
import java.util.Scanner;
public class Act9q1 {
public static void main(String[] args) {
int i,count;
System.out.print("Enter n value : ");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
System.out.println("Prime numbers between 1 to "+n+" are ");
for(int j=2;j<=n;j++)
{
count=0;
for(i=1;i<=j;i++)
{
if(j%i==0)
{
count++;
}
}
if(count==2)
System.out.print(j+" ");
}
int i,count;
System.out.print("Enter n value : ");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
System.out.println("Prime numbers between 1 to "+n+" are ");
for(int j=2;j<=n;j++)
{
count=0;
for(i=101;i<=j;i++)
{
if(j%i==0)
{
count++;
}
}
if(count==2)
System.out.print(j+" ");
}
}
}
Output:

Q2)
Code:
package act9q2;
import java.io.*;
class StopWord{
String file1="D:\\jv prac\\class question\\src\\file1.txt";
String file2="D:\\jv prac\\class question\\src\\file2.txt";

void allstop(String t) {
try(BufferedReader b=new BufferedReader(new
FileReader(file1))){
String s;
int count=0;
while((s=b.readLine())!=null) {
String words[] = s.split(" ");
//System.out.println(s); //to print the lines
for(String i:words) {
//System.out.println(i); //print the words
if(i.equals("a") || i.equals("and") ||
i.equals("the")) {
count+=1;
}
}
}
System.out.println("[+] There are ["+count+"] stop words
{'a','and','the'} in the file. says "+t);
}
catch(FileNotFoundException e) { //Exception
System.out.println(e);
}
catch(IOException e) {
System.out.println(e);
}

}
void allexceptstop(String t){
try(BufferedReader b=new BufferedReader(new
FileReader(file2))){
String s;
int counth=0;
int count=0;
while((s=b.readLine())!=null) {
String words[] = s.split(" "); x
for(String i:words)
if(i.equals("a") || i.equals("and") ||
i.equals("the")) {
}
else if(i.startsWith("h") || i.startsWith("H")) {
counth+=1;
count+=1;
}
else{
count+=1;
}
}
}
System.out.println("[+] There are ["+count+"] words except
stop words {'a','and','the'} in the file, with ["+counth+"] words starting with
'h/H'. says "+t);
}
catch(FileNotFoundException e) { //Exception
System.out.println(e);
e.printStackTrace();
}
catch(IOException e) {
System.out.println(e);
e.printStackTrace();
}
}

void thankyou(String t) {
System.out.println("[+] Thankyou for using the service. says"+t);
}
}
public class Act9q2 {
public static void main(String[] args) throws InterruptedException {
System.out.println("*************** 20BCE2963 - Mounika
****************");
StopWord sw=new StopWord();

Thread t1;
t1 = new Thread() {
@Override
public void run() {
try {
sw.allstop("t1");
} catch (Exception e) {
}
}
};
Thread t2=new Thread() {
@Override
public void run() {
try {
sw.allexceptstop("t2");
} catch (Exception e) {
}
}
};
Thread t3=new Thread() {
@Override
public void run() {
try {
sw.thankyou("t3");
} catch (Exception e) {
}
}
};
t1.setPriority(3);
t2.setPriority(2);
t3.setPriority(1);
t1.start();
t2.start();
t1.join(); //waiting for both t1, t2 to finish
t2.join();
t3.start();
}
}
Output:

ACTIVITY – 10
Q1)
Code:
package act10q1;
import java.util.Arrays;
interface ArraySort {
void apply(String[] arr);
}
public class Act10q1 {
public static final ArraySort sort1 = arr -> {
int n = arr.length;
for (int i = 1; i < n; i++) {
String temp = arr[i];
int j = i - 1;
while (j >= 0 && temp.length() < arr[j].length()) {
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = temp;
}
System.out.print("Strings sorted in ascending order based on their lengths: ");
for (int i = 0; i < n; i++)
System.out.print(arr[i] + " ");
System.out.print("\n");
System.out.print("\n");
};
public static final ArraySort sort2 = arr -> {
int n = arr.length;
for (int i = 1; i < n; i++) {
String temp = arr[i];
int j = i - 1;
while (j >= 0 && temp.length() > arr[j].length()) {
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = temp;
}
System.out.print("Strings sorted in descending order based on their lengths: ");
for (int i = 0; i < n; i++)
System.out.print(arr[i] + " ");
System.out.print("\n");
System.out.print("\n");
};
public static final ArraySort fsort = arr -> {
Arrays.sort(arr, (str1, str2) -> str1.charAt(0) -
str2.charAt(0));
Arrays.asList(arr).forEach(System.out::println);
};
public static final ArraySort esort = arr -> {
int n = arr.length;
String arr1[] = new String[arr.length];
int j = 0;
for (int i = 0; i < n; i++) {
int k = arr[i].indexOf('e');
if (k != -1) {
arr1[j] = arr[i];
j++;
}
}
for (int i = 0; i < n; i++) {
int k = arr[i].indexOf('e');
if (k == -1) {
arr1[j] = arr[i];
j++;
}
}
System.out.print("Strings sorted in ascending order based on who contains 'e'
first: ");
for (int i = 0; i < n; i++)
System.out.print(arr1[i] + " ");
System.out.print("\n");
System.out.print("\n");
};
public static void main(String[] args) {
String[] str =
{"devjyoti","karan","devraj","rahi","ram","anshula"};
sort1.apply(str);
sort2.apply(str);
System.out.println("Strings sorted based on the first alphabet only: ");
fsort.apply(str);
esort.apply(str);
}
}
Output:

Q2)
Code:
package act10q2;
import java.util.Scanner;
interface Capital {
void apply(String arr);
}
public class Act10q2 {
public static final Capital printCapitalized = arr -> {
int n = arr.length();
char c = Character.toUpperCase(arr.charAt(0));
System.out.print(c + "");
for (int i = 1; i < n; i++) {
if (arr.charAt(i) == ' ') {
i++;
c = Character.toUpperCase(arr.charAt(i));
System.out.print(" " + c + "");
} else {
c = arr.charAt(i);
System.out.print(c + "");
}
}
System.out.print("\n");
};
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str = input.nextLine();
printCapitalized.apply(str);
}

}
Output:
Q3)
Code:
package act10q3;
import java.util.*;
class books{
String name, author, type;
float price;
void input20BCE2963()
{
System.out.println("Enter Book Name: ");
Scanner input=new Scanner(System.in);
name=input.next();
System.out.println("Enter Author: ");
author=input.next();
System.out.println("Enter Book Type: ");
type=input.next();
System.out.println("Enter Price: ");
price=input.nextInt();
}
void display20BCE2963()
{
System.out.println("Book Name: "+name);
System.out.println("Author: "+author);
System.out.println("Book Type: "+type);
System.out.println("Price: "+price);
}
}
public class Act10q3 {
public static void main(String[] args) throws InputMismatchException{
List<books> fiction=new ArrayList<books>();
List<books> comic=new ArrayList<books>();
List<books> cooking=new ArrayList<books>();
books b1=new books(),b2=new books(),b3=new books(),b4=new
books(),b5=new books();
b1.input20BCE2963();
b2.input20BCE2963();
b3.input20BCE2963();
b4.input20BCE2963();
b5.input20BCE2963();
if(b1.type=="fiction")
fiction.add(b1);
else if(b1.type=="comic")
comic.add(b1);
else
cooking.add(b1);
if(b2.type=="fiction")
fiction.add(b2);
else if(b2.type=="comic")
comic.add(b2);
else
cooking.add(b2);
if(b3.type=="fiction")
fiction.add(b3);
else if(b3.type=="comic")
comic.add(b3);
else
cooking.add(b3);
if(b4.type=="fiction")
fiction.add(b4);
else if(b4.type=="comic")
comic.add(b4);
else
cooking.add(b4);
if(b5.type=="fiction")
fiction.add(b5);
else if(b5.type=="comic")
comic.add(b5);
else
cooking.add(b5);
System.out.println("Fiction Books:");
for(books b:fiction)
b.display20BCE2963();
System.out.println("Comics:");
for(books b:comic)
b.display20BCE2963();
System.out.println("Cooking Books:");
for(books b:cooking)
b.display20BCE2963();
}

}
Output:

Q4)
Code:
package act10q4;
import java.util.*;
public class Act10q4 {
public static void main(String[] args) {
Map<String, List<String>> h1=new HashMap<String, List<String>>();
Map<String, String>h2=new HashMap<String, String>();
Scanner scan=new Scanner(System.in);
System.out.print("ENTER TOTAL NUMBER OF STUDENTS: "); int
n=scan.nextInt(); scan.nextLine();
List<String> facultyList=new ArrayList<String>();
for(int i=0;i<n;i++)
{
System.out.println("NAME OF STUDENT: ");
String name=scan.nextLine();
System.out.print("TOTAL NUMBER OF COURSES TAKEN BY " +name+" :");
int t=scan.nextInt();
scan.nextLine();
List<String> list=new ArrayList<String>();
for(int j=0;j<t;j++)
{
System.out.print("COURSE"+(j+1)+" NAME : ");
String course=scan.nextLine();
if(!(h2.containsKey(course)))
{
System.out.print("FACULTY NAME FOR "+course +" : ");
String faculty=scan.nextLine();
h2.put(course, faculty);
}
list.add(course);
}
h1.put(name,list);
}
System.out.println(" STUDENT NAME"+ " COURSES REGISTERED");
for(Map.Entry<String, List<String>> entry:h1.entrySet())
{
System.out.println("| "+entry.getKey()+" | "+entry.getValue()+" | ");
}
System.out.println();
System.out.println(" COURSE NAME"+" FACULTY NAME");
for(Map.Entry<String, String> entry:h2.entrySet()){
System.out.println("| "+entry.getKey()+" | "+entry.getValue()+" | ");
}
System.out.println();
System.out.println("FACULTY DETAILS FOR EVERY STUDENT");
for(Map.Entry<String, List<String>> entry:h1.entrySet())
{
System.out.println("Faculties for "+entry.getKey()+" are:");
List<String> str=entry.getValue();
int len=str.size();
for(int i=0;i<len;i++)
{
String sub=str.get(i);
System.out.println(h2.get(sub));
}
System.out.println();
System.out.println("20BCE2963");
}
scan.close();
}
}
Output:

ACTIVITY – 11
Q1)
Code:
package act11q1;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;

public class Act11q1 extends Application {


public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
Button red = new Button("RED");
Button green = new Button("GREEN");
Button blue = new Button("BLUE");
Button pink = new Button("PINK");
Button black = new Button("BLACK");
Font font = Font.font("Courier New", FontWeight.BOLD, 20);
red.setFont(font);
green.setFont(font);
blue.setFont(font);
pink.setFont(font);
black.setFont(font);
Label l1 = new Label("Mounika\n20BCE2963");
l1.setFont(Font.font("Courier New", FontWeight.BOLD, 15));
red.setStyle("-fx-background-color: red");
green.setStyle("-fx-background-color: green");
blue.setStyle("-fx-background-color: blue");
pink.setStyle("-fx-background-color: pink");
black.setStyle("-fx-background-color: black");

red.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
System.out.println("RED was clicked");

}});
green.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
System.out.println("GREEN was clicked");

}});
blue.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
System.out.println("BLUE was clicked");

}});
pink.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
System.out.println("PINK was clicked");
}});
black.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
System.out.println("BLACK was clicked");

}});
GridPane gp = new GridPane();
gp.setVgap(5);
gp.setHgap(5);
gp.setAlignment(Pos.CENTER);
gp.add(red,2,0);
gp.add(green,2,1);
gp.add(blue,2,2);
gp.add(pink,2,3);
gp.add(black,2,4);
gp.add(l1,0,2);

Scene scene = new Scene(gp,600,600);


primaryStage.setScene(scene);
primaryStage.setTitle("Colors");
primaryStage.show();

}
}
Output:

Q2)
Code:
package act11q2;
import javafx.stage.Stage;
import java.time.LocalDate;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;

public class Act11q2 extends Application{


Scene booked, details;
TextField source,destination,passenger;
ToggleGroup group;
DatePicker date;
String src,des,pass,cls;
LocalDate dat;
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
Label l0=new Label("Aryan Chandrakar's Airline");

Label l1=new Label("Source: ");


l1.setMaxWidth(200);
source=new TextField();
source.setMaxHeight(20);

Label l2=new Label("Destination: ");


l2.setMaxWidth(200);
destination=new TextField();
destination.setMaxHeight(20);

Label l3=new Label("Date: ");


l3.setMaxWidth(200);
date = new DatePicker();

Label l4=new Label("# Passengers: ");


l4.setMaxWidth(200);
passenger=new TextField();
passenger.setMaxHeight(20);
Label l5=new Label("Class: ");
l5.setMaxWidth(200);
group = new ToggleGroup();
RadioButton button1 = new RadioButton("Business");
RadioButton button2 = new RadioButton("First");
RadioButton button3 = new RadioButton("Economy");
button1.setToggleGroup(group);
button2.setToggleGroup(group);
button3.setToggleGroup(group);

Button book = new Button("BOOK TICKET!"); // button

Font font = Font.font("Courier New", FontWeight.BOLD, 20);


l0.setFont(font);
l1.setFont(font);
l2.setFont(font);
l3.setFont(font);
l4.setFont(font);
l5.setFont(font);
source.setFont(font);
destination.setFont(font);
passenger.setFont(font);
button1.setFont(font);
button2.setFont(font);
button3.setFont(font);
book.setFont(font);

GridPane gp1=new GridPane();


gp1.setVgap(5);
gp1.setHgap(5);
gp1.setAlignment(Pos.CENTER);
gp1.add(l0, 1, 0);
gp1.add(l1, 0, 1);
gp1.add(source, 2, 1);
gp1.add(l2, 0, 2);
gp1.add(destination, 2, 2);
gp1.add(l3,0,3);
gp1.add(date, 2, 3);
gp1.add(l4, 0, 4);
gp1.add(passenger, 2, 4);
gp1.add(l5, 0, 5);
gp1.add(button1, 2, 5);
gp1.add(button2, 2, 6);
gp1.add(button3, 2, 7);
gp1.add(book, 1, 8);
details=new Scene(gp1,600,600);
book.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
// TODO Auto-generated method stub
src=source.getText();
des=destination.getText();
dat=date.getValue();
pass=passenger.getText();
RadioButton rb =
(RadioButton)group.getSelectedToggle();
cls=rb.getText();

Label q0=new Label("BOARDING PASS");


Label q1=new Label("Source: "+src);
Label q2=new Label("Destination: "+des);
Label q3=new Label("Date: "+dat);
Label q4=new Label("No. of Passenger: "+pass);
Label q5=new Label("Class: "+cls);
q0.setFont(font);
q1.setFont(font);
q2.setFont(font);
q3.setFont(font);
q4.setFont(font);
q5.setFont(font);
q0.setTextFill(Color.web("blue"));
q1.setStyle("-fx-border-style: dotted; -fx-border-color: black; -fx-
border-width: 1");
q2.setStyle("-fx-border-style: dotted; -fx-border-color: black; -fx-
border-width: 1");
q3.setStyle("-fx-border-style: dotted; -fx-border-color: black; -fx-
border-width: 1");
q4.setStyle("-fx-border-style: dotted; -fx-border-color: black; -fx-
border-width: 1");
q5.setStyle("-fx-border-style: dotted; -fx-border-color: black; -fx-
border-width: 1");

GridPane gp2=new GridPane();


booked=new Scene(gp2,600,600);
gp2.setVgap(5);
gp2.setHgap(5);
gp2.setAlignment(Pos.CENTER);
gp2.add(q0, 0, 0);
gp2.add(q1, 0, 1);
gp2.add(q2, 0, 2);
gp2.add(q3, 0, 3);
gp2.add(q4, 0, 4);
gp2.add(q5, 0, 5);
primaryStage.setScene(booked);
primaryStage.setTitle("Air Ticket");
primaryStage.show();
}
});
primaryStage.setScene(details);
primaryStage.setTitle("Air Ticket");
primaryStage.show();
}
}
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy