Question: JAVA - I need my GUI ReportsUI to read from text file records.txt and insert data into the correct field on the GUI. Do I

JAVA - I need my GUI ReportsUI to read from text file "records.txt" and insert data into the correct field on the GUI. Do I need to add a "view" button for this? I also need to be able to edit records, delete records and search records from this GUI. My text file is formatted: danny smith 259 lester dr lansing 1235498678 Large 11.50 with fields name, address, city, phone, pizza size, order amount. Once edited, i need to update the record in the text file and delete records from text file. I would like to be able to search records by last name. I am new to JAVA and can't seem to figure out how to get the GUI to read the file. The code I have is:

import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*;

public class RecordsUI extends JFrame implements ActionListener { private JLabel nameL, addressL, cityL, phoneL, pizzasizeL, amountL, allL; private JTextField nameTF, addressTF, cityTF, phoneTF, pizzasizeTF, amountTF; private JMenuBar menuMB = new JMenuBar(); private JMenu fileM, helpM; // private JMenuItem exitI, aboutI, ordersI; //declare button private JButton editRecord, deleteRecord, searchRecord, displayAll, summary; //declare billTA of JTextArea private JTextArea displayTA; //declare double variable private static double amount = 0; Scanner scan; public RecordsUI() {

//title of program setTitle("Pizza Palace Order Records"); //creates container Container pane = getContentPane(); //set layout pane.setLayout(null); //set size setSize(1000,700); editRecord = new JButton("Edit Record"); deleteRecord = new JButton("Delete Record"); searchRecord = new JButton("Search Records"); displayAll = new JButton("Display All Records"); summary = new JButton("Summary Report"); //set button size editRecord.setSize(150,30); deleteRecord.setSize(150,30); searchRecord.setSize(150,30); displayAll.setSize(150,30); summary.setSize(150,30); //set button location editRecord.setLocation(200,30); deleteRecord.setLocation(350,30); searchRecord.setLocation(500,30); displayAll.setLocation(50,30); summary.setLocation(600, 200); //add ItemListener editRecord.addActionListener(this); deleteRecord.addActionListener(this); searchRecord.addActionListener(this); displayAll.addActionListener(this); summary.addActionListener(this); //create text area displayTA = new JTextArea(); //set text area font displayTA.setFont(new Font("Times New Roman", Font.PLAIN, 12)); //set text area size displayTA.setSize(750,250); //set text area location displayTA.setLocation(100,375); // creates labels nameL = new JLabel("Name:"); addressL = new JLabel("Street Address: "); cityL = new JLabel("City: "); phoneL = new JLabel("Phone: "); pizzasizeL = new JLabel("Pizza Size: "); amountL = new JLabel("Order Amount: "); allL = new JLabel("All Records"); //set size and location nameL.setSize(100,30); nameL.setLocation(175,100); addressL.setSize(100,30); addressL.setLocation(175,140); cityL.setSize(100,30); cityL.setLocation(175, 180); phoneL.setSize(100,30); phoneL.setLocation(175,220); pizzasizeL.setSize(100,30); pizzasizeL.setLocation(175,260); amountL.setSize(100,30); amountL.setLocation(175,300); allL.setSize(100,30); allL.setLocation(450,350); //creates text fields nameTF = new JTextField(20); addressTF = new JTextField(50); cityTF = new JTextField(20); phoneTF = new JTextField(12); pizzasizeTF = new JTextField(12); amountTF = new JTextField(12); //set size nameTF.setSize(200,30); addressTF.setSize(200,30); cityTF.setSize(200,30); phoneTF.setSize(200,30); pizzasizeTF.setSize(200,30); amountTF.setSize(200,30); //set location nameTF.setLocation(275,100); addressTF.setLocation(275,140); cityTF.setLocation(275, 180); phoneTF.setLocation(275, 220); pizzasizeTF.setLocation(275,260); amountTF.setLocation(275,300); // add items to content pane pane.add(nameL); pane.add(nameTF); pane.add(addressL); pane.add(addressTF); pane.add(cityL); pane.add(cityTF); pane.add(phoneL); pane.add(phoneTF); pane.add(pizzasizeL); pane.add(pizzasizeTF); pane.add(amountL); pane.add(amountTF); pane.add(editRecord); pane.add(deleteRecord); pane.add(searchRecord); pane.add(displayAll); pane.add(displayTA); pane.add(allL); pane.add(summary); //set menu bar setJMenuBar(menuMB); setFileMenu(); setHelpMenu();

//content pane settings setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } //method to create file menu private void setFileMenu() { fileM = new JMenu("File"); menuMB.add(fileM); ordersI = new JMenuItem("Order System"); fileM.add(ordersI); exitI = new JMenuItem("Exit"); fileM.add(exitI); exitI.addActionListener(new ExitListener()); ordersI.addActionListener(new GUIListener()); } //method to create help menu private void setHelpMenu() { helpM = new JMenu("Help"); menuMB.add(helpM); aboutI = new JMenuItem("About"); helpM.add(aboutI); aboutI.addActionListener(new AboutListener()); } //method to display all records private void displayAllRecords() { //sets editibility to text area displayTA.setEditable(false); //set text displayTA.setText(""); //repaint method to display repaint(); } public static void main(String[]args) throws FileNotFoundException { RecordsUI records = new RecordsUI(); }

private class ExitListener implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } private class GUIListener implements ActionListener { public void actionPerformed(ActionEvent e) { Orders neworder = new Orders(); } } private class AboutListener implements ActionListener { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog( null, "Version 1.0 Copyright 2017. Created by .", "About", JOptionPane.INFORMATION_MESSAGE); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!