IST 256
Fall 2011
Programming Examples

Programming Examples about Forms or Data Structures
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.
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 JDialog. The example shows how the main form can put and get data into and from the second form by accessing its public class variables.
Programming Examples to get Data for Projects
These examples show how to use RSS feeds to get data: Earthquakes and Sports News
This example shows how to get data from the Twitter API, using a hashtag topic to get current and popular tweets.