Sams Teach Yourself Java in 21 Days by Rogers Cadenhead

Sams Teach Yourself Java in 21 Days by Rogers Cadenhead

Author:Rogers Cadenhead [Cadenhead, Rogers]
Language: eng
Format: epub
Tags: Computers & Technology, Programming, Introductory & Beginning, Languages & Tools, Java, Beginner's Guides, Software Design; Testing & Engineering, Object-Oriented Design, Computer Science, Programming Languages, Reference
ISBN: 9780672335747
Amazon: 0672335743
Publisher: Sams Publishing
Published: 2012-08-27T00:00:00+00:00


* * *

1: import java.awt.event.*;

2: import javax.swing.*;

3: import java.awt.*;

4:

5: public class TitleChanger extends JFrame implements ActionListener {

6: JButton b1;

7: JButton b2;

8:

9: public TitleChanger() {

10: super("Title Bar");

11: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

12: setLookAndFeel();

13: b1 = new JButton("Rosencrantz");

14: b2 = new JButton("Guildenstern");

15: b1.addActionListener(this);

16: b2.addActionListener(this);

17: FlowLayout flow = new FlowLayout();

18: setLayout(flow);

19: add(b1);

20: add(b2);

21: pack();

22: setVisible(true);

23: }

24:

25: public void actionPerformed(ActionEvent evt) {

26: Object source = evt.getSource();

27: if (source == b1) {

28: setTitle("Rosencrantz");

29: } else if (source == b2) {

30: setTitle("Guildenstern");

31: }

32: repaint();

33: }

34:

35: private void setLookAndFeel() {

36: try {

37: UIManager.setLookAndFeel(

38: "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"

39: );

40: SwingUtilities.updateComponentTreeUI(this);

41: } catch (Exception exc) {

42: System.err.println("Couldn't use the system "

43: + "look and feel: " + exc);

44: }

45: }

46:

47: public static void main(String[] arguments) {

48: TitleChanger frame = new TitleChanger();

49: }

50: }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.