Code Examples
A repository of 155 code examples for BeepBeep
GetValueSlider.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.functions.ApplyFunction;
22 import ca.uqac.lif.cep.io.Print;
23 import ca.uqac.lif.cep.widgets.GetWidgetValue;
24 import ca.uqac.lif.cep.widgets.ListenerSource;
25 import java.awt.Component;
26 import javax.swing.BorderFactory;
27 import javax.swing.BoxLayout;
28 import javax.swing.JFrame;
29 import javax.swing.JLabel;
30 import javax.swing.JPanel;
31 import javax.swing.JSlider;
32 
33 /**
34  * Get the value of a Swing widget and use it as a source of events.
35  * @author Sylvain HallĂ©
36  */
37 public class GetValueSlider
38 {
39  public static void main(String[] args)
40  {
41  ///
42  JFrame frame = new JFrame("My Widget Frame");
43  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
44  JPanel panel = new JPanel();
45  panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
46  JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 30);
47  slider.setMajorTickSpacing(20);
48  slider.setPaintTicks(true);
49  slider.setPaintLabels(true);
50  JLabel slider_label = new JLabel("Value", JLabel.CENTER);
51  slider_label.setAlignmentX(Component.CENTER_ALIGNMENT);
52  panel.add(slider_label);
53  panel.add(slider);
54  panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
55  frame.add(panel);
56  frame.pack();
57  frame.setVisible(true);
58  ///
59 
60  //!
61  ListenerSource ls = new ListenerSource();
62  slider.addChangeListener(ls);
63  ApplyFunction gwv = new ApplyFunction(GetWidgetValue.instance);
64  Connector.connect(ls, gwv);
65  Print print = new Print();
66  Connector.connect(gwv, print);
67  //!
68  }
69 }
Get the value of a Swing widget and use it as a source of events.