package HandleEvent; import javafx.application.Application; import javafx.event.
ID: 2247200 • Letter: P
Question
package HandleEvent;
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.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.stage.Stage; import javafx.scene.text.Text; public class HandleEvent extends Application { public static void main(String[] args) { launch(args); } private ImageView imageview; @Override public void start(Stage primaryStage) { GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(20); grid.setVgap(20); imageview=new ImageView(); imageview.setFitHeight(50); imageview.setFitWidth(100); Image img=new Image("https://s3.amazonaws.com/core-products-s3/90349557-f83b-4af1-a134-ef1b43293823.png?response-content-type=image%2Fpng&response-content-disposition=inline%3B%20filename%3D%22login_button.png%22%3B%20filename%2A%3DUTF-8%27%27login_button.png&X-Amz-Content-Sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJEJX3SFQYQNRCXMQ%2F20170825%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20170825T222800Z&X-Amz-SignedHeaders=Host&X-Amz-Expires=604800&X-Amz-Signature=01082d4eb695d6d7c2ec7fbdf7dfe3adea685708cc5f76508b00fa7dd0862617"); imageview.setImage(img); grid.add(imageview, 1, 1); Label orderNumberLbl = new Label("Order Number"); grid.add(orderNumberLbl, 0, 2); TextField userNameTextField = new TextField(); grid.add(userNameTextField, 1, 2); Label quanLbl = new Label("Quantity"); grid.add(quanLbl, 0, 3); TextField placeOrderTextField = new TextField(); grid.add(placeOrderTextField, 1, 3); Button btnPlaceOrder = new Button("Place Order"); HBox orderBox = new HBox(10); orderBox.getChildren().add(btnPlaceOrder); grid.add(orderBox, 1, 5); final Text messageTxt = new Text(); grid.add(messageTxt, 1, 6); btnPlaceOrder.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { messageTxt.setText("Order Placed Successfully!!!"); } }); Scene scene = new Scene(grid, 500, 300); primaryStage.setScene(scene); primaryStage.show(); } }
Design and implement at least 2 EventHandlers and then integrate with their previous implementation of the java GUI. Must design and implement the EventHandlers corresponding to their own GUI interface design.
1. Please test your handlers to call/invoke your GUI implementations. Also please enhance your implementation so that your handlers can run multiple processing steps instead of a simple String return.
2. One of the handlers should be associated with a button to retrieve/save customer info. When the button is clicked multiple times, multiple users/customers' information can be saved. And they can be retrieved later accordingly.
2a. (optional) You may implement a mouse/key handler as the 2nd handler.
3. You can implement the 2nd handler to respond to other GUI components (if you choose NOT to implement the optional requirement #2.)
4. Try a variety of handler styles/structure. One handler must use the shorthand lamda notation format. The other(s) should use a different format of your choice (e.g., in a full handler class, as an anonymous inner class, and so on).
5. Your codes will be judged on functionality and variety of implementations as well as the integration with your previous GUI.
Explanation / Answer
package project.server;
import javax.ejb.*;
import java.rmi.*;
import java.sql.*;
public interface Catalog extends EJBObject
{
public ResultSet getProducts() throws RemoteException;
}
package project.server;
import javax.ejb.*;
import java.rmi.*;
import java.sql.*;
public class CatalogBean implements SessionBean
{
SessionContext context;
public void ejbCreate() throws CreateException
{
System.out.println(" in the create of CatalogBean ");
}
public ResultSet getProducts()
{
ResultSet res=null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:ejb","scott","tiger");
Statement stmt=con.createStatement();
res=stmt.executeQuery("select * from product");
}
catch(Exception e)
{
System.out.println(" an error while executing the business mehtod of catalog bean");
e.printStackTrace();
}
return res;
}
public void setSessionContext(SessionContext ctx)
{
context=ctx;
}
public void ejbActivate()
{
System.out.println(" in the catalog bean's Activate");
}
public void ejbPassivate()
{
System.out.println(" in the catalog bean's passivate");
}
public void ejbRemove()
{
System.out.println(" in the catalog bean's remove");
}
}
package project.server;
import javax.ejb.*;
import java.rmi.*;
public class IProductBean implements EntityBean
{
EntityContext context;
public String pid,pname,capacity,um,producer;
public int pprice;
public void setEntityContext (EntityContext con)
{
context=con;
}
public void unsetEntityContext ()
{
context=null;
}
public String ejbCreate(String pid,String pname,int pprice,String capacity,String UM,String producer) throws CreateException
{
System.out.println(" in ejb create of the iproduct ");
return null;
}
public void ejbRemove()
{
System.out.println(" in the ejb remove of the iproduct ");
}
public void ejbLoad()
{
System.out.println(" in the ejb load of the iproduct ");
}
public void ejbStore()
{
System.out.println(" in the ejb store of the iproduct ");
}
public void ejbActivate()
{
System.out.println(" in the ejb activate of the iproduct ");
}
public void ejbPassivate()
{
System.out.println(" in the ejb passivate of the iproduct ");
}
public void ejbPostCreate(String pid,String pname,int pprice,String capacity,String UM,String producer)
{
System.out.println(" in the ejb post create of the iproduct ");
}
public String getID()
{
return pid;
}
public String getName()
{
return pname;
}
public int getPrice()
{
return pprice;
}
public String getCapacity()
{
return capacity;
}
public String getUM()
{
return um;
}
public String getProducer()
{
return producer;
}
}
package project.server;
import javax.ejb.*;
import java.rmi.*;
public interface IProductHome extends EJBHome
{
public IProduct create(String pid,String pname,int pprice,String capacity,String UM,String producer) throws RemoteException,CreateException;
public IProduct findByPrimaryKey(String pid) throws RemoteException,FinderException;
//public java.util.Enumeration findNullId() throws RemoteException,FinderException;
}
package project.server;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.util.*;
import javax.ejb.CreateException;
public class QuotationBean implements SessionBean
{
public Hashtable products;
private SessionContext context;
public void addProduct(String spid,int price,String pname) throws NameAlreadyExistException
{ Object pid=(Object)spid;
String nampri;
nampri=pname+":"+String.valueOf(price);
System.out.println(" in the addition of the product - "+pid +" having"+nampri);
if(products.containsKey(pid))
{
throw new NameAlreadyExistException("produt you want to buy is Already in quotation ");
}
else
{
products.put(pid,(Object)nampri);
System.out.println(" added the item to the quotation < -- > no of products are"+products.size());
}
}
public void removeProduct(String pid) throws NameNotFoundException
{
Object flag=null;
flag=products.remove((Object)pid);
if(flag==null)
{
throw new NameNotFoundException("Name of the product Not Found");
}
}
public Hashtable getAllProducts()
{
return products;
}
public void ejbCreate() throws CreateException
{
products=new Hashtable();
}
public void setSessionContext(SessionContext sc)
{
context=sc;
}
public void ejbActivate()
{
System.out.println("in ejb activate of the quotation.....");
}
public void ejbPassivate()
{
System.out.println("in ejb passivate of the quotation....");
}
public void ejbRemove()
{
System.out.println("in ejb remove of the quotation.....");
}
} // class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.