Presentation is loading. Please wait.

Presentation is loading. Please wait.

JButton – Container Layout & Icons

Similar presentations


Presentation on theme: "JButton – Container Layout & Icons"— Presentation transcript:

1 JButton – Container Layout & Icons
Jack Tompkins Department of Computer Science

2 JButton Constructor new ImageIcon(imagePath)
JButton​(String text, Icon icon) Creates a button with initial text and an icon. But the Icon is an interface (not instantiable) Icon - All Known Implementing Classes: IconUIResource, ImageIcon,… new ImageIcon(imagePath) Say the component is using a 3x2 GridLayout

3 JButton Container Instantiate the Container (say a JPanel)
Set the Layout Manager Say the component is using a 3x2 GridLayout setLayout(new GridLayout(3,2)); add(new Button("1")); add(new Button("2")); add(new Button("3")); add(new Button("4")); add(new Button("5")); add(new Button("6")); Add the Container to a JFrame

4 addButton(String text, Container container, String imagePath) {
JButton button = null; if (imagePath != null) button = new JButton(text, new ImageIcon(imagePath)); else button = new JButton(text); button.addActionListener(new MyActionListener()); container.add(button); }


Download ppt "JButton – Container Layout & Icons"

Similar presentations


Ads by Google