JSON-JAVA / CATATAN</>↗JSON-Java07 Feb 2022
In JSON-Java we can make a pretty-printed JSON string by specifying an indentFactor to the JSONObject‘s toString() method. The indent factor is the number of spaces to add to each level of indentation. If indentFactor > 0 and the JSONObject has only one key, the JSON string will be printed a single line, and if […]
JSON-JAVA / CATATAN</>↗JSON-Java07 Feb 2022
A JSONArray object represent an ordered sequence of values. We use the put() method to add or replace values in the JSONArray object. The value can be of the following types: Boolean, JSONArray, JSONObject, Number, String or the JSONObject.NULL object. Beside using the put() method we can also create and add data into JSONArray in […]
JSON-JAVA / CATATAN</>↗JSON-Java06 Feb 2022
A JSONObject is an unordered collection of key-value pairs. To read values from the JSONObject we can use the get(String key) and opt(String key) methods. These generic methods return an Object, which you can cast to a certain type. There are also typed get and opt methods to read value in specific type such as […]
JSON-JAVA / CATATAN</>↗JSON-Java05 Feb 2022
To convert Java objects or POJOs (Plain Old Java Objects) to JSON we can use one of JSONObject constructor that takes an object as its argument. In the following example we will convert Student POJO into JSON string. Student class must provide the getter methods, JSONObject creates JSON string by calling these methods. In this […]
JSON-JAVA / CATATAN</>↗JSON-Java05 Feb 2022
In the previous example we use JSONObject to directly put key-value pairs to create JSON string, using the various put() methods. Instead of doing that, we can also create JSON from a Map object. We create a Map with some key-value pairs in it, and pass it as an argument when instantiating a JSONObject. These […]
SWING / CATATAN</>↗Swing13 Jan 2022
Filter items in a long list are often accomplished using the JTextField component. As the user inputs into the JTextField component, the set of items shown in the list is narrowed to just those things that correspond to the input received from the user. It is necessary to utilize two elements to implement this function […]