標籤: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() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (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 9-1