MVC JOptionPane和复选框,不再显示此消息

时间:2015-07-01 01:45:30

标签: java swing

为错误消息实现JOptionPanes的最佳方法是什么?如果我决定将应用程序设计为远至5,那么我可能总共有10条错误消息。 JOptionPanes将在扩展抽象操作的类中调用。只有在用户输入验证失败时才会显示JOptionPanes。我选择的设计模式是静态工厂。

public class ApplicationErrorPanes {

    public static class NewSupplierError extends JOptionPane {
        //JOptionPane details with return.....
    }

    //More static factories.....
} 

对于JOptionPanes中的复选框,我将使用Object []作为API的对象参数,但是在应用程序中跟踪复选框是否已被检查的最佳方法是什么,即使申请结束?

1 个答案:

答案 0 :(得分:0)

基本上我完成了MadProgrammer在上述评论中所建议的内容....

这是模型:

pink = np.array([0.1001, 0.221, 0.321])

这是观点:

public class ErrorMessageModel {

  private Properties settings;

  private FileInputStream inputStream;

  private FileOutputStream outputStream;

  public ErrorMessageModel() {

    settings = new Properties();

  }

  public void loadProperties() {
    if (settings != null) {
        try {
            inputStream = new FileInputStream("config.properties");

            settings.load(inputStream);

            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
  }

  public String getErrorMessage(String key) {
    return settings.getProperty(key);
  }

  public boolean isDisplayable(String key) {
    if (settings.getProperty(key).equals("false")) {
        return false;
    } else {
        return true;
    }
  }

  public void saveProperties(String key, String value) {
    settings.put(key, value);

    storeProperties();
  }

  public void storeProperties() {
    try {
        outputStream = new FileOutputStream("config.properties");

        settings.store(outputStream, null);

        outputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
  }
}

这是控制器的一个例子:

public class ErrorMessagePane {

  private JLabel message;

  private JCheckBox checkBox;

  private JPanel panel;

  public ErrorMessagePane(Container parent, String errorMessage) {

    panel = new JPanel (new MigLayout(""));

    message = new JLabel (errorMessage);
    message.setFont(ApplicationStyles.STANDARD_FONT);
    panel.add(message);

    checkBox = new JCheckBox("Don't Show This Message Again");
    checkBox.setFont(ApplicationStyles.STANDARD_FONT);
    panel.add(checkBox);

    JOptionPane.showMessageDialog(parent, panel, "Error",
            JOptionPane.ERROR_MESSAGE);
  }

  public boolean isCheckBoxSelected () {
    return checkBox.isSelected();
  }
}