package keshe; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JTextField; import javax.swing.JLabel; public class keshe extends JFrame { private JPanel contentPane; private JTextField textField; private JTextField textField_1; private JTextField textField_2; private JTextField textField_3; private JLabel lblPcm; private JLabel label; private JLabel label_1; private JLabel label_2; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { keshe frame = new keshe(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public keshe() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); textField = new JTextField(); textField.setBounds(96, 25, 212, 21); contentPane.add(textField); textField.setColumns(10); textField_1 = new JTextField(); textField_1.setBounds(96, 56, 212, 21); contentPane.add(textField_1); textField_1.setColumns(10); textField_2 = new JTextField(); textField_2.setBounds(96, 98, 212, 21); contentPane.add(textField_2); textField_2.setColumns(10); textField_3 = new JTextField(); textField_3.setBounds(95, 139, 213, 21); contentPane.add(textField_3); textField_3.setColumns(10); JButton btnNewButton = new JButton("确定"); btnNewButton.addActionListener(new ActionListener() { private String f; public void actionPerformed(ActionEvent e) { int a,b,b1,c1,f,g; StringBuffer d,e1; /*a为输入的初始值,b为a的值取绝对值, b1为段内码的量化间隔所处的位置,c1为极性码,d段落码,e为段内码, f为段内量化间隔,g为量化误差*/ String s1 = textField.getText(); a = Integer.parseInt(s1); if(a>0&a<=2048){ c1=1; } else if(a<0&a>=-2048){ c1=0; } else { c1=9; } b=(int)(Math.sqrt(a*a)); if(b>0&b<=16){ b1=b; d=new StringBuffer("000"); f=1; g=1; } else if(b>16&b<=32){ b1=b-16; d=new StringBuffer("001"); f=1; g=1; } else if(b>32&b<=64){ b1=(b+1)/2-16; d=new StringBuffer("010"); f=2; g=b-30-2*b1; } else if(b>64&b<=128){ b1=(b+3)/4-16; d=new StringBuffer("011"); f=4; g=b-60-4*b1; } else if(b>128&b<=256){ b1=(b+7)/8-16; d=new StringBuffer("100"); f=8; g=b-120-8*b1; } else if(b>256&b<=512){ b1=(b+15)/16-16; d=new StringBuffer("101"); f=16; g=b-240-16*b1; } else if(b>512&b<=1024){ b1=(b+31)/32-16; d=new StringBuffer("110"); f=32; g=b-480-32*b1; } else if(b>1024&b<=2048){ b1=(b+63)/64-16; d=new StringBuffer("111"); f=64; g=b-960-64*b1; } else { b1=0;d=new StringBuffer("错误");f=0;g=0; } int t=b1; if(t==1) e1=new StringBuffer("0000"); else if(t==2) e1=new StringBuffer("0001"); else if(t==3) e1=new StringBuffer("0010"); else if(t==4) e1=new StringBuffer("0011"); else if(t==5) e1=new StringBuffer("0100"); else if(t==6) e1=new StringBuffer("0101"); else if(t==7) e1=new StringBuffer("0110"); else if(t==8) e1=new StringBuffer("0111"); else if(t==9) e1=new StringBuffer("1000"); else if(t==10) e1=new StringBuffer("1001"); else if(t==11) e1=new StringBuffer("1010"); else if(t==12) e1=new StringBuffer("1011"); else if(t==13) e1=new StringBuffer("1100"); else if(t==14) e1=new StringBuffer("1101"); else if(t==15) e1=new StringBuffer("1110"); else if(t==16) e1=new StringBuffer("1111"); else { e1=new StringBuffer("输入数据错误"); } /*System.out.println(""+c1+d+e1); System.out.println(""+f); System.out.println(""+g);*/ textField_1.setText(""+c1+d+e1); textField_2.setText(""+f); textField_3.setText(""+g); } }); btnNewButton.setBounds(41, 200, 156, 52); contentPane.add(btnNewButton); JButton btnNewButton_1 = new JButton("重置"); btnNewButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { textField.setText(""); textField_1.setText(""); textField_2.setText(""); textField_3.setText(""); } }); btnNewButton_1.setBounds(207, 200, 174, 52); contentPane.add(btnNewButton_1); lblPcm = new JLabel("PCM\u7801\u5B50"); lblPcm.setBounds(22, 59, 54, 15); contentPane.add(lblPcm); label = new JLabel("\u91CF\u5316\u95F4\u9694"); label.setBounds(22, 101, 54, 15); contentPane.add(label); label_1 = new JLabel("\u91CF\u5316\u8BEF\u5DEE"); label_1.setBounds(22, 142, 63, 15); contentPane.add(label_1); label_2 = new JLabel("\u8F93\u5165\u6570\u636E"); label_2.setBounds(22, 28, 54, 15); contentPane.add(label_2); } }
通信原理课程设计Javaswing技术计算出PCM编码——猎八哥FLY;此为原创博客,转载请标明出处。