In: Computer Science
You will be asked to implement a JavaFX program to demonstrate skills and knowledge covering the following:
• implementing EventHandlers and ChangeListeners for UI controls incl. ListViews
• JFoenix
Just need some examples in Java
Exception Handling Java
public class JavaExceptionExample{
public static void main(String args[]){
try{
int data=100/0;
}
catch(ArithmeticException e){System.out.println(e);
System.out.println("rest of the code...");
}
Implementing change listener in Javafx
import
java.awt.BorderLayout;
import
java.awt.Container;
import
java.awt.event.ActionEvent;
import
java.awt.event.ActionListener;
import
javax.swing.AbstractButton;
import
javax.swing.ButtonModel;
import
javax.swing.JButton;
import
javax.swing.JFrame;
import
javax.swing.event.ChangeEvent;
import
javax.swing.event.ChangeListener;
public
class
StateListener
{
public
static
void
main(String args[])
{
JFrame jFrame =
new
JFrame(
""
);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button =
new
JButton(
"Press
Me"
);
ActionListener actionListner
=
new
ActionListener() {
@Override
public
void
actionPerformed(ActionEvent event) {
AbstractButton
absButton = (AbstractButton) event.getSource();
boolean
selected = absButton.getModel().isSelected();
System.out.println(
"Selected="
+ selected +
"n"
);
}
};
ChangeListener changeListner
=
new
ChangeListener() {
@Override
public
void
stateChanged(ChangeEvent event) {
AbstractButton
aButton = (AbstractButton) event.getSource();
ButtonModel aModel =
aButton.getModel();
boolean
armed = aModel.isArmed();
boolean
pressed = aModel.isPressed();
boolean
selected = aModel.isSelected();
System.out.println(
"Armed
:"
+ armed +
" - Pressed :"
+ pressed +
" - Selected :"
+
selected);
}
};
button.addActionListener(actionListner);
button.addChangeListener(changeListner);
Container cPane =
jFrame.getContentPane();
cPane.add(button,
BorderLayout.CENTER);
jFrame.setSize(
800
,
500
);
jFrame.setVisible(
true
);
}
}
Implementing JFoenix
public void start(final Stage stage) throws Exception { StackPane pane = new StackPane(); JFXSpinner root = new JFXSpinner(); pane.getChildren().add(root); final Scene scene = new Scene(pane, 300, 300); scene.getStylesheets().add(MainDemo.class.getResource("/css/jfoenix-components.css").toExternalForm()); stage.setScene(scene); stage.setTitle("JFX Spinner Demo"); stage.show(); }