Code Examples
A repository of 155 code examples for BeepBeep
ListenerSourceExample.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2018 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package widgets;
19 
20 import ca.uqac.lif.cep.Connector;
21 import ca.uqac.lif.cep.io.Print;
22 import ca.uqac.lif.cep.widgets.ListenerSource;
23 import java.awt.Component;
24 import javax.swing.BorderFactory;
25 import javax.swing.BoxLayout;
26 import javax.swing.JFrame;
27 import javax.swing.JLabel;
28 import javax.swing.JPanel;
29 import javax.swing.JSlider;
30 
31 /**
32  * Wrap a Swing widget into a BeepBeep event <tt>Source</tt>.
33  * @author Sylvain HallĂ©
34  */
36 {
37  public static void main(String[] args)
38  {
39  ///
40  JFrame frame = new JFrame("My Widget Frame");
41  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
42  JPanel panel = new JPanel();
43  panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
44  JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 30);
45  slider.setMajorTickSpacing(20);
46  slider.setPaintTicks(true);
47  slider.setPaintLabels(true);
48  JLabel slider_label = new JLabel("Value", JLabel.CENTER);
49  slider_label.setAlignmentX(Component.CENTER_ALIGNMENT);
50  panel.add(slider_label);
51  panel.add(slider);
52  panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
53  frame.add(panel);
54  frame.pack();
55  frame.setVisible(true);
56  ///
57 
58  //!
59  ListenerSource ls = new ListenerSource();
60  slider.addChangeListener(ls);
61  Print print = new Print();
62  Connector.connect(ls, print);
63  //!
64  }
65 }
Wrap a Swing widget into a BeepBeep event Source.