用户界面一般建议?JAVA中带有ACH缓冲读写器的GUI
几周前我在这里发布了一个关于我工作的项目。该项目一开始是创建一个简单的小程序,它将接收一个传入的ACH文件并读取每一行。该程序还将要求用户输入“原因代码”和“银行”,这将影响下一步。然后,程序将以某种方式重新格式化所有数据,并将其保存到外部文件中。对于那些不知道的人来说,ACH只是一个非常具体的基于文本的文件。(每个字符和空格都有其含义。)
我使用了一些GUI项(Jcombobox、JFileChooser等)、字符串数组列表、缓冲读写器和许多if/else语句完成了这项任务
这项任务现在已经扩展到一个更复杂的领域,我不知道如何开始,所以我想我会寻求社区的建议
当ACH文件进入时,其格式如下所示:
101 100000000000000000000000000000
522 00000202020382737327372732737237
6272288381237237123712837912738792178
6272392390123018230912830918203810
627232183712636283761231726382168
822233473498327497384798234724273487398
522 83398402830943240924332849832094
62723921380921380921382183092183
6273949384028309432083094820938409832
82283409384083209482094392830404829304
900000000000000000000000000000000
9999999999999999999999999999999999999
9999999999999999999999999999999999999
(我将以“”编号引用每一行,例如“1编号”是以1开头的行)
最终结果是数据行被手动上传并放入“批处理”中。输出文件以“1号”开头 然后包含格式为的批
5
6
8
5
6
8
5
6
8
我们继续使用相同的“5号”,直到原始文件中低于它的所有6号都已写入,然后转到下一个“5号”,并使用它下面的“6号”
因此,我现在的项目是创建一个完整的GUI。用户输入文件后,GUI将具有某种类型的下拉框或所有“6”数字的类似列表。对于每个数字,应该有另一个下拉框来选择原因代码(共有7个原因代码)
基本上,最终目标是:
- 显示所有“6”数字,并让用户能够为每个数字选择原因代码李>
如果用户愿意,只允许用户选择一定数量的“6”数字
我是否可以使用缓冲读写器来执行此操作?我当前使用以下代码将值保存到数组列表中:
while((sCurrentLine = br.readLine()) !=null)//<---------This loop will continue while there are still lines to be read. { if (sCurrentLine.startsWith("5")){//<------------------If the line starts with "5".. listFive.add(sCurrentLine);//<-------------------------Add the line to the array list "listFive". countFive++;//<---------------------------------------------Increase the counter "countFive" by one. }else if (sCurrentLine.startsWith("6") && countFive==1){//<---------If the line starts with "6" and countFive is at a value of 1.. listSix.add(sCurrentLine);//<---------------------------------------Add the line to the array list "listSix". }else if (sCurrentLine.startsWith("6") && countFive==2){//<-----------------If the line starts with "6" and countFive is at a value of 2.. listSixBatchTwo.add(sCurrentLine);//<--------------------------------------Add the line to the array list "listSixBatchTwo". }else if (sCurrentLine.startsWith("6") && countFive==3){//<-----------------------If the line starts with "6" and countFive is at a value of 3.. listSixBatchThree.add(sCurrentLine);//<------------------------------------------Add the line to array list "listSixBatchThree". }else if (sCurrentLine.startsWith("6") && countFive==4){//<------------------------------If the line starts with "6" and countFive is at a value of 4.. listSixBatchFour.add(sCurrentLine); //<--------------------------------------------------Add the line to array list "listSixBatchFour". }else if (sCurrentLine.startsWith("8")){//<-----------------------------------------------------If the line starts with "8".. listEight.add(sCurrentLine);//<----------------------------------------------------------------Add the line to array list "listEight". }else if (sCurrentLine.startsWith("1")){//<-----------------------------------------------------------If the line starts with "1".. one = sCurrentLine;//<-------------------------------------------------------------------------------Save the line to String "one". }else if (sCurrentLine.startsWith("9") && count9 == 1){//<---------------------------------------------------If the line starts with "9" and count9 is at a value of 1.. nine = sCurrentLine;//<-------------------------------------------------------------------------------------Save the line to String "nine". count9 = 0;//<--------------------------------------------------------------------------------------------------Set count9 to a value of 0. }else if (sCurrentLine.startsWith("999") && count9 == 0){//<-----------------------------------------------------------If the line starts with "999" and count9 is at a value of 0.. listNine.add(sCurrentLine);//<---------------------------------------------------------------------------------------Add the line to array list "listNine". }else{ } }
如果有人能告诉我从哪里开始,我将非常感激。如果你需要更多的信息,请告诉我
更新:
下面是我的JOptionPane的一个决策示例
String[] choices = {"Wells Fargo", "Bank of America", "CitiBank", "Wells Fargo Legacy", "JPMC"};
String input = (String) JOptionPane.showInputDialog(null, "Bank Selection", "Please choose a bank: ", JOptionPane.QUESTION_MESSAGE, null, choices, choices[0]);
if (input.equals("Wells Fargo"))
{
bank = "WELLS FARGO";
}else if (input.equals("Bank of America")){
bank = "BANK OF AMERICA";
}else if (input.equals("CitiBank")){
bank = "CITI BANK";
}else if (input.equals("Wells Fargo Legacy")){
bank = "WELLS FARGO LEGACY";
}else if (input.equals("JPMC")){
bank = "JPMC";
}
}else{
}
假设我想使用缓冲写入程序将所有“6”数字保存到字符串数组中,然后将它们放入GUI中的下拉框中。我怎样才能做到这一点
# 1 楼答案
BufferedWriter不用于获取输入,而是用于输出信息,但假设您指的是BufferedReader,那么答案肯定是肯定的。了解GUI和使用BufferedReader获取数据是两个正交的概念,它们都可以独立工作。使用具有GUI的缓冲区读入数据的主要问题
我不知道你在这里是什么意思,也不知道这是怎么回事
我不知道你所说的“一切都在主要方法之前完成”是什么意思,但听起来你可能超越了自己。在考虑具体细节和代码的具体位置之前,先考虑一下您的程序将拥有哪些类/对象,以及它们将如何交互,即它们将拥有哪些方法
不,不要想静态的东西,因为一旦你这样做了,你就会离开OOP领域,进入程序编程。主数据应该保存在一两个类中的实例变量中
我不确定“在主方法之外”是什么意思,但是GUI将由多个类组成,可能是一个主类,并且主类的实例并不经常在主方法中创建,或者在主方法调用的方法中创建,而是排队到Swing事件线程中
再说一次,我不会这么做。主要方法应该很短,非常短,它存在的原因只是启动关键对象并将它们设置为运行,就是这样。在他们身上不应该做任何重要的事情(除了我所说的)。你在想小玩具程序,而那不是你在写的。读取器应该是其自身类中的实例变量。它可能由GUI通过控制类间接启动,控制类是响应GUI事件的类。如果在创建GUI之前需要数据,那么您将让主方法创建读入数据的类,要求它获取数据,然后创建GUI类,将数据传递给它