{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Javaawtcontainer addcomp component component adds a

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: s component. getX() and getY() return the coordinate of the component’s upper-left corner within its parent component. java.awt.Container +add(comp: Component): Component Adds a component to the container. +add(comp: Component, index: int): Component Adds a component to the container with the specified index. Removes the component from the container. +remove(comp: Component): void +getLayout(): LayoutManager +setLayout(l: LayoutManager): void +paintComponents(g: Graphics): void Returns the layout manager for this container. Sets the layout manager for this container. Paints each of the components in this container. The get and set methods for these data fields are provided in the class, but omitted in the UML diagram for brevity. javax.swing.JComponent The tool tip text for this component. Tool tip text is displayed when the mouse points on the component without clicking. EE3206/EE5805 Java Programming & Applications The border for this component. -border: javax.swing.border.Border -toolTipText: String 22 Borders Borders You You can set a border on any object of the JComponent class. Swing has several types of borders. To create a titled border, use new new TitledBorder(String title); To To create a line border, use new new LineBorder(Color color, int width); where width specifies the thickness of the line. For For example, the following code displays a titled border on a panel: JPanel JPanel panel = new JPanel(); panel.setBorder(new panel.setBorder(new TitleBorder(“My Panel”)); EE3206/EE5805 Java Programming & Applications 23 Test Test Swing Common Features Example Component Properties font font background background foreground foreground preferredSize preferredSize minimumSize minimumSize maximumSize maximumSize JComponent Properties toolTipText toolTipText border border TestSwingCommonFeatures Run EE3206/EE5805 Java Programming & Applications 24 Image Image Icons Java Java uses the javax.swing.ImageIcon class to represent an icon. An icon is a fixed-size picture; typically it is small and used to decorate fixedcomponents. Images are normally stored in image files. You You can use new ImageIcon(filename) to construct an image icon. For example, the following statement creates an icon from an image file us.gif in the image directory under the current class path: ImageIcon icon = new ImageIcon("image/us.gif"); TestImageIcon Run EE3206/EE5805 Java Programming & Applications 25...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online