1186 Java Utilities Package and Bit Manipulation Chapter (Medical web site)

1186 Java Utilities Package and Bit Manipulation Chapter 20 27 container.add( valueField ); 28 29 valueField.addActionListener( 30 31 new ActionListener() { 32 33 // read value and display its bitwise representation 34 public void actionPerformed( ActionEvent event ) 35 { 36 int value = Integer.parseInt( valueField.getText() ); 37 bitsField.setText( getBits( value ) ); 38 } 39 } 40 ); 41 42 // textfield to display bitwise representation of an integer 43 bitsField = new JTextField( 33 ); 44 bitsField.setEditable( false ); 45 container.add( bitsField ); 46 47 // button to shift bits left by one position 48 JButton leftButton = new JButton( “<<" ); 49 50 leftButton.addActionListener( 51 52 new ActionListener() { 53 54 // left shift one position and display new value 55 public void actionPerformed( ActionEvent event ) 56 { 57 int value = Integer.parseInt( valueField.getText() ); 58 value <<= 1; 59 valueField.setText( Integer.toString( value ) ); 60 bitsField.setText( getBits( value ) ); 61 } 62 } 63 ); 64 65 container.add( leftButton ); 66 67 // button to right shift value one position with sign extension 68 JButton rightSignButton = new JButton( ">>” ); 69 70 rightSignButton.addActionListener( 71 72 new ActionListener() { 73 74 // right shift one position and display new value 75 public void actionPerformed( ActionEvent event ) 76 { 77 int value = Integer.parseInt( valueField.getText() ); 78 value >>= 1; 79 valueField.setText( Integer.toString( value ) ); Fig. 20.11 Fig. 20.11 Demonstrating the bitwise shift operators (part 2 of 5).
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Leave a Reply