Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Topics on Graphical User Interfaces CardLayout JTabbedPane JFrame.

Similar presentations


Presentation on theme: "Advanced Topics on Graphical User Interfaces CardLayout JTabbedPane JFrame."— Presentation transcript:

1 Advanced Topics on Graphical User Interfaces CardLayout JTabbedPane JFrame

2 CardLayout Layout manager that allows you to group multiple panels but display just one of them at a time How to set it up Suppose p1, p2, p3 are the panels you want to group Create a main panel governed by a CardLayout manager and add p1, p2, p3 as cards to that panel The main panel and the CardLayout object should be defined as fields of the class Call methods on the CardLayout object to cause a particular card to be displayed

3 CardLayout continued Suppose cl is the CardLayout object and mp is the main panel Both of these variables should be defined as fields so they are accessible from init() and actionPerformed() CardLayout methods cl.first( mp ); // displays the first card cl.next( mp ); // displays the next card cl.show( mp, “name” ); // displays the named card

4 JTabbedPane Not a layout manager but a component that also allows you to create many panels but display only one of them at a time Shifting the panel that is displayed done by selecting a tab How to set it up: Create the panels Create a JTabbedPane object Call addTab( “tabname”, panel ) method on that object for each panel to add the panels to the pane

5 JFrame You can create GUIs that are applications (not applets) How to set it up: Extend JFrame instead of JApplet (e.g., … MyFrame extends JFrame … ) Code originally in init() should be placed in the constructor of the class ( e.g., public MyFrame() { …} ) In some main() method, instantiate that class ( e.g., MyFrame f = new MyFrame() ) Need to call some JFrame methods on the object to resize and display the frame

6 JFrame methods f.setSize( width, height ) f. setTitle( string ) f. setVisible( true ) Displays the frame f. setDefaultCloseOperation ( JFrame.CLOSE_ON_EXIT ) So that the x button closes and exits


Download ppt "Advanced Topics on Graphical User Interfaces CardLayout JTabbedPane JFrame."

Similar presentations


Ads by Google