JFC 2 - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

JFC 2

Description:

JFC 2. Revenge of the Swing. More Input, Please. What about creating large text areas for typing in descriptions, notes, etc? ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 12
Provided by: ftn1
Category:
Tags: jfc | revenge

less

Transcript and Presenter's Notes

Title: JFC 2


1
JFC 2
  • Revenge of the Swing

2
More Input, Please
  • What about creating large text areas for typing
    in descriptions, notes, etc? Or, for displaying
    large sections of text?
  • Enter the JTextArea widget
  • See TextAreaWidget.java

3
Custom Cell Rendering
  • How can we change the color, font, etc of items
    that are displayed in a list? This is handled by
    another STRATEGY pattern object in swing, called
    the ListCellRenderer. The Cell Renderer is a
    class that tells the entries in the list how to
    format themselves
  • See CellRender.java

4
May I see the menu?
  • In my discussion of the JFrame container, I
    mentioned that among other things, it can contain
    a Menu bar. How, precisely, do we get this menu
    bar in place, and how do we make it work?
  • See MenuBarDemo.java

5
Check Please!
  • JCheckBox is another handy widget to get user
    input.
  • Although it is a button, and thus inherits the
    buttons ability to be clicked, it is primarily
    used in conjunction with another button or input
    method, like the text box.
  • See CheckBoxDemo.java

6
Graphical Alerts
  • How do you relay errors to the user in a GUI
    system?
  • You could have a text area that lists out status
    messages, but this takes up real estate, and is
    usually ugly.
  • The most common method is to pop up an error
    dialog.
  • See DialogDemo.java

7
Lets see some progress
  • Sometimes, a program will need to perform
    operations that are very time consuming.
  • Users hate waiting more than .02 seconds for
    anything to happen
  • Sometimes, the distraction of a pretty graphic
    letting them know that its working solves the
    problem.
  • See ProgressBarDemo.java

8
The raw deal
  • So far, we have looked at some of the swing
    toolkits many pre-defined widgets for creating
    graphical user interfaces.
  • Sooner or later, you will want to do something
    that doesnt have a widget
  • Java also allows you to draw your own widgets, by
    using the graphics primitives.

9
Where do I draw?
  • Theoretically, you can override the paint method
    of any component. This is a very bad idea,
    unless you know exactly what you are doing.
    Since you are creating a new component of your
    very own, you want to start at the base of the
    swing object hierarchy, with a JComponent.

10
How do I draw?
  • Override the PaintComponent(Graphics g) method,
    and go to town.
  • See DrawDemo.java

11
Wow, that was lame.
  • True. Most components that you are going to
    create yourself will have more complicated
    behavior than just drawing some shapes and
    calling it quits. Often this behavior will
    depend on user input. So, how do you capture
    user input in a GUI?
  • The mouse, silly.
  • See DrawDemo2.java
Write a Comment
User Comments (0)
About PowerShow.com