Chapter 20 Java Utilities (Web design software) Package and Bit Manipulation
Chapter 20 Java Utilities Package and Bit Manipulation 1177 7 8 // Java extension packages 9 import javax.swing.*; 10 11 public class PrintBits extends JFrame { 12 private JTextField outputField; 13 14 // set up GUI 15 public PrintBits() 16 { 17 super( “Printing bit representations for numbers” ); 18 19 Container container = getContentPane(); 20 container.setLayout( new FlowLayout() ); 21 22 container.add( new JLabel( “Enter an integer ” ) ); 23 24 // textfield to read value from user 25 JTextField inputField = new JTextField( 10 ); 26 27 inputField.addActionListener( 28 29 new ActionListener() { 30 31 // read integer and get bitwise representation 32 public void actionPerformed( ActionEvent event ) 33 { 34 int value = Integer.parseInt( 35 event.getActionCommand() ); 36 outputField.setText( getBits( value ) ); 37 } 38 } 39 ); 40 41 container.add( inputField ); 42 43 container.add( new JLabel( “The integer in bits is” ) ); 44 45 // textfield to display integer in bitwise form 46 outputField = new JTextField( 33 ); 47 outputField.setEditable( false ); 48 container.add( outputField ); 49 50 setSize( 720, 70 ); 51 setVisible( true ); 52 } 53 54 // display bit representation of specified int value 55 private String getBits( int value ) 56 { 57 // create int value with 1 in leftmost bit and 0s elsewhere 58 int displayMask = 1 << 31; 59 Fig. 20.6Printing the bits in an integer (part 2 of 3). Fig. 20.6
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision professional web hosting services