In: Computer Science
implement a JavaFX program to demonstrate skills and knowledge using the following:
1.General Java programming skills (e.g. conditionals, branching and loops) as well as object-oriented concepts)
2. Writing JavaFX applications incl. using fxml
3. • GUI Layouts (organizing UI controls)
I just need some samples and explanations.
1.General Java programming skills (e.g. conditionals, branching and loops) as well as object-oriented concepts)
Conditional example:
public class MyClass {
public static void main(String[] args) {
if (20 > 18) {
System.out.println("20 is greater than 18"); // obviously
}
else {
System.out.println("20 is smaller than 18");
}
}
Loop example:
public class MyClass {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
}
}
OOPS concept - I'm taking one example of encapsulation (which binds the data and object together in a single capsule so as to reduce the complexity of the code)
public class MyClass {
public static void main(String[] args) {
Person myObj = new Person();
myObj.name = "John";
System.out.println(myObj.name);
}
}
2. Writing JavaFX applications incl. using fxml:
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("fxml_example.fxml"));
Scene scene = new Scene(root, 300, 275);
stage.setTitle("FXML Welcome");
stage.setScene(scene);
stage.show();
}
3. • GUI Layouts (organizing UI controls):
/*
* A Java swing FlowLayout example
*/
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.FlowLayout;
public class FlowLayoutExample {
public static void main(String[] args) {
// Create and set up a frame window
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Layout");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Define new buttons
JButton jb1 = new JButton("Button 1");
JButton jb2 = new JButton("Button 2");
JButton jb3 = new JButton("Button 3");
// Define the panel to hold the buttons
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(jb1);
panel.add(jb2);
panel.add(jb3);
// Set the window to be visible as the default to be false
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}
These were some of the examples of JAVA concepts. Java is an OOP language and most of the product based companies are looking for the candidates who have a strong base in java. So if you have any doubts or need any suggestion regarding how to learn java etc, feel free to ask. I'll guide you.
And if my answer suffice your requirements, then kindly upvote.
Happy Learning