Thursday, April 7, 2016

EVENT HANDLING OF MULTIPLE FIELDS IN JAVAFX WINDOWS APPLICATION



EVENT HANDLING OF MULTIPLE FIELDS IN JAVAFX 


import javax.swing.JOptionPane;
import javafx.event.EventHandler;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;


public class EventController 
{
private MouseHandler mh;
private HomeView homeview;
private MainView mv;
Public EventController(HomeView homeview,MainView main)
{
this.homeview=homeview;
mh = new MouseHandler();
this.mv=main;
this.addMouseListener(mh);
}
private void mouseHandler(MouseEvent handle
{
Object obj = handle.getSource();
if (obj == null) {
return;
}
if (handle.getEventType() == MouseEvent.MOUSE_CLICKED) {
if (handle.getButton() == MouseButton.PRIMARY) {
if (obj.equals(homeview.getCalc())) 
{
                  JOptionPane.showMessageDialog(null,"Triggered 1");
} else if (obj.equals(homeview.getRegis())) {
 JOptionPane.showMessageDialog(null,"Triggered 2");
 mv.getmainborder().setCenter(null);
 mv.getmainborder().setCenter(new RegisterView());

}
}
}
 class MouseHandler implements EventHandler<MouseEvent> {
public void handle(MouseEvent me) {
mouseHandler(me);
}
}
private void addMouseListener(EventHandler<MouseEvent> eh) {

homeview.getCalc().addEventHandler(MouseEvent.MOUSE_CLICKED, eh);
homeview.getRegis().addEventHandler(MouseEvent.MOUSE_CLICKED, eh);
}

}



No comments:

Post a Comment