获取02字段与85字段
2014-05-16 17:07
204 查看
测试字段:"02 0A B8 47 F1 CD 6E 01 06 00 86 2F 09 02 0A B8 47 F1 E8 69 01 00 00 85 1F 1E 02 0A B8 47 F1 55 AC 01 00 00 84 29 51 02 0A B8 47 F1 CD 6E 01 06 00 86 06 20 02 0A B8 47 F1 E8 69 01 00 00 85 1E 1F “
代码如下:
效果如下:
![](http://img.blog.csdn.net/20140516181402015?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc2FucWltYQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
可以看到以“85”开头的酒精传感器字段,
其中,第一行只是标题,从第二开始才是真正的酒精传感器数据,用红框框画出的数据是电压的模拟值,本例中电压的模拟值分别为1F、1E,对应十进制的31、30。
代码如下:
package cn.ch.da; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.border.TitledBorder; import javax.swing.JScrollPane; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.UIManager; public class StringLinewrap extends JFrame { private JPanel contentPane; private JTextArea sourceTextArea; private JTextArea destinationTextArea; private JTextArea destinationTextArea2; /** * Launch the application. */ public static void main(String[] args) { try { UIManager .setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (Throwable e) { e.printStackTrace(); } EventQueue.invokeLater(new Runnable() { public void run() { try { StringLinewrap frame = new StringLinewrap(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public StringLinewrap() { setTitle("根据字段02对字符串进行分行"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 475, 660); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel label = new JLabel( "<html>在下面的文本框中输入字符串段落,其中要包括(02)字段,然后单击“分行显示”按钮,程序将根据(02)字段进行分行。</html>"); label.setBorder(new TitledBorder(null, "说明", TitledBorder.LEADING, TitledBorder.TOP, null, null)); label.setBounds(10, 10, 439, 76); contentPane.add(label); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(10, 84, 439, 98); contentPane.add(scrollPane); sourceTextArea = new JTextArea(); sourceTextArea.setLineWrap(true); scrollPane.setViewportView(sourceTextArea); JButton button = new JButton("分行显示"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { do_button_actionPerformed(e); } }); JButton button2 = new JButton("酒精传感器"); button2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { do_button_actionPerformed2(e); } }); button.setBounds(80, 192, 101, 25); button2.setBounds(210, 192, 101, 25); contentPane.add(button); contentPane.add(button2); JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setBounds(10, 233, 439, 156); contentPane.add(scrollPane_1); destinationTextArea = new JTextArea(); scrollPane_1.setViewportView(destinationTextArea); JScrollPane scrollPane_2 = new JScrollPane(); scrollPane_2.setBounds(10, 390, 439, 156); contentPane.add(scrollPane_2); destinationTextArea2 = new JTextArea(); scrollPane_2.setViewportView(destinationTextArea2); } protected void do_button_actionPerformed(ActionEvent e) { String sourceString = sourceTextArea.getText();// 获取用户输入字段 String[] lines = sourceString.split("02");// 根据“02字段”分割字符串为数组 StringBuilder sbuilder = new StringBuilder();// 创建字符串构建器 for (String line : lines) {// 遍历分割后的字符串数组 // 把每个数组元素的字符串与回车符相连并添加到字符串构建器中 sbuilder.append("02"+line + "\n"); } // 把字符串添加到换行显示字符串的文本域中 destinationTextArea.setText(sbuilder.toString()); } protected void do_button_actionPerformed2(ActionEvent e){ String destinon2String = sourceTextArea.getText(); //String tou="02",wei="85"; String[] lines = destinon2String.split("85"); StringBuilder sbuilder2 = new StringBuilder(); for (String line : lines) {// 遍历分割后的字符串数组 // 把每个数组元素的字符串与回车符相连并添加到字符串构建器中 //if() sbuilder2.append("85"+line + "\n"); } // 把字符串添加到换行显示字符串的文本域中 destinationTextArea2.setText(sbuilder2.toString()); } }
效果如下:
可以看到以“85”开头的酒精传感器字段,
其中,第一行只是标题,从第二开始才是真正的酒精传感器数据,用红框框画出的数据是电压的模拟值,本例中电压的模拟值分别为1F、1E,对应十进制的31、30。
相关文章推荐
- 获取02字段(第二篇)
- ASP获取数据库表名,字段名以及对字段的一些操作
- 蛙蛙推荐:怎样获取一个表中所有字段的信息
- 获取数据库中用户表,表中的字段名及类型
- 获取数据库表名和字段
- asp.net获取SQL所有数据库名、所有表名、所有字段名
- 获取SqlServer 2000中字段的备注信息--downmoon
- 获取一个数据表中某个字段的所有值
- 获取数据表中某字段唯一值
- Delphi中如何点击DBgrid中的一行,而获取选中行的各字段的值
- 获取IE的HTTP RequestHeader的Accept字段的内容
- 获取表的字段列表
- ASP获取数据库表名,字段名以及对字段的一些操作
- 获取所有用户表及根据表Id取得表字段信息
- Ajax获取数据库中的字段
- 获取SAP表字段说明
- 获取SAP表字段说明
- 获取M$ SQL Server用户表的字段信息
- sql server获取表的所有字段
- 偏方获取水晶报表特殊字段(TotalPageCount)的值