Code Examples
A repository of 155 code examples for BeepBeep
SetValueSlider.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.Pushable;
21 import ca.uqac.lif.cep.widgets.WidgetSink;
22 import java.awt.Component;
23 import javax.swing.BorderFactory;
24 import javax.swing.BoxLayout;
25 import javax.swing.JFrame;
26 import javax.swing.JLabel;
27 import javax.swing.JPanel;
28 import javax.swing.JSlider;
29 
30 /**
31  * Set the value of a widget using a stream of events.
32  */
33 public class SetValueSlider
34 {
35  public static void main(String[] args) throws InterruptedException
36  {
37  JPanel panel = new JPanel();
38  panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
39  JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 30);
40  slider.setMajorTickSpacing(20);
41  slider.setPaintTicks(true);
42  slider.setPaintLabels(true);
43  JLabel slider_label = new JLabel("Value", JLabel.CENTER);
44  slider_label.setAlignmentX(Component.CENTER_ALIGNMENT);
45  panel.add(slider_label);
46  panel.add(slider);
47  panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
48  JFrame frame = new JFrame("My Widget Frame");
49  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
50  frame.add(panel);
51  frame.pack();
52  frame.setVisible(true);
53 
54  //!
55  WidgetSink ws = new WidgetSink(slider);
56  Pushable p = ws.getPushableInput();
57  for (int i = 10; i <= 100; i+= 10)
58  {
59  p.push(i);
60  Thread.sleep(1000);
61  }
62  //!
63  }
64 }
Set the value of a widget using a stream of events.