Package Gui

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

package gui_1;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.util.Timer;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
import javax.swing.plaf.basic.BasicArrowButton;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class GUI_DrawThreshold extends JFrame implements ActionListener {

private XYSeries series;


public int n_points = 512;
public double[] y_of_x, x;
public int thre_UP_DOWN = 0;
private final ValueAxis domainAxis;
private boolean startStop;
public int cpt = 0;
public int cptMin = 0;

public GUI_DrawThreshold() {
series = new XYSeries("Random Data");
XYDataset dataset = new XYSeriesCollection(series);
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(700, 500));
chart.setBackgroundPaint(Color.white);

XYPlot plot = chart.getXYPlot();


//AXE DES X
domainAxis = plot.getDomainAxis();
domainAxis.setAutoRange(false);
domainAxis.setRange(0, 512);
if (domainAxis instanceof NumberAxis) {
NumberAxis axisX = (NumberAxis) domainAxis;
axisX.setAutoRangeIncludesZero(true);
axisX.setTickUnit(new NumberTickUnit(50, new DecimalFormat("0")));
}

//AXE DES Y
ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setAutoRange(false);
rangeAxis.setRange(-10, 10);
rangeAxis.setFixedDimension(15.0);//décalage vers la droite
if (rangeAxis instanceof NumberAxis) {
NumberAxis axisY = (NumberAxis) rangeAxis;
axisY.setAutoRangeIncludesZero(true);
axisY.setTickUnit(new NumberTickUnit(1, new DecimalFormat("0")));
}

JFrame aWindow = new JFrame("Digital Oscilloscope");


aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Channel A
Box channel_A = Box.createVerticalBox();
channel_A.setBorder(BorderFactory.createTitledBorder("Channel A"));
Box trigger = Box.createVerticalBox();
BasicArrowButton up = new BasicArrowButton(BasicArrowButton.NORTH);
up.setActionCommand("UP");
up.addActionListener(this);

BasicArrowButton down = new BasicArrowButton(BasicArrowButton.SOUTH);


down.setActionCommand("DOWN");
down.addActionListener(this);

JButton button = new JButton("Start/Stop");


button.setActionCommand("START");
button.addActionListener(this);

trigger.add(up);
trigger.add(down);
trigger.add(button);

Box trigger_ful = Box.createHorizontalBox();


trigger_ful.add(new JLabel(" Set Threshold "));
trigger_ful.add(trigger);

channel_A.add(new JCheckBox("Show real-time trace"));


channel_A.add(Box.createVerticalStrut(30));
channel_A.add(trigger_ful);

JSlider vPositionA = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);


vPositionA.setBorder(BorderFactory.createTitledBorder("Vertical Position"));
vPositionA.setMajorTickSpacing(20);
vPositionA.setMinorTickSpacing(5);
vPositionA.setPaintTicks(true);
vPositionA.setPaintLabels(true);

JSlider vRangeA = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);


vRangeA.setBorder(BorderFactory.createTitledBorder("Vertical Range"));
vRangeA.setMajorTickSpacing(20);
vRangeA.setMinorTickSpacing(5);
vRangeA.setPaintTicks(true);
vRangeA.setPaintLabels(true);

channel_A.add(vPositionA);
channel_A.add(vRangeA);

// Creating Channel B
Box channel_B = Box.createVerticalBox();
channel_B.setBorder(BorderFactory.createTitledBorder("Channel B"));
channel_B.add(Box.createVerticalStrut(30));
channel_B.add(new JCheckBox("Show real-time trace"));
channel_B.add(Box.createVerticalStrut(30));

JSlider vPositionB = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);


vPositionB.setBorder(BorderFactory.createTitledBorder("Vertical Position"));
vPositionB.setMajorTickSpacing(20);
vPositionB.setMinorTickSpacing(5);
vPositionB.setPaintTicks(true);
vPositionB.setPaintLabels(true);

JSlider vRangeB = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);


vRangeB.setBorder(BorderFactory.createTitledBorder("Vertical Range"));
vRangeB.setMajorTickSpacing(20);
vRangeB.setMinorTickSpacing(5);
vRangeB.setPaintTicks(true);
vRangeB.setPaintLabels(true);

channel_B.add(vPositionB);
channel_B.add(vRangeB);

//Creating Trigger Mode


Box triggerMode = Box.createVerticalBox();
triggerMode.setBorder(BorderFactory.createTitledBorder("Trigger Mode"));
ButtonGroup radioGroup1 = new ButtonGroup();
JRadioButton Auto = new JRadioButton("Auto");
JRadioButton Normal = new JRadioButton("Normal");
JRadioButton Single = new JRadioButton("Single");
radioGroup1.add(Auto);
radioGroup1.add(Normal);
radioGroup1.add(Single);
//triggerMode.add(Box.createVerticalStrut(5));
triggerMode.add(Auto);
triggerMode.add(Normal);
triggerMode.add(Single);
triggerMode.add(Box.createVerticalStrut(10));

// Creating Trigger Slop


Box triggerSlop = Box.createVerticalBox();
triggerSlop.setBorder(BorderFactory.createTitledBorder("Trigger Slop"));
ButtonGroup radioGroup2 = new ButtonGroup();
JRadioButton risingEdge = new JRadioButton("Rising Edge");
JRadioButton fallingEdge = new JRadioButton("Falling Edge");
radioGroup2.add(risingEdge);
radioGroup2.add(fallingEdge);
//triggerSlop.add(Box.createVerticalStrut(10));
triggerSlop.add(risingEdge);
triggerSlop.add(fallingEdge);
triggerSlop.add(Box.createVerticalStrut(10));

//Creating sampling changing combo box


Box sampling = Box.createVerticalBox();
sampling.setBorder(BorderFactory.createTitledBorder("Time Per Div"));
JComboBox pick = new JComboBox();
pick.addItem("2 ms/div");
pick.addItem("5 ms/div");
pick.addItem("10 ms/div");
pick.addItem("20 ms/div");
pick.addItem("50 ms/div");
pick.setEditable(false);
pick.setSelectedItem("2 ms/div");
sampling.add(pick);

//combining the trigger mode, tigger slop and sampling


Box tiggerMS = Box.createVerticalBox();
//tiggerMS.add(Box.createVerticalStrut(200));
tiggerMS.add(triggerMode);
tiggerMS.add(Box.createVerticalStrut(5));
tiggerMS.add(triggerSlop);
tiggerMS.add(Box.createVerticalStrut(5));
tiggerMS.add(sampling);

// combining triggerMS , channel_A and channel_B


Box chAB_tri = Box.createHorizontalBox();
chAB_tri.add(tiggerMS);
chAB_tri.add(Box.createHorizontalStrut(5));
chAB_tri.add(channel_A);
chAB_tri.add(Box.createHorizontalStrut(5));
chAB_tri.add(channel_B);

Box top = Box.createVerticalBox();


top.add(chartPanel);
top.add(Box.createVerticalStrut(5));
top.add(chAB_tri);

Container content = aWindow.getContentPane();


content.setLayout(new BorderLayout());

content.add(top, BorderLayout.CENTER);
aWindow.pack();
aWindow.setVisible(true);

aWindow.pack();
aWindow.setVisible(true);

private static JFreeChart createChart(XYDataset dataset) {


JFreeChart chart = ChartFactory.createXYLineChart(
"XY Series Demo",
"X",
"Y",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false);
return chart;
}

public void actionPerformed(ActionEvent event) {


if (event.getActionCommand().equals("UP")) {

if (thre_UP_DOWN < 11) {


y_of_x = new double[512];
x = new double[512];
series.clear();

thre_UP_DOWN++;
for (int i = 0; i < 512; i++) {
y_of_x[i] = thre_UP_DOWN;
series.add((double) i, y_of_x[i]);

}
}

if (event.getActionCommand().equals("DOWN")) {

if (thre_UP_DOWN > (-11)) {


y_of_x = new double[512];
x = new double[512];
series.clear();

thre_UP_DOWN--;
for (int i = 0; i < 512; i++) {
y_of_x[i] = thre_UP_DOWN;
series.add((double) i, y_of_x[i]);

}
}

int integer = thre_UP_DOWN;


String hexstr = Integer.toString(thre_UP_DOWN, 16);
System.out.println(hexstr);

public static void main(String[] args) {

new GUI_DrawThreshold();

}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy