Samreen Dhillon - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Samreen Dhillon

Description:

Widget Toolkit for Java. Provides GUI to java programs. Lightweight. More sophisticated GUI components than AWT. Pluggable look and feel itself draws the GUI ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 10
Provided by: colu82
Category:

less

Transcript and Presenter's Notes

Title: Samreen Dhillon


1
COMS W3137 RecitationFebruary 20 08
  • Samreen Dhillon

2
Agenda
  • Java Swings
  • GUI components
  • DisplaySimpleTree.java(http//www1.cs.columbia.edu
    /allen/S08/NOTES/DisplaySimpleTree.java)
  • GUI components used
  • Tree routines
  • Algorithm

3
Java Swings
  • Widget Toolkit for Java
  • Provides GUI to java programs
  • Lightweight
  • More sophisticated GUI components than AWT
  • Pluggable look and feel itself draws the GUI
    components
  • MVC (Model View Controller) architecture

4
GUI Components
  • JFrame
  • Extension of java.awt.Frame
  • ContentPane - should contain all non-menu items
  • frame.getContentPane().add(child)
  • ContentPane is never null
  • setDefaultCloseOperation()
  • pack()

public class DisplaySimpleTree extends JFrame
5
GUI Components
  • JPanel
  • PaintComponent(Graphics g)
  • Revalidate() update the panel
  • Graphics
  • Draw on components
  • drawString()
  • g.drawString("Binary Search tree for the input
    string\n",xs,ys)
  • drawLine()
  • g.drawLine(dx,dy,dx2,dy2)

6
Binary Tree
  • Tree routines
  • insert () insert a node into the tree
  • treeHeight () - calculate the tree height
  • inorder_traversals ()
  • why do we need this?

class MyTree MyTree() public int
treeHeight(Node t) public int max(int a, int
b) public void computeNodePositions()
public void inorder_traversal(Node t, int
depth) public Node insert(Node root, String
s) // Binary Search tree insert
Explain the code
7
Displaying the tree
ys
SCREENHEIGHT
SCREENWIDTH
8
Algorithm
  • Read data from text file r f g t h y b v c
  • Insert each element into the binary tree
  • Compute node positions (using inorder traversal
    and height information)
  • JPanel displays the string that we input
  • JPanel draws the filled Tree
  • drawTree()

Explain the code
9
HW1 Solutions
Write a Comment
User Comments (0)
About PowerShow.com