# Decimal to Binary Converter using Java GUI

In this tutorial, i will teach you how to create a program that converts an inputted decimal number into binary using Java GUI. So, now let's start this tutorial! 1. Open JCreator or NetBeans and make a java program with a file name of decToBinary.java. 2. Import javax.swing package. Hence we will use a GUI (Graphical User Interface) here like the inputting the decimal number.
`import javax.swing.*;`
3. Initialize your variables in your Main, variable numInput as string and make it as an inputdialogbox. Variable n as integer that will parse the inputted value of numInput. And variable binary as integer that will hold the binary value of our input.
`        int n;        String numInput;        String binary;        numInput = JOptionPane.showInputDialog(null, "Enter a number:");	n = Integer.parseInt(numInput);`
4. Compute the equivalent binary value of the inputted decimal number.
` binary  = Integer.toBinaryString(n);`
toBinaryString method converts any number into a binary value. 5. Lastly, display the output of the program using JOptionPane.showMessageDialog.
`JOptionPane.showMessageDialog(null, "Binary equivalent is: " +binary);`
Output: Here's the full code of this tutorial:
`import javax.swing.*; public class decToBinary {      public static void main(String[] args) {          int n;        String numInput;        String binary;        numInput = JOptionPane.showInputDialog(null, "Enter a number:");		n = Integer.parseInt(numInput);          binary  = Integer.toBinaryString(n);        JOptionPane.showMessageDialog(null, "Binary equivalent is: " +binary);    } }`
Hope this program helps! :) Best Regards, Engr. Lyndon R. Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware