package com;
import java.awt.Button;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.WindowConstants; /*
* 连接设备的JPanel类
*/
public class Monkey_run {
MonkeySql monkeySql = new MonkeySql();
public Monkey_run() {
JFrame jFrame= new JFrame("monkey可视化操作工具");
Container container = jFrame.getContentPane();
container.setLayout(null);
try {
container.add(new P1().P1_Connect_the_device());
container.add(new P2_log_Detail_level().P2_log_Detail_level());
container.add(new P3_delay().P3_delay());
container.add(new P4_Constraint_package().P4_Constraint_package());
container.add(new P5_Run_times().P5_Run_times());
container.add(new P6_log_save().P6_log_save());
container.add(new P7_Start_and_finish().P7_Start_and_finish());
container.add(P9_Chart_switch());
container.add(new P10_getPackage().P10_getPackage());
jFrame.setVisible(true);
jFrame.setSize(800, 800);
jFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}catch(Exception e) {
e.printStackTrace();
}
}
public JPanel P9_Chart_switch() throws InterruptedException {
JPanel p9 = new JPanel();
p9.setBorder(BorderFactory.createTitledBorder("图表开关"));
p9.setBounds(15, 700, 200, 50);
JButton jButton = new JButton("log");
jButton.setBounds(15, 30, 50, 50);
jButton.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
try {
new P8("ID").setVisible(true);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} }
});
p9.add(jButton);
return p9;
}
public static void main(String [] agrs) {
new Monkey_run(); } }
package com;

import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField; public class P1 extends MonkeySql{
MonkeySql monkey_data = new MonkeySql();
public JPanel P1_Connect_the_device(){
StringBuffer stringBuffer = new StringBuffer();
JPanel p1 = new JPanel();
p1.setLayout(null);
p1.setBorder(BorderFactory.createTitledBorder("连接设备"));
p1.setBounds(15, 1, 750, 70);
JTextField jTextField = new JTextField(1);
jTextField.setBounds(30, 25, 300, 30);
JRadioButton Write = new JRadioButton("写入");
Write.setBounds(350, 30, 70, 25);
Write.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String aString = jTextField.getText();
monkey_data.setmonkey_array("-s "+aString, 1); }
});
JRadioButton Clear = new JRadioButton("清除");
Clear.setBounds(420, 30, 70, 25);
Clear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
jTextField.setText("");
jTextField.requestFocus();
monkey_data.setmonkey_array("", 1);
}
});
Button Device_ID = new Button("Device_ID");
JTextArea jTextArea = new JTextArea();
jTextArea.setLineWrap(true);
Device_ID.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
Process process=Runtime.getRuntime().exec("cmd /c adb devices");
InputStream pInputStream =process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(pInputStream));
StringBuffer sBuffer = new StringBuffer();
String ID ="";
while((ID = br.readLine()) != null ) {
if (ID.endsWith("device")) {
sBuffer.append(ID);
int size=sBuffer.lastIndexOf("ice");
sBuffer.insert(size+3, "\n");
sBuffer.replace(size-3, size+3, "");
jTextArea.setText(sBuffer.toString()); } }
process.waitFor();
br.close();
pInputStream.close();
}catch(IOException e1) {
e1.printStackTrace(); } catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
Device_ID.setBounds(480, 15, 70, 50);
jTextArea.setBounds(560, 15, 180, 50);
p1.add(jTextArea);
p1.add(Device_ID);
p1.add(Write);
p1.add(Clear);
p1.add(jTextField);
ButtonGroup group = new ButtonGroup();
group.add(Write);
group.add(Clear);
return p1;
} }
package com;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JRadioButton; public class P2_log_Detail_level {
MonkeySql monkeySql = new MonkeySql();
public JPanel P2_log_Detail_level() {
JPanel p2 = new JPanel();
p2.setBorder(BorderFactory.createTitledBorder("log详细级别"));
p2.setBounds(15, 72, 350, 70);
p2.setLayout(null);
String value [] = {"空","一级","二级","三级"};
JComboBox<String> group = new JComboBox<>(value);
group.setBounds(50, 25, 200, 35);
group.addItemListener(new ItemListener() { @Override
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
if(group.getSelectedItem().equals("空")) {
monkeySql.setmonkey_array("", 5); }else if(group.getSelectedItem().equals("一级")){
System.out.println("一级");
monkeySql.setmonkey_array("-v", 5); }else if (group.getSelectedItem().equals("二级")) {
System.out.println("二级");
monkeySql.setmonkey_array("-v -v", 5); }else if(group.getSelectedItem().equals("三级")) {
System.out.println("三级");
monkeySql.setmonkey_array("-v -v -v", 5); } }
});
/*JRadioButton v1 = new JRadioButton("1级");
JRadioButton v2 = new JRadioButton("2级");
JRadioButton v3 = new JRadioButton("3级");
JRadioButton cancel = new JRadioButton("取消");
v1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
monkeySql.setmonkey_array("-v", 5);
}
});
v2.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
monkeySql.setmonkey_array("-v -v", 5); }
});
v3.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
monkeySql.setmonkey_array("-v -v -v", 5); }
});
cancel.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
monkeySql.setmonkey_array("", 3); }
});
ButtonGroup group = new ButtonGroup();
group.add(v1);
group.add(v2);
group.add(v3);
group.add(cancel);
*/
//p2.add(v1);
//p2.add(v2);
//p2.add(v3);
//p2.add(cancel);
p2.add(group);
return p2;
} }

