IST 256
Fall 2011
Programming Examples

Programming Examples
Multiple Forms: This example shows how to create and use a second form. The computation starts with a main form with a second form created as a new JDialogForm. The example shows how the main form can put and get data into and from the second form by accessing its public class variables. The simple example is in the package testforms2.
Alphabetical Sort:
  • The first example shows the code for a bubble sort in the Students example that sorts the name field by alphabetical order, using the compareTo() String comparison function.
  • The second example shows using the built-in sort function of Java, writing a comparator function.
Lists on a form: This example shows how to use a JList on a form, where list elements are shown in a box on the form, and the user may select an item on the list.
ComboBox on a form: This example shows how to use a JComboBox on a form, where only the currently selected item in the list is shown in a box on the form. If the user clicks the triangle, then the entire list is shown and the user may select a different element. This element has essentially the same functionality as a JList, but takes up less room on the form.
Other Form Functionality:
  • This example shows the use of the WindowOpened event to perform initializing computations as the form opens. This could be useful to read an initial data file, for example.
  • This example also shows the use of a JTextArea to get a scrollable box to display text. It also shows the use of \n to get another line and \t to get a column.
Dynamic Images:
  • If you want to have an image loaded into the form during the running of the program, perhaps as a result of the user selection.
Programming Examples to get Data for Projects
These examples show how to use RSS feeds to get data: Earthquakes and Sports News List of RSS Feeds to see more ideas for data, also search for RSS feeds on-line
Social Media APIs: The Twitter API has changed, but this is an old example showing basically what this type of application would look like. If interested, we can provide examples of the new Twitter or other Social Media APIs.