我可以避免这么多if语句吗?

时间:2013-01-27 03:43:16

标签: java

在我的项目中,一个ComboBox中的选项会影响下一个ComboBox中可用的选项......我对此很新,但如果我是对的,我在这里看到每个String都是if / else语句在actionListener中。有没有什么方法可以减少这个问题,或者只是时候破解我的指关节并打字(如果你看到2个模型具有完全相同的字符串,那只是因为还没有添加所有单个字符串)?

//Model Dropdown
final DefaultComboBoxModel termModel = new DefaultComboBoxModel(new String[]{
        "Choose One...", "Hypercom", "DejaVoo", "Nurit", "Verifone"});

//Default Dropdown
final DefaultComboBoxModel slctAbove = new DefaultComboBoxModel(new String[]{"Select Option Above"});


//Terminal Dropdowns
final DefaultComboBoxModel hSpecModel = new DefaultComboBoxModel(new String[]{
        "Choose One...", "T7Plus", "4205", "4210", "4220", "4230"});
final DefaultComboBoxModel dSpecModel = new DefaultComboBoxModel(new String[]{
        "Choose One...", "Dial", "IP", "Wireless"});
final DefaultComboBoxModel nSpecModel = new DefaultComboBoxModel(new String[]{
        "Choose One...", "2085", "3020", "8320 Dial", "8320 IP", "8400 Dial", "8400 IP"});
final DefaultComboBoxModel vSpecModel = new DefaultComboBoxModel(new String[]{
        "Choose One...", "Global Dial", "Global IP", "TPS Dial", "TPS IP", "Ptech Dial", "Ptech IP"});

//Call Type Dropdown
final DefaultComboBoxModel callReason = new DefaultComboBoxModel(new String[]{
        "Choose One...", "Download", "Troubleshoot"});

//Error Dropdowns
//Hypercom
final DefaultComboBoxModel hypError = new DefaultComboBoxModel(new String[]{
        "Choose One...", "Invalid Merch ID", "Printer Error", "Retry Batch Trans", "AP Dupe", "Invalid Balance Settlement"});

//DejaVoo
final DefaultComboBoxModel dejaError = new DefaultComboBoxModel(new String[]{
        "Choose One...", "Invalid Merch ID", "Invalid Batch #", "AP Dupe"});
final DefaultComboBoxModel dejaMError = new DefaultComboBoxModel(new String[]{
        "Choose One...", "Invalid Merch ID", "Invalid Batch #", "Transport Layer Abort", "AP Dupe"});

//Nurit
final DefaultComboBoxModel nuritDError = new DefaultComboBoxModel(new String[]{
        "Choose One...", "Invalid Merch ID", "Invalid DUKPT Key", "Invalid Balance Settlement", "AP Dupe", "Secure Capture", "Invalid Term ID", "Open Tab", "No Host Response"});
final DefaultComboBoxModel nuritIpError = new DefaultComboBoxModel(new String[]{
        "Choose One...", "Invalid Merch ID", "Invalid DUKPT Key", "Invalid Balance Settlement", "AP Dupe", "Secure Capture", "Invalid Term ID", "Open Tab", "No Host Response"});
final DefaultComboBoxModel nuritWError = new DefaultComboBoxModel(new String[]{
        "Choose One...", "Invalid Merch ID", "Invalid DUKPT Key", "Invalid Balance Settlement", "AP Dupe", "Secure Capture", "Invalid Term ID", "Open Tab", "No Host Response", "Rad Fail", "No Net"});

//Verifone
final DefaultComboBoxModel verifError = new DefaultComboBoxModel(new String[]{
        "Choose One...", "Invalid Merch ID", "Invalid DUKPT Key", "Invalid Balance Settlement", "AP Dupe", "Keyboard Locked", "Invalid Term ID", "Card Not Supported", "Comm Error"});

0 个答案:

没有答案