buttons

buttons - CSc 2700: Lecture # 15 Part 2 Buttons October 21,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSc 2700: Lecture # 15 Part 2 Buttons October 21, 2008 1 Buttons Buttons come in all shapes, sizes, and colors. Some display images and others text. Buttons generate action events and a ”button listener” might send a document to a printer, copy or paste text, save a fle, open a fle, or change a Font style. And those are just a Few actions related to a word processor. There are Exit buttons, Go buttons, Submit buttons, Clear buttons and Resume buttons. Buttons are part most GUI programs. Here are the basics oF the JButton class: Class: JButton Generates: ActionEvent Listener: Must implement ActionListener Listener method to implement: void actionPerformed( ActionEvent e) Register a listener: void AddActionListener(ActionEvent e) Constructors: JButton() instantiates a JButton object that displays neither text nor image. JButton(String text) instantiates a JButton object that displays text. JButton(Icon icon) instantiates a JButton object that displays an image; can be invoked as JButton button( new ImageIcon(String flename)), where flename is the name oF a graphic fle such as ”zap.giF.” JButton(String text, Icon icon) instantiates a JButton object that displays text and as well as an image. 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Some JButton Methods: public void setHorizontalAlignment(int alignment) sets the horizontal alignment of the text and/or image on the button. The alignment parameter is a Swing constant: SwingConstants.LEFT (numerical value: 2) SwingConstants.RIGHT (numerical value: 4, default) SwingConstants.CENTER (numerical value: 0) public int getHorizontalAlignment() returns the horizontal alignment. public void setVerticalAlignment(int alignment)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/06/2009 for the course CSC 2700 taught by Professor Duncan during the Spring '08 term at LSU.

Page1 / 6

buttons - CSc 2700: Lecture # 15 Part 2 Buttons October 21,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online