L22 - Computer Science 101 SS C Lecture 22 Contents! 2!...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CompSci 101 - Lecture 22 1 Computer Science 101 SS C Lecture 22 Contents The javax.swing package. Examples of components. The default LayoutManager for a JPanel. Creating and adding JTextField instances to the JPanel. getText(), setText() methods with JTextField objects. Creating & adding JButtons and JLabels to the JPanel. Examples which use the information from JTextFields. Course Book: §15 NOTE: some of the examples and exercise in this lecture are NOT the correct way to handle events. 2 javax.swing package The javax.swing package contains the de±nitions for the JFrame and the JPanel classes. Because JPanels inherit (learn more about this in future courses) from the javax.swing.JComponent class, they contain a paintComponent() method. Because JPanels inherit from java.awt.Container class, other components can be added to JPanels In CS101 examples, the JFrame is the top-level container. JFrame objects have a ContentPane to which we add the JPanel object. 3 Examples of Components The javax.swing package contains the de±nition of the basic components: JButton, JCheckbox, JLabel, JTextField, JTextArea, JPopupMenu. We will be using the components: JLabels, JButtons and JTextFields in our JPanels. 4 FlowLayout LayoutManagers position the components inside the JPanel. The default LayoutManager for a JPanel is FlowLayout. This means that when the components are added to the JPanel they are added from left to right, top to bottom. CS101 uses the default layout manager, FlowLayout. The first component which was added to the JPanel The second component which was added to the JPanel The third component which was added to the JPanel 5 Another Layouts - BorderLayout BorderLayout layout means that when components are added to the JPanel the components are added NORTH, SOUTH, EAST, WEST and CENTER. An example of another layout which can be used when adding components to a JPanel is BorderLayout. We will not be using BorderLayout in CS101 this semester SOUTH CENTER EAST NORTH WEST 6 Components - JTextField In order to use JTextField objects we need to know three things: which instance methods can be used with JTextField instances. how to get these components to appear inside the JPanel window. how to construct JTextField components.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CompSci 101 - Lecture 22 2 7 JTextField - constructors There are several different constructors for JTextField objects.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2012 for the course COMPSCI 101 taught by Professor Adrianaferraro during the Summer '12 term at Auckland.

Page1 / 5

L22 - Computer Science 101 SS C Lecture 22 Contents! 2!...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online