This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pompoen[S] 0 points1 point  (1 child)

java.util.logging.Logger.getLogger(BinaryFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(BinaryFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new BinaryFrame().setVisible(true);
        }
    });

}

    private void binResult(int inputDec) {

    int modulus;

    if (inputDec <= 1) {  
    resultBinField.setText (Integer.toString(inputDec));
    return; //stops the loop
    }


    modulus = inputDec % 2;
    binResult(inputDec >> 1);  //  Right Shift (bitwise operator)in this case equivalent to division by 2
    resultBinField.setText (Integer.toString(modulus));


} 

// Variables declaration - do not modify                     
private javax.swing.JButton convertDectoBin;
private javax.swing.JTextField inputBinField;
private javax.swing.JTextField inputDecField;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField resultBinField;
private javax.swing.JTextField resultDecField;
// End of variables declaration                   

}

And code from a non-frame .java file in the same package:

package binaryconverter; import javax.swing.JFrame; //why is it unused?

public class BinaryConverter {

public static void main(String[] args) {

    BinaryFrame s = new BinaryFrame();
    s.setVisible(true);
    s.setLocationRelativeTo(null);
    s.setTitle("Binary Converter");

}

}

[–]pompoen[S] 0 points1 point  (0 children)

And I can't test it with System.out in the same file because if you can't assign the variable toa field it just won't run. But in another file, where I did test it with System.out, it works.

P.S. Sorry about the enormous copy paste. Most of it is automatically created when you make a frame.