import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; public class Twoscomplement extends JApplet { JTextField inputField; JTextField input32Field; JLabel errorLabel; public void init() { Container container = getContentPane(); int panelRowsSize = 3; container.setLayout( new GridLayout( panelRowsSize, 1 ) ); JPanel [] panelRows = new JPanel[panelRowsSize]; for (int i=0; i=0; i--) result += ((num>>i) & 1); input32Field.setText( "" + result ); } } } ); errorLabel = new JLabel( "" ) ; errorLabel.setFont( bigFont ); panelRows[2].add( errorLabel ); JLabel input32Label = new JLabel( "32 bits" ); input32Label.setFont( bigFont ); panelRows[1].add( input32Label ); input32Field = new JTextField( 32 ); input32Field.setFont( bigFont ); panelRows[1].add( input32Field ); input32Field.addActionListener( new ActionListener () { public void actionPerformed( ActionEvent event ) { errorLabel.setText( "" ); String input= input32Field.getText(); if ( input.length() != 32 ) { errorLabel.setText( "Must be 32 bits" ); inputField.setText( "" ); } else { char c; int num = 0; for (int i=31; i>=0; i--) { c = input.charAt( 31-i ); if ( c!='0' && c!='1') { errorLabel.setText( "Must be 32 bits" ); inputField.setText( "" ); return; } int j = c=='0' ? 0 : 1; num = (j<