1 / 20

Specialised Components

Specialised Components. Can create specialised components. Do this by subclassing the component that you are interested in. It now looks and behaves like we want. This subclass has all the properties of its superclass along with the extra’s we’ve added. We can now re-use this component!

luke-ware
Download Presentation

Specialised Components

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Specialised Components Can create specialised components. Do this by subclassing the component that you are interested in. It now looks and behaves like we want. This subclass has all the properties of its superclass along with the extra’s we’ve added. We can now re-use this component! • can create multiple instances of it • can subclass it SE204:2004/2005: Lecture 3

  2. SE204:2004/2005: Lecture 3

  3. We can now place this in a frame, in an applet, or any other higher-level container! SE204:2004/2005: Lecture 3

  4. Other Component Methods setVisible(boolean b) • can be called on any component • it makes the component visible or invisible setEnable(boolean b) • can be used to disable a component, it cannot receive user input • most components when disabled change their appearance SE204:2004/2005: Lecture 3

  5. Laying out components Can place components in containers by • use of absolute position and size co-ordinates • use of layout managers The arrangement of several components in a container iscalled a layout. SE204:2004/2005: Lecture 3

  6. Laying out components There are a number of predefined layout classes • FlowLayout • BorderLayout • GridLayout • GridBagLayout • CardLayout These all implement the LayoutManager interface SE204:2004/2005: Lecture 3

  7. Using Layouts Set the layout of the container by invoking the setLayout() method. This method accepts as a parameter an instance of a class that implements the layout manager interface. SE204:2004/2005: Lecture 3

  8. Border Layout • This allows you to place components in five different regions in the container - North, South, East, West and Center. • You specify the position of each component when adding it to the container. SE204:2004/2005: Lecture 3

  9. Border Layout Constructors BorderLayout() -- creates a new border layout BorderLayout(int hGap, int vGap) -- creates a new border layout with the specified horizontal and vertical gaps SE204:2004/2005: Lecture 3

  10. SE204:2004/2005: Lecture 3

  11. SE204:2004/2005: Lecture 3

  12. Flow Layout • This allows any number of components in a container. • It arranges the components from left to right in a row. When that row is full, it will begin a new row. SE204:2004/2005: Lecture 3

  13. Flow Layout Constructors FlowLayout() -- creates a new flow layout with centered alignment. FlowLayout(int alignment) -- creates a new flow layout with the specified alignment. FlowLayout(int alignment, int hGap, int vGap) --creates a new flow layout with the specified alignment and horizontal and vertival gaps. SE204:2004/2005: Lecture 3

  14. SE204:2004/2005: Lecture 3

  15. SE204:2004/2005: Lecture 3

  16. Grid Layout • This allows you to lay out components in a grid of rows and columns. SE204:2004/2005: Lecture 3

  17. Grid Layout Constructors GridLayout(int rows, int cols) -- creates a new grid layout with the specified number of rows and columns GridLayout(int rows, int cols, int hGap, int vGap) -- creates a new grid layout with the specified number of rows and columns and specified horizontal and vertical gaps SE204:2004/2005: Lecture 3

  18. SE204:2004/2005: Lecture 3

  19. SE204:2004/2005: Lecture 3

  20. Other Layouts • There are other layouts available • These include CardLayout, BoxLayout SE204:2004/2005: Lecture 3

More Related