Collections


Contiguous Arrays

  • Arrays are great for storing data and accessing elements
  • Arrays are stored in contiguous memory
  • Adding and removing elements?
  • Add and remove operations in the middle, or at the beginning can be inefficient
    • Requires element by element copying

Linked Structures

  • Linked data structures are NOT stored in contiguous memory
  • Linked list data structure has a node containing th e value of interest and a reference to the next node
  • Inserting element in the middle does not require a complete reorganization

Java Collections

Using a Set

  • When you don't need to store duplicate items multiple itimes and you don't care what order things are stored in, a Set is a good option
  • Each element can only be added once.

Sorting Set Elements

A hashset order is defined by a hash function and is not related to: The order in which the items are inserted The natural order of the elements

Treeset

Tresset is the same as a hashset, but will return the items in order.

Swing's Event Dispatch Thread (EDT)

  • The Event dispatch thread is the thread of execution in which Swing stuff occurs
  • If your swing event handling code utilizes blocking calls, your GUI can lock up and act oddly

SwingWorker Implementation

  • SwingWorked class in the API allows you to do work in a separate thread of execution
  • To use SwingWorked, develop a clas that etends it

Using SwingWorker

  • Make a new class that extends SwingWorker
  • In the event handling code

Using JList

  • A Jlist is simply a list of items that act as a Swing component
  • Associate a list model with a list for easy modifications on the list

  • DefaultListModel in the API provides useful functiaonlity to moify the List's contents

    • addELement(element)
    • getElementAt(index)
    • removeElementAt(index)
    • etc
  • JList is a Swing component that can be interacted with
    • Select items via click
    • Multi-select via ctr-click( can be set to be single selection only)
    • Functions like:
      • getSelectedIndices

Using a Frame's Content Pane

  • A frame consists of decoraions, borders, and a content pane
  • The content pane is where the window's contents are displayed
  • Jframe comes witha d efault content pane
    • Uses the BorderLayour by default
    • Can use different layout manager via setLayout
  • Rather than add a bunch of components to the frame, can add to a JpPanel, and then replace the fram'e's contents

The Glass Pane

  • The glass pane is another pane that can sit on top of the content pane
  • It is often used to prevent events from being performed on the conetnt pane
  • Set a JFRame's glass pane using setGlassPane

Internal Frames

  • Internal frames, JInternalFrame, can be used to contain multiple farmes inside one overall frame
    • Mos common ctor:
    • JInternalFrame
  • Used in conjunction with a JDesktopPane to contain the internal frames
  • THe JdesktopPane is set to be the content pane for the main frame
  • Good for apps wich need a lot of windwos for control

results matching ""

    No results matching ""