Your SlideShare is downloading. ×
Graphic Programming
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Graphic Programming

126
views

Published on

Published in: Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
126
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. JFrame ClassThe JFrame class is slightly incompatible with Frame. Like all other JFC/Swing top-levelcontainers, a JFrame contains a JRootPane as its only child. The content pane provided by theroot pane should, as a rule, contain all the non-menu components displayed by the JFrame.This is different from the AWT Frame case. As a conveniance add and its variants, removeand setLayout have been overridden to forward to the contentPane as necessary. This meansyou can write: frame.add(child);The JFrame class have a lot of methods. Method Name Description showConfirmDialog Asks a confirming question, like yes/no/cancel. showInputDialog Prompt for some input. showMessageDialog Tell the user about something that has happened. showOptionDialog The Grand Unification of the above three.Parameters:The parameters to these methods follow consistent patterns:parentComponent: Defines the Component that is to be the parent of this dialog box. It is used in two ways: the Frame that contains it is used as the Frame parent for the dialog box, and its screen coordinates are used in the placement of the dialog box. In general, the dialog box is placed just below the component. This parameter may be null, in which case a default Frame is used as the parent, and the dialog will be centered on the screen (depending on the L&F).message: A descriptive message to be placed in the dialog box. In the most common usage, message is just a String or String constant. However, the type of this parameter is actually Object. Its interpretation depends on its type: Object[] An array of objects is interpreted as a series of messages (one per object) arranged in a vertical stack. The interpretation is recursive -- each object in the array is interpreted according to its type. Component
  • 2. The Component is displayed in the dialog. Icon The Icon is wrapped in a JLabel and displayed in the dialog. others The object is converted to a String by calling its toString method. The result is wrapped in a JLabel and displayed.messageType: Defines the style of the message. The Look and Feel manager may lay out the dialog differently depending on this value, and will often provide a default icon. The possible values are: ERROR_MESSAGE INFORMATION_MESSAGE WARNING_MESSAGE QUESTION_MESSAGE PLAIN_MESSAGEoptionType: Defines the set of option buttons that appear at the bottom of the dialog box: DEFAULT_OPTION YES_NO_OPTION YES_NO_CANCEL_OPTION OK_CANCEL_OPTION You arent limited to this set of option buttons. You can provide any buttons you want using the options parameter.options: A more detailed description of the set of option buttons that will appear at the bottom of the dialog box. The usual value for the options parameter is an array of Strings. But the parameter type is an array of Objects. A button is created for each object depending on its type: Component The component is added to the button row directly. Icon A JButton is created with this as its label. other The Object is converted to a string using its toString method and the result is used to label a JButton.icon: A decorative icon to be placed in the dialog box. A default value for this is determined by the messageType parameter.title: The title for the dialog box.
  • 3. initialValue: The default selection (input value).When the selection is changed, setValue is invoked, which generates a PropertyChangeEvent.If a JOptionPane has configured to all input setWantsInput the bound propertyJOptionPane.INPUT_VALUE_PROPERTY can also be listened to, to determine when the user hasinput or selected a value.When one of the showXxxDialog methods returns an integer, the possible values are: YES_OPTION NO_OPTION CANCEL_OPTION OK_OPTION CLOSED_OPTIONJOptionPane JOptionPane.showConfirmDialog() :
  • 4. JOptionPane.showMessageDialog() :JOptionPane.showInputDialog() ;
  • 5. JOptionPane.showOptionDialog() :JCheckBox
  • 6. JPanel ClassThe JPanel class provides general-purpose containers for lightweight components. Bydefault, panels do not add colors to anything except their own background; however, youcan easily add borders to them and otherwise customize their painting.Setting the Layout ManagerLike other containers, a panel uses a layout manager to position and size its components.By default, a panels layout manager is an instance of FlowLayout, which places the panelscontents in a row. You can easily make a panel use any other layout manager by invokingthe setLayout method or by specifying a layout manager when creating the panel. The latterapproach is preferable for performance reasons, since it avoids the unnecessary creationof a FlowLayout object.Here is an example of how to set the layout manager when creating the panel.JPanel p = new JPanel(new BorderLayout()); //PREFERRED!This approach does not work with BoxLayout, since the BoxLayout constructor requires a pre-existing container. Here is an example that uses BoxLayout.JPanel p = new JPanel();p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
  • 7. Adding ComponentsWhen you add components to a panel, you use the add method. Exactly which argumentsyou specify to the add method depend on which layout manager the panel uses. When thelayout manager is FlowLayout, BoxLayout, GridLayout, or SpringLayout, you will typically use theone-argument add method, like this:aFlowPanel.add(aComponent);aFlowPanel.add(anotherComponent);When the layout manager is BorderLayout, you need to provide an argument specifying theadded components position within the panel. For example:aBorderPanel.add(aComponent, BorderLayout.CENTER);aBorderPanel.add(anotherComponent, BorderLayout.PAGE_END);With GridBagLayout you can use either add method, but you must somehow specify grid bagconstraints for each component.

×