XML HTML Swing An Overview Inf 141 Information

  • Slides: 16
Download presentation
XML, HTML & Swing An Overview Inf 141 Information Retrieval Winter 2007

XML, HTML & Swing An Overview Inf 141 Information Retrieval Winter 2007

XML • General purpose mark-up language • Extensible because it allows users to define

XML • General purpose mark-up language • Extensible because it allows users to define their own elements – • Example: <start></start> Follows a tree-like structure – Must have exactly one root element

XML • Levels of correctness – Well-formed: if u start with a statement you

XML • Levels of correctness – Well-formed: if u start with a statement you must end with a statement or it will not be parsed • • • – Example: <start> blah </start> Element names are case sensitive <start /> Valid: conforms to semantic rules (either user defined or schema included) • Example: if a document contains an undefined element, then it is not valid and will not be parsed

HTML Predominant markup language for web pages. It provides a means to describe the

HTML Predominant markup language for web pages. It provides a means to describe the structure of textbased information in a document — by denoting certain text as headings, paragraphs, lists, and so on — and to supplement that text with interactive forms, embedded images, and other objects.

HTML • Elements are the basic structure – Properties: • Attributes – contained in

HTML • Elements are the basic structure – Properties: • Attributes – contained in the start label – <font size = “ 8”></font> • Content - located between the labels – <p> hello </p> • Types of markup – Structural: describes purpose; most browsers have formatting standards • Example: – <h 2></h 2> – Presentational: describes appearance • Example: – <strong> bold </strong> – <em> italics </em> – Hypertext: links to other documents or pages • Example: – <a href="http: //en. wikipedia. org/">Wikipedia</a> • Stylesheets may be created and accessed to maintain formatting across pages

HTML Must start with a document type which determines which rendering mode to use

HTML Must start with a document type which determines which rendering mode to use HTML documents transmitted from a web server to a web browser for viewing

Swing • GUIs are layed out as trees • There is a toplevel container,

Swing • GUIs are layed out as trees • There is a toplevel container, usually a window – Inside this are multiple panels (often invisible), used to control layout • Swing: Java’s GUI programming toolkit

Swing

Swing

Common Swing Widgets • JFrames, JPanels • Layout Managers • JLists • JButtons •

Common Swing Widgets • JFrames, JPanels • Layout Managers • JLists • JButtons • JLabels, JText. Fields, JText. Areas

Swing: JFrames and JPanels • JFrames are top-level windows • JPanels allow grouping of

Swing: JFrames and JPanels • JFrames are top-level windows • JPanels allow grouping of other widgets • Each JFrame has a panel into which the frame’s contents must go: the content. Pane – window = swing. JFrame(”Frame. Demo”) – window. content. Pane. add(new JButton()) • You must pack and show a JFrame to display it – window. pack() – window. show()

Swing: Layout Managers • Layout Managers control the placement of widgets in a JPanel

Swing: Layout Managers • Layout Managers control the placement of widgets in a JPanel • Simplest by far: awt. Border. Layout – window. content. Pane. layout = awt. Border. Layout() – window. content. Pane. add(”Center”, swing. JButton(”Button 2 (CENTER)”)) • Five regions: – North, South: expand horizontally – East, West: expand vertically – Center: expands in both directions

Swing: JLists • JLists are collections of widgets – list = swing. JList() •

Swing: JLists • JLists are collections of widgets – list = swing. JList() • Put JLists in a JScroll. Pane to make them scrollable – window. content. Pane. add(swing. JScroll. Pane(list)) • JLists contain a list. Data member with the contents – list. Data = [’January’, ‘February’, ‘March’, . . . ] • selected. Value contains the selected item! – >>> print list. selected. Value – ‘March’

Swing: JButtons • JButtons have many fancy features. . . – Images, labels, tooltips,

Swing: JButtons • JButtons have many fancy features. . . – Images, labels, tooltips, etc. • Basic use is very simple: – Supply a label when you construct the button • button = swing. JButton(”This is my label!”) • Provide a function to use as a callback – button. action. Performed = some. Callback

Swing: JText. Fields, JText. Areas, and JLabels • JLabels are the world’s simplest widgets

Swing: JText. Fields, JText. Areas, and JLabels • JLabels are the world’s simplest widgets – years = swing. JLabel(”Years”) • JText. Fields are used for single-line text entry – year. Value = swing. JText. Field() – print year. Value. text • JText. Areas are used for longer pieces of text – area = swing. JText. Area(24, 80)

Resources • XML: – Wikipedia – Tutorial: http: //www. w 3 schools. com/xml/default. asp

Resources • XML: – Wikipedia – Tutorial: http: //www. w 3 schools. com/xml/default. asp – inside out: http: //www. xml. com/ • HTML: – Wikipedia – Tutorial: http: //www. w 3 schools. com/html/default. asp • Swing: – Wikipedia – JComponent Class: http: //java. sun. com/docs/books/tutorial/uiswing/components/jcom ponent. html

Questions ?

Questions ?