2525import javax .swing .JMenuItem ;
2626import javax .swing .JOptionPane ;
2727import javax .swing .JTextField ;
28+ import javax .imageio .ImageIO ;
2829import javax .swing .JButton ;
2930import javax .swing .JCheckBox ;
3031import javax .swing .JTextPane ;
3334import javax .swing .JMenu ;
3435import java .awt .event .KeyAdapter ;
3536import java .awt .event .KeyEvent ;
37+ import java .awt .image .BufferedImage ;
38+ import java .io .File ;
39+ import java .io .IOException ;
3640import java .util .ArrayList ;
3741import java .util .List ;
3842import java .awt .Canvas ;
43+ import java .awt .Graphics2D ;
44+ import java .awt .Image ;
3945
4046public class SensorMapsExample extends BasicProcessWithCallBack {
4147
@@ -47,14 +53,14 @@ public class SensorMapsExample extends BasicProcessWithCallBack {
4753 static BasicShimmerBluetoothManagerPc btManager = new BasicShimmerBluetoothManagerPc ();
4854 BasicPlotManagerPC plotManager = new BasicPlotManagerPC ();
4955 String btComport ;
50-
56+ final Chart2D mChart = new Chart2D ();
5157 /**
5258 * Initialize the contents of the frame
5359 * @wbp.parser.entryPoint
5460 */
5561 public void initialize () {
5662 frame = new JFrame ("Shimmer SensorMaps Example" );
57- frame .setBounds (100 , 100 , 662 , 591 );
63+ frame .setBounds (100 , 100 , 842 , 591 );
5864 frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
5965 frame .getContentPane ().setLayout (null );
6066
@@ -155,7 +161,7 @@ public void actionPerformed(ActionEvent e) {
155161 frame .getContentPane ().add (plotPanel );
156162 plotPanel .setLayout (null );
157163
158- final Chart2D mChart = new Chart2D ();
164+
159165 mChart .setLocation (12 , 13 );
160166 mChart .setSize (587 , 246 );
161167 plotPanel .add (mChart );
@@ -192,6 +198,22 @@ public void actionPerformed(ActionEvent e) {
192198 btnStopStreaming .setBounds (415 , 181 , 187 , 31 );
193199 frame .getContentPane ().add (btnStopStreaming );
194200
201+ JButton btnTakeSnapshot = new JButton ("Take Snapshot" );
202+ btnTakeSnapshot .addActionListener (new ActionListener () {
203+ public void actionPerformed (ActionEvent arg0 ) {
204+
205+ try {
206+
207+ File outputfile = new File ("saved.png" );
208+ ImageIO .write (mChart .snapShot (), "png" , outputfile );
209+ } catch (IOException e ) {
210+
211+ }
212+ }
213+ });
214+ btnTakeSnapshot .setBounds (625 , 181 , 187 , 31 );
215+ frame .getContentPane ().add (btnTakeSnapshot );
216+
195217 plotManager .setTitle ("Plot" );
196218 }
197219
0 commit comments