Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA - I have a Report GUI that needs to read from text file records.txt and insert all records from text file into text area

JAVA - I have a Report GUI that needs to read from text file records.txt and insert all records from text file into text area of GUI when display all button is clicked.

This is the code I have so far. The code under actionPerformed doesn't do anything.

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(this); ordersI.addActionListener(this); } //method to create help menu private void setHelpMenu() { helpM = new JMenu("Help"); menuMB.add(helpM); aboutI = new JMenuItem("About"); helpM.add(aboutI); aboutI.addActionListener(this); } //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(); } static void summaryReport(Scanner textfile) { int i = 0; double sum = 0; while(i > 0) { int amount = textfile.nextInt(); System.out.println("The total amount of sales: " + amount); sum = sum + amount; i++; } } @Override public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("Display All")) { try { FileReader reader = new FileReader("records.txt"); BufferedReader br = new BufferedReader(reader); displayTA.read(br, null); br.close(); displayTA.requestFocus(); } catch (IOException e2) { System.out.println("File Not Found."); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions