一般建议? JAVA 中 ACH 的带缓冲 Reader/Writer 的 GUI
General advice? GUI with Buffered Reader/Writer for ACH in JAVA
我几周前在这里发布了关于我工作的项目。该项目从创建一个简单的小程序开始,该程序将接收传入的 ACH 文件并读取每一行。该程序还会要求用户输入 "reason code" 和 "bank",这会影响下一步。然后程序会以某种方式重新格式化所有数据并将其保存到外部文件中。对于那些不知道的人,ACH 只是一个非常具体格式的基于文本的文件。 (每个字符和 space 都有含义。)
我已经使用一些 GUI 项(Jcombobox、JFileChooser 等)、字符串数组列表、缓冲 reader/writer 和大量 if/else 语句完成了该任务。
任务现在已经扩展到更加复杂,我不知道如何开始,所以我想我会寻求社区的建议。
当 ACH 文件出现时,它将采用如下格式:
101 100000000000000000000000000000
522 00000202020382737327372732737237
6272288381237237123712837912738792178
6272392390123018230912830918203810
627232183712636283761231726382168
822233473498327497384798234724273487398
522 83398402830943240924332849832094
62723921380921380921382183092183
6273949384028309432083094820938409832
82283409384083209482094392830404829304
900000000000000000000000000000000
9999999999999999999999999999999999999
9999999999999999999999999999999999999
(我会用“ ”号来指代每一行,例如“1号”就是以1开头的行)
最终的结果是数据行被操作并放入"batches"。输出文件以“1号”开头
然后包含格式为
的批处理
5
6
8
5
6
8
5
6
8
我们继续使用相同的“5 数字”,直到原始文件中它下面的所有 6 都被写入,然后我们转到下一个“5”并处理它下面的“6”。
所以,我现在的项目是创建一个完整的 GUI。用户输入文件后,GUI 将有某种类型的下拉框或所有“6”数字的类似列表。对于每个号码,应该有另一个下拉框来选择原因代码(有 7 个原因代码)。
基本上最终的objective是:
- 显示所有“6”数字并让用户能够为每个数字选择原因代码。
如果用户愿意,只允许他们 select 一定数量的“6”号码。
我可以使用 Buffered Reader/ Writer 来做到这一点吗?我目前使用以下代码将值保存到数组列表中:
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{
}
假设我想使用 Buffered Writer 将所有“6”数字保存到一个字符串数组中,然后将它们放入 GUI 中的下拉框中。我怎么能做到这一点?
Can you use the input from Buffered Writer in a GUI..
好吧,BufferedWriter 不是用于获取输入而是用于输出信息,但假设您指的是 BufferedReader,那么答案肯定是肯定的。了解 GUI 和使用 BufferedReader 获取数据是正交的概念——它们都可以独立于另一个工作得很好。涉及使用具有 GUI 的 Buffered 读取数据的主要问题
Say a JOptionPane for example.
我不确定你在这里的意思或这之间的关系。
If yes, then how could I go about doing that? In all the examples I have seen and tutorials about JOptionPane everything is done BEFORE the main method. What if I need if statements included in my JOptionPane input? How can I accomplish this?
我不确定您所说的 "everything is done before the main method" 是什么意思,但听起来您可能有些言过其实了。在担心具体细节和代码的具体位置之前,请考虑 classes/objects 您的程序将具有什么,以及它们将如何交互——即它们将具有哪些方法。
I believe I just had an idea of how I need to proceed first. Can someone please verify? 1. Create static variables representing the lines that will be read. (Such as a static ArrayList.
不,不要立即考虑静态的任何东西,因为一旦这样做,您就离开了 OOP 领域并进入过程编程。主要数据应保存在 class 或两个
内的实例变量中
- Create the actual GUI, outside the main Method.
我不确定你的意思"outside the main method",但是 GUI 将由多个 class 组成,可能是一个主要的,主要 class 的一个实例是不是经常在 main 方法中创建,或者在 main 方法调用的方法中创建,而是排队到 Swing 事件线程。
- Create the Buffered Reader which will write to the variables mentioned in #1, inside the main method.
同样,我不会这样做。 main方法应该很短,很短,它存在的理由只是启动你的关键对象并设置它们运行,仅此而已。对它们不应该做任何重要的事情(除了我所说的)。你在想小玩具程序,那不是你在写的。 reader 应该是其自身 class 内部的一个实例变量。它可能由 GUI 通过控件 class 间接启动,该控件是响应 GUI 事件的 class。如果您在创建 GUI 之前需要数据,那么您将让您的主要方法创建读取数据的 class,要求它获取数据,然后创建您的 GUI class,将数据传递给它。
我几周前在这里发布了关于我工作的项目。该项目从创建一个简单的小程序开始,该程序将接收传入的 ACH 文件并读取每一行。该程序还会要求用户输入 "reason code" 和 "bank",这会影响下一步。然后程序会以某种方式重新格式化所有数据并将其保存到外部文件中。对于那些不知道的人,ACH 只是一个非常具体格式的基于文本的文件。 (每个字符和 space 都有含义。)
我已经使用一些 GUI 项(Jcombobox、JFileChooser 等)、字符串数组列表、缓冲 reader/writer 和大量 if/else 语句完成了该任务。
任务现在已经扩展到更加复杂,我不知道如何开始,所以我想我会寻求社区的建议。
当 ACH 文件出现时,它将采用如下格式:
101 100000000000000000000000000000
522 00000202020382737327372732737237
6272288381237237123712837912738792178
6272392390123018230912830918203810
627232183712636283761231726382168
822233473498327497384798234724273487398
522 83398402830943240924332849832094
62723921380921380921382183092183
6273949384028309432083094820938409832
82283409384083209482094392830404829304
900000000000000000000000000000000
9999999999999999999999999999999999999
9999999999999999999999999999999999999
(我会用“ ”号来指代每一行,例如“1号”就是以1开头的行)
最终的结果是数据行被操作并放入"batches"。输出文件以“1号”开头 然后包含格式为
的批处理5
6
8
5
6
8
5
6
8
我们继续使用相同的“5 数字”,直到原始文件中它下面的所有 6 都被写入,然后我们转到下一个“5”并处理它下面的“6”。
所以,我现在的项目是创建一个完整的 GUI。用户输入文件后,GUI 将有某种类型的下拉框或所有“6”数字的类似列表。对于每个号码,应该有另一个下拉框来选择原因代码(有 7 个原因代码)。
基本上最终的objective是:
- 显示所有“6”数字并让用户能够为每个数字选择原因代码。
如果用户愿意,只允许他们 select 一定数量的“6”号码。
我可以使用 Buffered Reader/ Writer 来做到这一点吗?我目前使用以下代码将值保存到数组列表中:
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{
}
假设我想使用 Buffered Writer 将所有“6”数字保存到一个字符串数组中,然后将它们放入 GUI 中的下拉框中。我怎么能做到这一点?
Can you use the input from Buffered Writer in a GUI..
好吧,BufferedWriter 不是用于获取输入而是用于输出信息,但假设您指的是 BufferedReader,那么答案肯定是肯定的。了解 GUI 和使用 BufferedReader 获取数据是正交的概念——它们都可以独立于另一个工作得很好。涉及使用具有 GUI 的 Buffered 读取数据的主要问题
Say a JOptionPane for example.
我不确定你在这里的意思或这之间的关系。
If yes, then how could I go about doing that? In all the examples I have seen and tutorials about JOptionPane everything is done BEFORE the main method. What if I need if statements included in my JOptionPane input? How can I accomplish this?
我不确定您所说的 "everything is done before the main method" 是什么意思,但听起来您可能有些言过其实了。在担心具体细节和代码的具体位置之前,请考虑 classes/objects 您的程序将具有什么,以及它们将如何交互——即它们将具有哪些方法。
I believe I just had an idea of how I need to proceed first. Can someone please verify? 1. Create static variables representing the lines that will be read. (Such as a static ArrayList.
不,不要立即考虑静态的任何东西,因为一旦这样做,您就离开了 OOP 领域并进入过程编程。主要数据应保存在 class 或两个
内的实例变量中
- Create the actual GUI, outside the main Method.
我不确定你的意思"outside the main method",但是 GUI 将由多个 class 组成,可能是一个主要的,主要 class 的一个实例是不是经常在 main 方法中创建,或者在 main 方法调用的方法中创建,而是排队到 Swing 事件线程。
- Create the Buffered Reader which will write to the variables mentioned in #1, inside the main method.
同样,我不会这样做。 main方法应该很短,很短,它存在的理由只是启动你的关键对象并设置它们运行,仅此而已。对它们不应该做任何重要的事情(除了我所说的)。你在想小玩具程序,那不是你在写的。 reader 应该是其自身 class 内部的一个实例变量。它可能由 GUI 通过控件 class 间接启动,该控件是响应 GUI 事件的 class。如果您在创建 GUI 之前需要数据,那么您将让您的主要方法创建读取数据的 class,要求它获取数据,然后创建您的 GUI class,将数据传递给它。