/./././././././././ # ButtonExample.java Uses the following classes: * CloseableFrame.java * FgReporter.java * BgReporter.java * SizeReporter.java ****************** ButtonExample.java ****************** import java.awt.*; import java.awt.event.*; /././././././././././ public class ButtonExample extends CloseableFrame { public static void main(String[] args) { new ButtonExample(); } public ButtonExample() { super("Using ActionListeners"); setLayout(new FlowLayout()); Button b1 = new Button("Button 1"); Button b2 = new Button("Button 2"); Button b3 = new Button("Button 3"); b1.setBackground(Color.lightGray); b2.setBackground(Color.gray); b3.setBackground(Color.darkGray); FgReporter fgReporter = new FgReporter(); BgReporter bgReporter = new BgReporter(); SizeReporter sizeReporter = new SizeReporter(); b1.addActionListener(fgReporter); b2.addActionListener(fgReporter); b2.addActionListener(bgReporter); b3.addActionListener(fgReporter); b3.addActionListener(bgReporter); b3.addActionListener(sizeReporter); add(b1); add(b2); add(b3); setSize(350, 100); setVisible(true); } } /./././././././././ FgReporter.java *************** import java.awt.event.*; import java.awt.*; /././././././././././ public class FgReporter implements ActionListener { public void actionPerformed(ActionEvent event) { Component c = (Component)event.getSource(); System.out.println("Foreground: " + c.getForeground()); } } **************** BgReporter.java **************** /././././././././ import java.awt.event.*; import java.awt.*; /././././././././././././ public class BgReporter implements ActionListener { public void actionPerformed(ActionEvent event) { Component c = (Component)event.getSource(); System.out.println("Background: " + c.getBackground()); } } /././././././././././ SizeReporter.java *********************** import java.awt.event.*; import java.awt.*; /././././././././ public class SizeReporter implements ActionListener { public void actionPerformed(ActionEvent event) { Component c = (Component)event.getSource(); Dimension d = c.getSize(); System.out.println("Size: " + d.width + "x" + d.height); } } ********************
Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10334
Categories:Programming Code Examples, Java/J2EE/J2ME, AWT Components
Tags:Java/J2EE/J2MEAWT Components
Post Data:2017-01-02 16:04:35
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada