Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Programming The file FileDump.java (code pasted below instructions) contains the Swing based code for the event handlers for the FileDump utility. This file will
Java Programming
- The file FileDump.java (code pasted below instructions) contains the Swing based code for the event handlers for the FileDump utility. This file will be the basis for completing the lab assignment. All the event handling code is commented in FileDump.java file.
- Your task for the assignment is to add event handling code to the JavaFX based file named FileDump.java.
- The FileDump.java file should be a JavaFX based program that implements identical functionality found in the Swing based FileDump utility (See images for reference).
Swing based FileDump utility images (For reference)
FileDump.java
import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.text.*; public class FileDump extends JFrame { // set up the menu private JMenu menuFile = new JMenu("File"); private JMenuItem menuFileOpen = new JMenuItem("Open"); private JMenuItem menuFileExit = new JMenuItem("Exit"); private JMenu menuHelp = new JMenu("Help"); private JMenuItem menuHelpAbout = new JMenuItem("About"); private JMenuBar mb = new JMenuBar(); // set up north panel private JPanel northPanel = new JPanel(); private JLabel fileName = new JLabel(""); // set up east panel private JPanel eastPanel = new JPanel(); private JButton up = new JButton("Up"); private JButton down = new JButton("Down"); // set up south panel private JPanel southPanel = new JPanel(); private JButton resetButton = new JButton("Reset"); private JButton exitButton = new JButton("Exit"); private JTextArea fileOutput = new JTextArea(10, 80); private RandomAccessFile file = null; private int fileIndex; private int fileOffset; private File choosenFile; public FileDump(String str) { super(str); Container cp = getContentPane(); cp.setLayout(new BorderLayout()); setSize(620, 300); fileOutput.setEditable(false); fileOutput.setFont(new Font("Courier", Font.PLAIN, 12)); menuFileOpen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileChoose = new JFileChooser(); int result = fileChoose.showOpenDialog(FileDump.this); choosenFile = fileChoose.getSelectedFile(); if(choosenFile == null || result != JFileChooser.APPROVE_OPTION) { return; } String strFileName = choosenFile.getAbsolutePath(); choosenFile.getName(); fileName.setText(strFileName); try { file = new RandomAccessFile(strFileName, "r"); } catch(Exception openExec) { JOptionPane.showMessageDialog(null, " Could Not Open File: " + strFileName, "File Open Exception - File: " + strFileName, JOptionPane.PLAIN_MESSAGE); fileName.setText("No file currently open"); return; } fileIndex = 0; fileOffset = 0; up.setEnabled(true); down.setEnabled(true); resetButton.setEnabled(true); menuFileOpen.setEnabled(false); displayData(); } } ); menuFile.add(menuFileOpen); menuFileExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //e.getWindow().dispose(); System.exit(0); } } ); menuFile.add(menuFileExit); mb.add(menuFile); menuHelpAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, " This is the file dump utillity program" + " Developed by: Kim Cannon" + " Version 1.0", "About Dialog", JOptionPane.PLAIN_MESSAGE); } } ); menuHelp.add(menuHelpAbout); mb.add(menuHelp); setJMenuBar(mb); // set up the north panel fileName.setBorder(BorderFactory.createTitledBorder("Open File:")); fileName.setText("No file currently open"); northPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); northPanel.add(fileName); cp.add(northPanel, BorderLayout.NORTH); // set up the east panel eastPanel.setLayout(new GridLayout(5, 1)); up.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { fileIndex--; if(fileIndex File Dump Utility - O X File Help Open File: No file currently open Up Down Reset Exit - O X File Dump Utility File Help Open ile: Exit currently open Up Down Reset Exit - 0 X File Dump Utility File Help Ope About No file currently open Up Down Reset Exit File Dump Utility - O X File Help Open File: No file currently open Up Down Reset Exit - O X File Dump Utility File Help Open ile: Exit currently open Up Down Reset Exit - 0 X File Dump Utility File Help Ope About No file currently open Up Down Reset Exit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started