Create an interactive GUI application that displays the list of the orders read
ID: 3694392 • Letter: C
Question
Create an interactive GUI application that displays the list of the orders read in from the file (AccountRecords.txt) and the total number of bank accounts. When your program starts it will first read the records from the Bank Account file (AccountRecords.txt) and creates an array of BankAcct objects. The user of the application will then be able to have the bank accounts sorted (sorting the array of BankAcct objects) in the list by either, Customer #, Customer name, or Customer balance. Save your application as GUIBankAcctSorter.java.
The output from your program will look something like this:
Sample output follows:
When the application opens the user sees the above window displayed on the monitor. The JTextArea control has been filled with the records read in from the file and at the bottom it displays the total number of orders read from the file. The user can scroll the JTextArea control to see those records which are out of view. The following are a series of what the window should look like when the user interacts with the program causing specific events to occur.
When the user clicks on the Balance checkbox the records in the JTextArea control are sorted in ascending order by Balance.
When the user clicks another check box, this time Name, the records are sorted in ascending order by Name. Notice that the other 2 check boxes become unchecked. The user can continue to use the application by clicking on one of the other check boxes to have the records sorted in that order.
Bank Account Sorter Bank Account Sorter Cust # 145 Cust#1234 Cust#4567 Cust#5430 Cust# 5521 Cust#7234 Name R Rich Balance Name Stoth Balance Name M Snell Balance Name S Gone Balance Name Y Mark Balance Name MRed Balance 99,876.32 23,987.98 4,532.78 56.22 456.23 564.02 Sort By LI cust # Balance Name Total # of Bank AccountsExplanation / Answer
due to lack of time I had done with design only:
package guibankacctsorter;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class GUIBankAcctSorter {
private Frame mainFrame;
private Font font;
private Label headerLabel;
private FileReader fr;
private File file;
//private Label statusLabel;
private Panel cp2,cp1;
private TextField txtBox;
public GUIBankAcctSorter() throws FileNotFoundException, IOException{
prepareGUI();
}
public static void main(String[] args) throws FileNotFoundException, IOException {
GUIBankAcctSorter awtControlDemo = new GUIBankAcctSorter();
}
private void prepareGUI() throws FileNotFoundException, IOException {
font = new Font("Verdana", Font.BOLD, 20);
mainFrame = new Frame("Bank Account Sorter");
mainFrame.setSize(600,500);
mainFrame.setLayout(new GridLayout(5, 1));
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
headerLabel = new Label("Bank Account Sorter",Label.CENTER);
headerLabel.setFont(font);
headerLabel.setAlignment(Label.CENTER);
Label sort= new Label("Sort By :",Label.CENTER);
Label count= new Label("Total number of bank accounts :",Label.CENTER);
TextArea txtArea = new TextArea(30,60);
txtBox=new TextField();
txtBox.setSize(40,20);
Checkbox cb1 = new Checkbox("Cust number");
Checkbox cb2 = new Checkbox("Balance");
Checkbox cb3 = new Checkbox("Name");
file = new File("C:/Users/Kanth/Documents/NetBeansProjects/GUIBankAcctSorter/src/guibankacctsorter/data.txt");
fr = new FileReader(file);
BufferedReader br=new BufferedReader(fr);
String data="";
char [] a = new char[500];
fr.read(a); // reads the content to the array
for(char c : a){
System.out.println(c); //prints the characters one by one
txtArea.setText(Character.toString(c));
}
/*while(br.readLine()!= null)
{
data=br.readLine();
txtArea.setText(data);
System.out.println(data);
} */
cp1 = new Panel();
cp1.setLayout(new FlowLayout());
cp2 =new Panel();
cp2.setLayout(new FlowLayout());
cp1.add(sort);
cp1.add(cb1);
cp1.add(cb3);
cp1.add(cb2);
cp2.add(count);
cp2.add(txtBox);
mainFrame.add(headerLabel);
mainFrame.add(txtArea);
mainFrame.add(cp1);
mainFrame.add(cp2);
mainFrame.setVisible(true);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.