Question

In: Computer Science

i need code that uses javafx where the feauture are. 1. like with menubar that allows...

i need code that uses javafx where the feauture are.
1. like with menubar that allows to save and open file
2. when it has to save file it has own file type like for example s.suv
3. it should be able to open that file s.suv and lets add more icon into it

Solutions

Expert Solution

JAVAFX:

  • JavaFX is a set of graphics and media packages that enables developers to design, create, test, debug, and deploy rich client applications that operate consistently across diverse platforms.
  • JavaFX is a software platform for creating and delivering desktop applications, as well as rich Internet applications (RIAs) that can run across a wide variety of devices. JavaFX is intended to replace Swing as the standard GUI library for Java SE, but both will be included for the foreseeable future. JavaFX has support for desktop computers and web browsers on Microsoft Windows, Linux, and macOS. JavaFX is no longer bundled with the latest Java.
  • JavaFX Applications:

Written as a Java API, JavaFX application code can reference APIs from any Java library. For example, JavaFX applications can use Java API libraries to access native system capabilities and connect to server-based middleware applications.

How Do I Run a Sample Application?

The steps in this section explain how to download and run the sample applications that are available as a separate download with the Java Platform (JDK 7).

To download and run the sample applications:

  1. Go to the Java SE Downloads page .

  2. Scroll down to locate the JDK 7 and JavaFX Demos and Samples section.

  3. Click the Demos and Samples Download button to go to the downloads page.

  4. On the Java SE Development Kit 7 Downloads page, scroll down to the JavaFX Demos and Samples Downloads section.

  5. Download the zip file for the correct operating system and extract the files.

    The javafx-samples-2.2.x directory is created and contains the files for the available samples. The NetBeans projects for the samples are in the javafx-samples-2.2.x\src directory.

A menu bar is a horizontal bar that acts as a container for menus. An instance of the MenuBar class represents a menu bar. You can create a MenuBar using its default constructor:

Menu is a popup menu that contains several menu items that are displayed when the user clicks a menu. The user can select a menu item after which the menu goes into a hidden state

Constructor of the MenuBar class are:

  1. MenuBar(): creates a new empty menubar.
  2. MenuBar(Menu… m): creates a new menubar with the given set of menu.
  3. Using Menu Items:A MenuItem represents an actionable option. When it is clicked, the registered ActionEvent handlers are called.

Using a menu is a multistep process. The following sections describe the steps in detail. The following is the summary of steps:

  • 1. Create a menu bar and add it to a container.
  • 2. Create menus and add them to the menu bar.
  • 3. Create menu items and add them to the menus.
  • 4. Add ActionEvent handlers to the menu items to perform actions when they are clicked.
​
 

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
 
public class FxMenuExample extends Application
{
    // Create the Message Label
    Label messageLbl = new Label("Press any Menu Item to see the message");
     
    public static void main(String[] args)
    {
        Application.launch(args);
    }
 
    @Override
    public void start(Stage stage)
    {
        // Create some menus
        Menu openMenu = new Menu("open");
        Menu subMenu = new Menu("filename");
        MenuItem menuItem11 = new MenuItem("file1.suv");
        Menu saveMenu = new Menu("save");
          MenuItem menuItem2 = new MenuItem("file2");
          menu.getItems().add(menuItem2);
         
        // Create the MenuItem New
        MenuItem newItem = new MenuItem("New");
        newItem.setOnAction(new EventHandler<ActionEvent>() 
        {
            @Override public void handle(ActionEvent e) 
            {
                printMessage("You have pressed the New Menu Item");
            }
        });     
 
       // Add menu items to the File menu
        fileMenu.getItems().addAll(newItem, openItem);
 
        // Create the MenuItem Copy
        MenuItem copyItem = new MenuItem("Copy");
        copyItem.setOnAction(new EventHandler<ActionEvent>() 
        {
            @Override public void handle(ActionEvent e) 
            {
                printMessage("You have pressed the Copy Menu Item");
            }
        });     
 
        // Create the MenuItem Paste
        MenuItem pasteItem = new MenuItem("Paste");
        pasteItem.setOnAction(new EventHandler<ActionEvent>() 
        {
            @Override public void handle(ActionEvent e) 
            {
                printMessage("You have pressed the Paste Menu Item");
            }
        });     
 
        // Add menu items to the Edit menu
        editMenu.getItems().addAll(copyItem, pasteItem);
 
        // Create a menu bar
        MenuBar menuBar = new MenuBar();
        // Add menus to a menu bar
        menuBar.getMenus().addAll(fileMenu, editMenu);
         
        // Create the Menu Box
        HBox menu = new HBox();
        // Add the MenuBar to the Menu Box
        menu.getChildren().add(menuBar);
         
        // Create the VBox
        VBox root = new VBox();
        // Add the children to the VBox     
        root.getChildren().addAll(menu,messageLbl);
        // Set the Size of the VBox
        root.setMinSize(350, 250);
         
        /* 
         * Set the padding of the VBox
         * Set the border-style of the VBox
         * Set the border-width of the VBox
         * Set the border-insets of the VBox
         * Set the border-radius of the VBox
         * Set the border-color of the VBox
        */
        root.setStyle("-fx-padding: 10;" +
                "-fx-border-style: solid inside;" +
                "-fx-border-width: 2;" +
                "-fx-border-insets: 5;" +
                "-fx-border-radius: 5;" +
                "-fx-border-color: blue;");
         
        // Create the Scene
        Scene scene = new Scene(root);
        // Add the scene to the Stage
        stage.setScene(scene);
        // Set the title of the Stage
        stage.setTitle("A Menu Example");
        // Display the Stage
        stage.show();       
    }
 
