标签:java
1. import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Menu; import java.awt.MenuBar; import java.awt.MenuItem; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class Test { public static void main (String[] args){ final JFrame test= new JFrame(); //test.setSize(300,100); test.setLayout(new FlowLayout(FlowLayout.LEFT)); JPanel pan1 = new JPanel(new GridLayout(5,1)); JLabel lab1 = new JLabel("十进制"); final JTextField text1 = new JTextField("-1",32); JLabel lab2 = new JLabel("二进制"); final JTextField text2 = new JTextField("11111111111111111111111111111111",32); JLabel lab3 = new JLabel("八进制"); final JTextField text3 = new JTextField("37777777777",32); JLabel lab4 = new JLabel("十六进制"); final JTextField text4 = new JTextField("ffffffff",32); final JButton but1 = new JButton("转换"); but1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == but1) { int n = Integer.parseInt(text1.getText()); text2.setText(Integer.toBinaryString(n)); text3.setText(Integer.toOctalString(n)); text4.setText(Integer.toHexString(n)); } } }); pan1.add(lab1); pan1.add(text1); pan1.add(lab2); pan1.add(text2); pan1.add(lab3); pan1.add(text3); pan1.add(lab4); pan1.add(text4); test.add(pan1); test.add(but1); test.setVisible(true); test.pack(); } }
本文出自 “hacker” 博客,请务必保留此出处http://anglecode.blog.51cto.com/5628271/1619875
标签:java
原文地址:http://anglecode.blog.51cto.com/5628271/1619875