[Java] GUI Console Output

Normally, if you write an application, to get the console output, you need to either load it in command propmt or write a batch file to have the Jar file launched with the command prompt window. This method might not work at some locations (ie. Comapny Shared Folder).

To solve this problem, we can create out own Output window in Java, and redirect  System.out to that window by overriding the methods.

Continue reading

[Java] ArrayList – sorting

Let’s say I am writing a program to keep track of amount of hours we spent on testing each engine, I need to utimately generate a report. It will be nice if I can sort the Engine based on it’s Serial number. So here’s the easy way to sort an ArrayList.

We sill use the method:

Collections.sort(list, comparator);

Continue reading

[Java] ArrayList

As I was writting the Voucher Reporting Tool for GE Aviation, the process of storing data in arrays became more and more tedious. Every time I wanted to add another engine, or remove a DAN #, I have to write all those codes to create a new array, filling it in, arranging it and such. Why can’t arrays be resized? Anyway, I turned to the ArrayList class, which I should have been a long time ago.

I guess it is similar to the Data Structure called Linked List, but all coded out by other devs and ready for use. Here’s a simple example.


import java.util.ArrayList;

public class Testing {

public static void main(String[] args) {

//Defining the Array List
ArrayList list = new ArrayList();

//Adding Elements in Order
list.add("One");
list.add("Two");
list.add("Three");
list.add("Four");
list.add("Five");

//Add Element at a certain Index
list.add(2, "Two and a Half");

//Revoce Element by Index Number
list.remove(list.size()-2);

//Remove Element by supplying the Object
list.remove("Five");

//Retrieve Elements in the Array List
for(int i = 0; i < list.size(); i ++)
System.out.println(list.get(i));

//Search for a certain Element Index
System.out.println("Two is at position: "+list.indexOf("Two"));

}
}