    // Helper Method
    public void printMessage(String message)
    {
        // Set the Text of the Label
        messageLbl.setText(message);
    }
     
}

 

 

​

Related Solutions

i need a javafx code 1. first create menu bar with option open and save 2....
i need a javafx code 1. first create menu bar with option open and save 2. when user click on open it opens the file only image file 3. when user click on save it saves as new file.
I need code for the HCS12 Dragon trainer plus 2 that allows me to read values...
I need code for the HCS12 Dragon trainer plus 2 that allows me to read values from its built in temperature sensor and displays those values on the seven segment displays .
(This is for java) I need to rewrite this code that uses a while loop. public...
(This is for java) I need to rewrite this code that uses a while loop. public class Practice6 {      public static void main (String [] args) {         int sum = 2, i=2;        do { sum *= 6;    i++;    } while (i < 20); System.out.println("Total is: " + sum); }
I need a Verilog code that makes the LEDs on the FPGA board works like this....
I need a Verilog code that makes the LEDs on the FPGA board works like this. https://image.ibb.co/mu5tnS/6.gif There are 16 LEDs in the FPGA board
I need the output of the code like this in java First we create a new...
I need the output of the code like this in java First we create a new building and display the result: This building has no apartments. Press enter to continue......................... Now we add some apartments to the building and display the result: This building has the following apartments: Unit 1 3 Bedroom Rent $450 per month Currently unavailable Unit 2 2 Bedroom Rent $400 per month Currently available Unit 3 4 Bedroom Rent $1000 per month Currently unavailable Unit 4...
I need the code in python where I can encrypt and decrypt any plaintext. For example,...
I need the code in python where I can encrypt and decrypt any plaintext. For example, the plaintext "hello" from each of these Block Cipher modes of Operation. Electronic Code Block Mode (ECB) Cipher block Mode (CBC) Cipher Feedback Mode (CFB) Output feedback Mode (OFB) Counter Mode (CTR) Here is an example, Affine cipher expressed in C. Encryption: char cipher(unsigned char block, char key) { return (key+11*block) } Decryption: char invcipher(unsigned char block, char key) { return (163*(block-key+256)) }
Hi, I need the HTML5 code for the below. About Me **Would like to add a...
Hi, I need the HTML5 code for the below. About Me **Would like to add a image of a plane or something related to travel here. Mia Jo I am taking this class to earn my Computer programmer CL1. Things I Like to Do: Spend time with family Traveling People Watch Places I Want to Go or Have Visited: Dubai- December'18 Enjoyed shopping and the desert safari the most. Cuba- August '18 Enjoyed learning about the culture and history. China-...
I need couple paprgraph for a reaserch paper that Define Graphene and the uses, where it...
I need couple paprgraph for a reaserch paper that Define Graphene and the uses, where it comes from and the down side to it.
c# code working but output not right, I need to output all numbers like : Prime...
c# code working but output not right, I need to output all numbers like : Prime factors of 4 are: 2 x 2 here is just 2 Prime factors of 7 are: 7 Prime factors of 30 are: 2 x 3 x 5 Prime factors of 40 are: 2 x 2 x 2 x 5 here is just 2,5 Prime factors of 50 are: 2 x 5 x 5 here is just 2,5 1) How I can fix it 2)I...
I need to modify the following code (using Python3), where Groceries.csv is of following form (Item...
I need to modify the following code (using Python3), where Groceries.csv is of following form (Item on 1st column, price on 2nd) Stewing beef,15.45 Ground beef,11.29 Pork chops,11.72 Chicken,7.29 Bacon,7.12 Wieners,4.33 Canned salmon,5.68 Homogenized milk,5.79 Partly skimmed milk,5.20 Butter,4.99 Processed cheese slices,2.53 Evaporated milk,1.89 Eggs,3.11 Bread,2.74 Soda crackers,3.27 Macaroni,1.45 Flour,4.54 Corn flakes,5.72 Apples,4.71 Bananas,1.56 Oranges,3.70 ... a. In the function createPricesDict(), create a dictionary of each product mapped to its price. b. Suppose we have another dictionary for our cart...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT