51,411
社区成员
发帖
与我相关
我的任务
分享

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.FlowLayout;
public class 说明 {
JFrame frame;
private JTextField txtlogo;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private DySwingChart panel1;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
说明 window = new 说明();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public 说明() {
initialize();
// MyThread mythread = new MyThread();
// mythread.start();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
txtlogo = new JTextField();
txtlogo.setText("说明及LOGO");
txtlogo.setBounds(6, 6, 97, 26);
frame.getContentPane().add(txtlogo);
txtlogo.setColumns(10);
JButton button = new JButton("运行");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MyThread mythread = new MyThread();
mythread.start();
String Btn = button.getText();
if(Btn.equals("暂停"))
{
mythread.toSuspend();
button.setText("继续");
}else{
mythread.toResume();
button.setText("暂停");
}
}
});
button.setBounds(302, 6, 117, 29);
frame.getContentPane().add(button);
textField_1 = new JTextField();
textField_1.setText("操作说明");
textField_1.setBounds(301, 84, 130, 159);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
panel1=new DySwingChart();
panel1.chartPanel.setBounds(6,46,251,211);
frame.getContentPane().add(panel1.chartPanel);
JButton button_1 = new JButton("返回");
button_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
UI window = new UI();
window.frame.setVisible(true);
frame.dispose();
}
});
button_1.setBounds(302, 243, 117, 29);
frame.getContentPane().add(button_1);
JButton button_3 = new JButton("结束");
button_3.setBounds(302, 57, 117, 29);
frame.getContentPane().add(button_3);
JLabel label = new JLabel("速率:");
label.setBounds(115, 11, 39, 16);
frame.getContentPane().add(label);
textField = new JTextField();
textField.setBounds(151, 6, 106, 26);
frame.getContentPane().add(textField);
textField.setColumns(10);
}
class MyThread extends Thread{
private boolean suspend = false;
public synchronized void toSuspend(){
suspend = true;
}
public synchronized void toResume(){
notify();//当前等待的线程继续执行
suspend = false;
}
public void run() {
int i=0;
while (true) {
// synchronized (this) {
// while(suspend){
// try {
// wait();//让线程进入等待状态
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
double factor=-500 + 1000 * Math.random();
DySwingChart.xyseries.add(i, factor);
try {
Thread.currentThread();
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
i++;
}
}
}
}
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.awt.Window;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;
import java.awt.Color;
import javax.swing.JTextField;
public class UI {
JFrame frame;
private JTextField txtlogo;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UI window = new UI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public UI() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new GridLayout(0, 1, 0, 0));
JPanel panel = new JPanel();
frame.getContentPane().add(panel);
panel.setLayout(null);
JTextArea textArea = new JTextArea();
textArea.setBounds(126, 11, 0, 16);
panel.add(textArea);
JButton btnNewButton_1 = new JButton("平衡模式");
btnNewButton_1.setBounds(169, 95, 96, 29);
btnNewButton_1.setBackground(Color.WHITE);
btnNewButton_1.setForeground(Color.DARK_GRAY);
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
panel.add(btnNewButton_1);
JButton btnNewButton = new JButton("监测模式");
btnNewButton.setBounds(169, 136, 96, 29);
btnNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
说明 window1 = new 说明();
window1.frame.setVisible(true);
frame.dispose();
}
});
panel.add(btnNewButton);
JButton button = new JButton("说明及版本号");
button.setBounds(161, 243, 117, 29);
panel.add(button);
JLabel lbllogo = new JLabel("产品名称及LOGO");
lbllogo.setBounds(161, 26, 109, 48);
panel.add(lbllogo);
}
}
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.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;
import org.jfree.ui.RefineryUtilities;
public class DySwingChart extends JComponent {
private static final long serialVersionUID = 4540402465397663673L;
public JPanel chartPanel;
public DySwingChart() {
super();
//setContentPane();
chartPanel = createDemoPanel();
}
public static XYSeries xyseries;
public XYSeriesCollection createDataset1() {
xyseries = new XYSeries("折线图");
XYSeriesCollection xyseriescollection = new XYSeriesCollection();
xyseriescollection.addSeries(xyseries);
return xyseriescollection;
}
public JFreeChart createChart() {
XYDataset xydataset = createDataset1();
JFreeChart jfreechart = ChartFactory.createXYLineChart(
"变化", "时间", "值", xydataset,
PlotOrientation.VERTICAL, false, true, false);
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
numberaxis.setAutoRangeIncludesZero(true);
NumberAxis x=(NumberAxis)xyplot.getDomainAxis();
x.setLabel("时间");
x.setAutoRange(true);
return jfreechart;
}
public void dynamicRun() {
int i=0;
while (true) {
double factor=-500 + 1000 * Math.random();
xyseries.add(i, factor);
try {
Thread.currentThread();
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
i++;
}
}
public JPanel createDemoPanel() {
JFreeChart jfreechart = createChart();
return new ChartPanel(jfreechart);
}
// public static void main(String args[]) {
// JFrame.setDefaultLookAndFeelDecorated(true);
// DySwingChart annotationdemo2 = new DySwingChart(
// "动态折线图");
// annotationdemo2.pack();
// annotationdemo2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// RefineryUtilities.centerFrameOnScreen(annotationdemo2);
// annotationdemo2.setVisible(true);
// annotationdemo2.dynamicRun();
// }