HangMan....
Transcript: JTextFields, JButtons and Tool Tips JTextField - component a user can type a single line of text data JButtons - component used to trigger an action or make a selection when the user clicks it Tool Tips - pop up windows to help users understand ✳✱* A label is an uneditable component that is most often used provide information for a user. You can add(), remove(), setText(), setFont() JLabels More.... Utilizing the GUI in Java LayoutManager When you use swing components, you usually place them in a container. A container is a type of component that allows you to group items together and interact with them as one entity. Containers are defined in the Container class. A container can be either a window or a frame. A frame is preferred because it has a title bar and border. It also has several methods that can be used. A JFrame has multiple constructors: JFrame() JFrame(String title) JFrame(GraphicsConfiguration fc) JFrame (String title, GraphicsConfiguration fc) Event occurs when a user takes action Event-driven program - multiple events A component triggered is the source of the event An object interested in an event is a listener If you want an object to be a listener you have to register the object java.awt.event - prepares class to accept event messages event handler is a method waiting to react when an event is generated Setting Up GUI.... JCheckBox - consists of a label positioned beside a square you can click ButtonGroup - javax.swing package, allows you to group components JComboBox - A combo box is a component that combines a button or editable field and a drop down list Don't Forget... There are many types of constructors for JLabel. JLabel() JLabel(Icon image) JLabel(Icon image, int horizontalAlignment) JLabel(String text) JLabel(String text, Icon image, int horizontalAlignment) JLabel(String text, int horizontalAlignment) Event-Driven Programming Objectives : Light weight components that do not rely on local operating system. Include: JButton, JLabel Use: import javax.swing.*; When placing multiple components in a container, you must use the LayoutManager, if not the compenents are placed in the same region and hide each other. Flow Layout Manager - put components in a row When you extend your class with JFrame, you are turning your original class into a child class and utilizing the parent class. This is an example of inheritance. Inheritance enables one class to acquire all the behaviors and attributes of another class. Base Class - original class (aka Super Class or Parent Class) Derived Class - the class extending (aka subclass or child class) Utilize Java Classes like JFrame and JLabel Understand Swing components Identify string data problems Use Character and String class methods Use the StringBuilder and StringBuffer classes Containers Swing Components More Components Working with JLabels JFrame Extending the JFrame Add library: import java.awt.*; After you initiate a JFrame you must do the following: setVisible(true); give it a size - setSize(WIDTH, HEIGHT); give it a title on construction - JFrame aFrame = new JFrame ("Title Here"); Don't forget the x in javax when y import Swing Don't forget to use JFrame's setVisible to make JFrame visible Don't forget to use setLayout() when adding multiple components Don't forget to call validate() or repaint() after you add or remove a compenent after making them visible Don't forget that creating a ButtonGroup does not cause components to be groups, they must be added to group Don't forget that the ButtonGroup class does not begin with a J.