Skip to content

Commit e981111

Browse files
committed
minor update
1 parent 7262fdc commit e981111

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.swing.JMenuItem;
2626
import javax.swing.JOptionPane;
2727
import javax.swing.JTextField;
28+
import javax.imageio.ImageIO;
2829
import javax.swing.JButton;
2930
import javax.swing.JCheckBox;
3031
import javax.swing.JTextPane;
@@ -33,9 +34,14 @@
3334
import javax.swing.JMenu;
3435
import java.awt.event.KeyAdapter;
3536
import java.awt.event.KeyEvent;
37+
import java.awt.image.BufferedImage;
38+
import java.io.File;
39+
import java.io.IOException;
3640
import java.util.ArrayList;
3741
import java.util.List;
3842
import java.awt.Canvas;
43+
import java.awt.Graphics2D;
44+
import java.awt.Image;
3945

4046
public 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

Comments
 (0)