Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 567 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A good way to have all my messages in Java

#1
i'm looking for a small framework to have all my messages stored in a common way. I'll give an example for better understanding.

In a part of my code, in a particular JFrame i've an alert something like this:

JOptionPane.showMessageDialog(null, "Error, you must provide an integer value", "ERROR", JOptionPane.ERROR_MESSAGE);

So, this string: "Error, you must provide an integer value". I would like to have it in a particular "log", or something like that, so i can do something like this:

JOptionPane.showMessageDialog(null, Messages.getMessage(Messages.INTEGER_VALUE), "ERROR", JOptionPane.ERROR_MESSAGE);

Hard to explain, hope you can help me.

Thanks!
Reply

#2
Sounds like you need a [`ResourceBundle`][1]. It allows you to maintain locale-sensitive user-displayable messages keyed against a code.

It's not an external framework, it's part of the JavaSE API.


[1]:

[To see links please register here]

Reply

#3
Create a static class called "Messages"

Inside this, have a method called getMessage which accepts an integer, and return the correct error message corresponding to the code.
Reply

#4
Sounds more like you want a lookup table for your error messages. You could get fancy and actually make a class to do this for you or do something easy:

String errors[] = {"Some error","Some other error"};
JOptionPane.showMessageDialog(null,errors[0],"ERROR", JOptionPane.ERROR_MESSAGE);

or

Map<String,String> errors = new HashMap<String,String>();
errors.put("PROVIDE_INT","Error, you must provide an integer value");
JOptionPane.showMessageDialog(null,errors.get("PROVIDE_INT"),"ERROR", JOptionPane.ERROR_MESSAGE);

Reply

#5
I think something like cal10n might be the type of framework you're looking for.

[To see links please register here]


Reply

#6
Or... you can write your own mini messaging utility, like this:-

public class MessageUtil {
enum Message {
ERROR_INTEGER_REQUIRED("Error", "Error, you must provide an integer value"),
ERROR_STRING_REQUIRED("Error", "Error, you must provide a string value"),
ERROR_BLA_BLA("Error", "Error, you are doomed"),
INFO_DATA_SAVED("Note", "Data is successfully saved");

String title;
String msg;

private Message(String title, String msg) {
this.title = title;
this.msg = msg;
}
}

public static void display(Message message) {
JOptionPane.showMessageDialog(null, message.msg, message.title, JOptionPane.ERROR_MESSAGE);
}
}


Then, you can do something like this:-

MessageUtil.display(ERROR_INTEGER_REQUIRED);

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through