package com;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter; import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField; public class P3_delay {
MonkeySql monkeySql = new MonkeySql();
public JPanel P3_delay() {
JPanel p3 = new JPanel();
p3.setLayout(null);
p3.setBorder(BorderFactory.createTitledBorder("执行间隔时间"));
p3.setBounds(380, 72, 385, 70);
JTextField jTextField = new JTextField(1);
jTextField.setBounds(10, 25, 150, 30);
JRadioButton Write = new JRadioButton("写入");
Write.setBounds(165, 15, 55, 50);
JRadioButton Clear = new JRadioButton("清除");
Clear.setBounds(216, 15, 55, 50);
Write.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String Value = jTextField.getText();
monkeySql.setmonkey_array(" --throttle "+Value, 6); }
});
Clear.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
jTextField.setText("");
monkeySql.setmonkey_array("", 6); }
}); ButtonGroup group = new ButtonGroup();
group.add(Write);
group.add(Clear);
p3.add(Write);
p3.add(Clear);
p3.add(jTextField);
return p3; } }

package com;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random; import javax.net.ssl.SSLException;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.xml.xpath.XPath; import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.DataUtilities;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
public class P8 extends JPanel{
private static Thread thread;
public P8(String AA) throws InterruptedException {
JFrame jFrame = new JFrame(AA);
Container container = jFrame.getContentPane();
container.add(p8_log());
jFrame.setVisible(true);
jFrame.setSize(1000, 600);
jFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); }
public ChartPanel p8_log() throws InterruptedException {
ChartPanel framel;
JFreeChart jfreechart = ChartFactory.createLineChart("ID",
"Type",
"Value",
createDataset(),
PlotOrientation.VERTICAL,
true,
true,
false);
framel= new ChartPanel(jfreechart,true);
framel.setBounds(15, 15, 750, 300);;
jfreechart.setBackgroundPaint(Color.white);
CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
categoryplot.setBackgroundPaint(Color.lightGray);
categoryplot.setRangeGridlinePaint(Color.white);
NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
numberaxis.setAutoRangeIncludesZero(true);
//获得renderer 注意这里是下嗍造型到lineandshaperenderer!!
LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer)categoryplot.getRenderer();
lineandshaperenderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {6F, 6F}, 0.0F)); //定义series为”Second”的(即series2)点之间的连线
lineandshaperenderer.setSeriesStroke(2, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {2.0F, 6F}, 0.0F)); //定义series为”Third”的(即series3)点之间的连线
return framel; }
public static CategoryDataset createDataset() throws InterruptedException {
DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
thread = new Thread(new Runnable() { @Override
public void run() {
// TODO Auto-generated method stub
while(true) {
try {
Process process=Runtime.getRuntime().exec("cmd /c adb shell dumpsys cpuinfo");
InputStream pInputStream =process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(pInputStream));
StringBuffer sBuffer = new StringBuffer();
String ID ="";
while((ID = br.readLine()) != null ) {
if (ID.endsWith("TOTAL")) {
sBuffer.append(ID);
int size=sBuffer.lastIndexOf("ice");
sBuffer.insert(size+3, "\n");
sBuffer.replace(size-3, size+3, ""); } } }catch(IOException e1) {
e1.printStackTrace(); }
Date date = new Date();
String hour =String.format("%tH", date);
String minute =String.format("%tM", date);
String second =String.format("%tS", date);
String time1 = hour+minute+second;
sleep(2000);
Random random = new Random();
int randNum = random.nextInt(10);
defaultCategoryDataset.addValue(randNum, "A",time1);
sleep(1000);
int randNum2 = random.nextInt(10);
defaultCategoryDataset.addValue(randNum2, "B",time1);
sleep(1000);
int randNum3 = random.nextInt(10);
defaultCategoryDataset.addValue(randNum3, "C",time1); } }
});
thread.start(); return defaultCategoryDataset; }
public static void sleep(int time) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }

