Question: l have question regarading the answer for first question: Modify your program from Assignment # 7 part b by creating an interactive GUI application that
l have question regarading the answer for first question:
Modify your program from Assignment # 7 part b by creating an interactive GUI application that displays the list of the accounts read in from the file (create a text data file using your CreateBankFile.java program which has a least 10 bank account records in it and include it with your submission) and the total number of bank accounts. When your program starts it will first read the records from the Bank Account file 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.
l did finsh the code but some part off it l am not able to finsh it regardig sort in asednding cust , Balance, name becuase l am not get at it if the buble sort is asednding how to apply it to to GUl application and how to set the source slected and deslected . this code there are missing statemnt regarding the buble sort and selcted item as
import java.awt.BorderLayout; 10 import java.awt.FlowLayout; 11 import java.awt.Font; 12 import java.awt.event.ItemEvent; 13 import java.awt.event.ItemListener; 14 import java.io.BufferedInputStream; 15 import java.io.BufferedReader; 16 import java.io.InputStreamReader; 17 import java.nio.ByteBuffer; 18 import java.nio.file.Files; 19 import java.nio.file.Path; 20 import java.nio.file.Paths; 21 import java.util.ArrayList; 22 import java.util.Arrays; 23 import java.util.List; 24 import java.util.Scanner; 25 import javax.swing.JCheckBox; 26 import javax.swing.JFrame; 27 import javax.swing.JLabel; 28 import javax.swing.JScrollPane; 29 import javax.swing.JTextArea; 30 import javax.swing.JTextField; 31 import javax.swing.ScrollPaneConstants; 32 33 /* this lines are transfer the read class to the GUI application by creating GUIBankAcctSorter */ 34 35 public class GUIBankAcctSorter extends JFrame implements ItemListener 36 { 37 38 String Results = null; 39 String FinalResults =" "; 40 String ActualNumber; 41 int Accounts; 42 ArrayList list=new ArrayList(); 43 44 public String StringBuilderw() 45 { 46 String ProgrammerName =("Bank.txt"); 47 Scanner input = new Scanner(System.in); 48 final String ID_FORMAT = "000"; 49 final String NAME_FORMAT = " "; 50 final int NAME_LENGTH = NAME_FORMAT.length(); 51 final String BALANCE_FORMAT ="000.00"; 52 String delimiter = ","; 53 String s = ID_FORMAT + delimiter + NAME_FORMAT + delimiter + 54 BALANCE_FORMAT + 55 System.getProperty("line.separator"); 56 final int RECSIZE = s.length(); 57 byte data[] = s.getBytes(); 58 final String EMPTY_ACCT = "000"; 59 String[] array = new String[10]; 60 double balance; 61 double total = 0; 62 63 /* this lines is to try catch and handle all data entery and file writting */ 64 65 try 66 { 67 InputStream iSteram = new 68 BufferedInputStream(Files.newInputStream(Bank)); 69 BufferedReader reader = new 70 BufferedReader(new InputStreamReader(iSteram)); 71 72 s = reader.readLine(); 73 74 75 76 while(s != null) 77 { 78 array = s.split(delimiter); 79 if(!array[0].equals(EMPTY_ACCT)) 80 { 81 balance = Double.parseDouble(array[2]); 82 /* this line is the total # Bank Accounts to parse it */ 83 84 Accounts = Integer.parseInt(array[0]); 85 86 87 if (Accounts != 0) { 88 String CustomerNumber = array[0]; 89 String Names = array[1]; 90 Balance = Double.parseDouble(array[2]); 91 92 String ActualResult = ("Cust# " + CustomerNumber 93 + " Name " + Names + "Balance $" + Balance + " "); 94 // total += Balance; 95 total += 1; 96 97 test[0]=array[0]; 98 test[1]=array[1]; 99 test[2]=array[2]; 100 list.add(test); 101 //cust.add(array[0]); 102 StringBuilder AllTotalNumber = new StringBuilder(); 103 AllTotalNumber.append(total); 104 ActualNumber = AllTotalNumber.toString(); 105 106 FinalResults = FinalResults+ActualResult; 107 } 108 109 } 110 111 StringBuilder results = new StringBuilder(); 112 113 String newline = System.getProperty("line.separator"); 114 115 results.append(FinalResults); 116 117 118 119 120 121 //results.append(s); 122 123 // results.append(s1); 124 Results = results.toString(); 125 126 s = reader.readLine(); 127 128 } 129 130 reader.close(); 131 132 } 133 134 catch (Exception ex) 135 { 136 System.out.println("Error was cought" + ex); 137 } 138 139 return Results; 140 } 141 142 JLabel header = new JLabel("Bank Account Sorter"); 143 /* I have to make this text field hold multiple text */ 144 JTextArea textArea = new JTextArea(StringBuilderw(), 10, 30); 145 146 JTextField TotalNumber = new JTextField(ActualNumber); 147 JLabel sortBy = new JLabel("Sort By"); 148 JLabel totalNumberOfBankAcct = new JLabel("Total # of Bank Accounts"); 149 150 /* JCheckBoxes */ 151 JCheckBox boxCustomer = new JCheckBox("Cust#", false); 152 JCheckBox boxBalance = new JCheckBox("Balance", false); 153 JCheckBox boxName = new JCheckBox("Name", false); 154 155 // This is to make the textField scroll horizontally as need and not always. 156 // Vertical scroll is as needed as well 157 JScrollPane scroll = new JScrollPane(textArea); 158 159 /* This is to set a font for JLabel header to be big */ 160 161 private Font bigFont = new Font("Arial", Font.BOLD, 20); 162 163 public GUIBankAcctSorter() 164 { 165 super("Bank Account Sorter"); 166 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 167 setLayout(new FlowLayout()); 168 /* this lins are add copmoints to the text area */ 169 add(header); 170 header.setFont(bigFont); 171 172 /* this line is to show the scroll line */ 173 scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); 174 175 176 add(scroll); 177 textArea.add(scroll); 178 add(textArea); 179 textArea.setEditable(false); 180 scroll.setBounds(5, 5, 300, 200); 181 add(sortBy); 182 add(boxCustomer); 183 add(boxBalance); 184 add(boxName); 185 add(totalNumberOfBankAcct); 186 add(TotalNumber); 187 TotalNumber.setEditable(false); 188 textArea.setEditable(false); 189 190 /* this lines are for Registering the class as listener for events */ 191 192 193 boxCustomer.addItemListener(this); 194 boxBalance.addItemListener(this); 195 boxName.addItemListener(this); 196 197 } 198 199 200 @Override 201 public void itemStateChanged(ItemEvent event) { 202 Object Source = event.getSource(); 203 int Select = event.getStateChange(); 204 205 // This is were I define what happens when 206 // boxCustomer CheckBox is selected 207 if (Source == boxCustomer) { 208 209 // this is to check if boxCustomer is selected 210 // then the other check boxes should not be checked 211 if (boxCustomer.isSelected()) { 212 boxName.setSelected(false); 213 boxBalance.setSelected(false); 214 } 215 216 } 217 218 // this is to see if boxCustomer is sure selected from 219 // event.getStateChange() method 220 if (Select == ItemEvent.SELECTED) { 221 // code here 222 // Sort elements in an object array(bauble sort) using customer 223 224 } 225 226 // This is were I define what happens when 227 // boxName CheckBox is select 228 229 if (Source == boxName) { 230 231 // this is to check if boxName is selected 232 // then the other check boxes should not be checked 233 if (boxName.isSelected()) { 234 235 boxCustomer.setSelected(false); 236 boxBalance.setSelected(false); 237 } 238 StringBuilder results = new StringBuilder(); 239 String table[][]=new String[list.size()][]; 240 table=list.toArray(table); 241 Arrays.sort(table[0]); 242 for(int j=0;j<=list.size()-1;j++){ 243 for(int k=j;k<1;k++){ 244 245 results.append("Cust# " + table[j][k] + " Name " + table[j][k+1] + "Balance $" + table[j][k+2] + " "); 246 247 } 248 249 } 250 251 252 } 253 // this is to see if boxCustomer is sure selected from 254 // event.getStateChange() method 255 if (Select == ItemEvent.SELECTED) { 256 // code here 257 // Sort elements in an object array(bauble sort) using Names 258 } 259 260 // This is were I define what happens when 261 // boxBalance CheckBox is select 262 if (Source == boxBalance) { 263 // this is to check if boxBalance is selected 264 // then the other checkboxes should not be checked 265 if (boxBalance.isSelected()) { 266 267 boxCustomer.setSelected(false); 268 boxName.setSelected(false); 269 270 } 271 // this is to see if boxCustomer is sure selected from 272 // event.getStateChange() method 273 if (Select == ItemEvent.SELECTED) { 274 // code here 275 // Sort elements in an object array(bauble sort) using balance 276 } 277 278 } 279 } 280 281 // Main Method 282 public static void main(String[] args) { 283 GUIBankAcctSorter gui = new GUIBankAcctSorter(); 284 gui.setSize(450, 350); 285 gui.setVisible(true); 286 gui.setResizable(false); 287 288 } 289 290 } 291
could we apply this buble sort
for(a = 0; a < someNums.length -1; ++a) for(b =0, b < someNums.length -1; ++b)
{
temp = someNums[b];
someNums[b] = someNums[b+1]
someNums[b+1] = temp;
}
how to applly the sort for the cast the blance and the name