Java swing 代码例子的更多相关文章

  1. Java Swing类 例子代码:将子类继承JFrame 并且接口按键监听ActionLisetener (将内容直接添加到JFrame不创建Contaniner)

    package rom; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import ...

  2. Java Swing 使用总结(转载)

    随笔转载自:此去经年ぢ 地址:http://www.cnblogs.com/FLFL/p/5369756.html 1.     GUI编程引言 以前的学习当中,我们都使用的是命令交互方式: 例如:在 ...

  3. java swing 添加 jcheckbox复选框

    总体上而言,Java Swing编程有两大特点:麻烦.效果差. 麻烦是说由于设计器的使用不方便(如果您希望使用窗体设计器通过快速拖拽控件建立您的Java Swing GUI程序,请您使用MyEclip ...

  4. Java swing: 实现ActionListener监听器的三种途径

    Swing是目前Java中不可缺少的窗口工具组,是用户建立图形化用户界面(GUI)程序的 强大工具.Java Swing组件自动产生各种事件来响应用户行为.如当用户点击按钮或选择菜单项目时,Swing ...

  5. Atitit。D&D drag&drop拖拽功能c#.net java swing的对比与实现总结

    Atitit.D&D drag&drop拖拽功能c#.net java swing的对比与实现总结 1. 实现一个D&D操作一般包括三个步骤: 1 2. .net黑头的拖曳机制 ...

  6. 恶补Java Swing线程刷新UI机制(由浅到深的参考大佬博文)

    1. java中进度条不能更新问题的研究 感谢大佬:https://blog.csdn.net/smartcat86/article/details/2226681 为什么进度条在事件处理过程中不更新 ...

  7. Java Swing 第03记 布局管理器

    几种Swing常用的布局管理器 BorderLaout 它将容器分为5个部分,即东.南.西.北.中,每一个区域可以容纳一个组件,使用的时候也是通过BorderLayout中5个方位常量来确定组件所在的 ...

  8. Java swing项目-图书管理系统(swing+mysql+jdbc) 总结

    (一)java Swing的学习. (1)学习如何安装windowbuilder插件的安装. <1>在eclipse中点击help <2>在help的下拉选中选择install ...

  9. 【小型系统】抽奖系统-使用Java Swing完成

    一.需求分析 1. 显示候选人照片和姓名. 2. 可以使用多种模式进行抽奖,包括一人单独抽奖.两人同时抽奖.三人同时抽奖. 3. 一个人可以在不同的批次的抽奖中获取一.二.三等奖,但是不能在同一批次抽 ...

随机推荐

  1. DeviceIoControl 驱动交互

    驱动程序通信的函数,除了ReadFile和WriteFile函数还有DeviceIoControl函数,而且DeviceIoControl函数那是相当的彪悍.因为它可以自定义控制码,你只要在IRP_M ...

  2. Tensorflow安装环境更新

    本博文是对前面两篇tensorflow的博文的一个继续,对环境的更新. 基于tensorflow的MNIST手写识别 安装tensorflow,那叫一个坑啊 主要出发点: 上述两篇博文的程序运行的环境 ...

  3. 多wan示意图

    此时计算机的网关可以任意选择其中的一台路由器的ip地址.

  4. springboot学习心得

    1.mvn package --加载运行一个含有pom.xml的目录并生成target目录2.mvn dependency:tree 显示项目所有依赖的树状结构3.业务委托给了Spring Boot的 ...

  5. 未找到路径“/Agent/SissQrTemplate/AddN”的控制器或该控制器未实现 IController。

    未找到路径“/Agent/SissQrTemplate/AddN”的控制器或该控制器未实现 IController. Controller 命名空间错误,应该是Areas.Agent.Controll ...

  6. 【转】[Android] NDK独立编译——独立工具链

    转载地址:https://blog.csdn.net/suningning/article/details/74510125

  7. PureMVC剖析

    http://www.cnblogs.com/skynet/archive/2013/01/29/2881244.html http://hi.baidu.com/mmforever/item/408 ...

  8. vc++获取网页源码之使用import+智能指针包装类

    创建基于对话框的mfc应用程序 使用智能指针包装类IWinHttpRequestptr,它内部采用的是引用计数来管理对象的生命周期 代码: #import "C:\\Windows\\Sys ...

  9. 数据库SQL语言学习--上机练习2(连接查询 嵌套查询)

    上机练习2 1.              启动SQL Server 2008中的 SQL Server Management Studio. 2.              针对下面三张基本表进行操 ...

  10. centos6.9发送邮件功能

    centos6.9发送邮件功能       第一个里程碑 测试发邮件的功能 系统环境centos 6.9     #配置发邮件 /etc/mail.rc中追加 set bsdcompat set fr ...