public CalcBTN = new javax.swing.JButton(); Ip1 =

public class Subnet_Calculator extends javax.swing.JFrame {        public Subnet_Calculator() {        initComponents();    }        @SuppressWarnings(“unchecked”)    //                               private void initComponents() {        Root = new javax.swing.JPanel();        TitleContainer = new javax.swing.JPanel();        Title = new javax.swing.JLabel();        InputContainer = new javax.swing.JPanel();        Ip = new javax.swing.JLabel();        dot1 = new javax.swing.JLabel();        dot2 = new javax.swing.JLabel();        dot3 = new javax.swing.JLabel();        numOfadd = new javax.swing.JLabel();        address_num = new javax.swing.JTextField();        CalcBTN = new javax.swing.JButton();        Ip1 = new javax.swing.JFormattedTextField();        Ip2 = new javax.swing.JFormattedTextField();        Ip3 = new javax.swing.JFormattedTextField();        Ip4 = new javax.swing.JFormattedTextField();        OutputContainer = new javax.swing.JPanel();        FirstAddress = new javax.swing.JLabel();        SencondAddress = new javax.swing.JLabel();        stAdd = new javax.swing.JTextField();        ndAdd = new javax.swing.JTextField();        javax.swing.JScrollPane LogArea_Scroll = new javax.swing.JScrollPane();        LogArea = new javax.swing.JTextArea();        Log = new javax.swing.JLabel();        jSeparator2 = new javax.swing.JSeparator();        jSeparator1 = new javax.swing.JSeparator();        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        Title.setFont(new java.awt.Font(“Calibri Light”, 0, 24)); // NOI18N        Title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);        Title.setText(“Subnetting Calculator”);        javax.swing.GroupLayout TitleContainerLayout = new javax.swing.GroupLayout(TitleContainer);        TitleContainer.setLayout(TitleContainerLayout);        TitleContainerLayout.setHorizontalGroup(            TitleContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, TitleContainerLayout.createSequentialGroup()                .addContainerGap()                .addComponent(Title, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                .addContainerGap())        );        TitleContainerLayout.setVerticalGroup(            TitleContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, TitleContainerLayout.createSequentialGroup()                .addContainerGap()                .addComponent(Title, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)                .addContainerGap())        );        Ip.setText(“IP”);        dot1.setText(“.”);        dot2.setText(“.”);        dot3.setText(“.”);        numOfadd.setText(“Enter the number of addresses”);        CalcBTN.setText(“Calculate”);        CalcBTN.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                CalcBTNActionPerformed(evt);            }        });        try {            Ip1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter(“#**”)));        } catch (java.text.ParseException ex) {            ex.printStackTrace();        }        Ip1.setHorizontalAlignment(javax.swing.JTextField.CENTER);        try {            Ip2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter(“#**”)));        } catch (java.text.ParseException ex) {            ex.printStackTrace();        }        Ip2.setHorizontalAlignment(javax.swing.JTextField.CENTER);        try {            Ip3.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter(“#**”)));        } catch (java.text.ParseException ex) {            ex.printStackTrace();        }        Ip3.setHorizontalAlignment(javax.swing.JTextField.CENTER);        try {            Ip4.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter(“#**”)));        } catch (java.text.ParseException ex) {            ex.printStackTrace();        }        Ip4.setHorizontalAlignment(javax.swing.JTextField.CENTER);        javax.swing.GroupLayout InputContainerLayout = new javax.swing.GroupLayout(InputContainer);        InputContainer.setLayout(InputContainerLayout);        InputContainerLayout.setHorizontalGroup(            InputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(InputContainerLayout.createSequentialGroup()                .addContainerGap()                .addGroup(InputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addGroup(InputContainerLayout.createSequentialGroup()                        .addComponent(numOfadd)                        .addGap(18, 18, 18)                        .addComponent(address_num, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))                    .addGroup(InputContainerLayout.createSequentialGroup()                        .addComponent(Ip)                        .addGap(18, 18, 18)                        .addComponent(Ip1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(dot2)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(Ip2, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(dot1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(Ip3, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(dot3)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(Ip4, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))                .addContainerGap(141, Short.MAX_VALUE))            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, InputContainerLayout.createSequentialGroup()                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                .addComponent(CalcBTN, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)                .addGap(29, 29, 29))        );        InputContainerLayout.setVerticalGroup(            InputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(InputContainerLayout.createSequentialGroup()                .addGap(27, 27, 27)                .addGroup(InputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addGroup(InputContainerLayout.createSequentialGroup()                        .addGap(6, 6, 6)                        .addComponent(Ip, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))                    .addGroup(InputContainerLayout.createSequentialGroup()                        .addGap(3, 3, 3)                        .addGroup(InputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                            .addComponent(dot2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                            .addComponent(dot1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                            .addComponent(dot3)                            .addComponent(Ip1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                            .addComponent(Ip2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                            .addComponent(Ip3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                            .addComponent(Ip4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))                .addGap(22, 22, 22)                .addGroup(InputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addGroup(InputContainerLayout.createSequentialGroup()                        .addGap(6, 6, 6)                        .addComponent(numOfadd, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE))                    .addComponent(address_num))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(CalcBTN, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap())        );        FirstAddress.setText(“First Address”);        SencondAddress.setText(“Last Address”);        stAdd.setEditable(false);        stAdd.setBackground(new java.awt.Color(154, 154, 154));        stAdd.setForeground(new java.awt.Color(255, 255, 255));        stAdd.setHorizontalAlignment(javax.swing.JTextField.CENTER);        stAdd.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));        ndAdd.setEditable(false);        ndAdd.setBackground(new java.awt.Color(154, 154, 154));        ndAdd.setForeground(new java.awt.Color(255, 255, 255));        ndAdd.setHorizontalAlignment(javax.swing.JTextField.CENTER);        ndAdd.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));        LogArea.setEditable(false);        LogArea.setColumns(20);        LogArea.setRows(5);        LogArea_Scroll.setViewportView(LogArea);        Log.setText(“LOG”);        javax.swing.GroupLayout OutputContainerLayout = new javax.swing.GroupLayout(OutputContainer);        OutputContainer.setLayout(OutputContainerLayout);        OutputContainerLayout.setHorizontalGroup(            OutputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(OutputContainerLayout.createSequentialGroup()                .addContainerGap()                .addGroup(OutputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addComponent(LogArea_Scroll)                    .addGroup(OutputContainerLayout.createSequentialGroup()                        .addGroup(OutputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                            .addGroup(OutputContainerLayout.createSequentialGroup()                                .addComponent(FirstAddress)                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                                .addComponent(stAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE))                            .addGroup(OutputContainerLayout.createSequentialGroup()                                .addComponent(SencondAddress)                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                                .addComponent(ndAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE))                            .addComponent(Log))                        .addGap(0, 0, Short.MAX_VALUE))                    .addComponent(jSeparator2)                    .addComponent(jSeparator1))                .addContainerGap())        );        OutputContainerLayout.setVerticalGroup(            OutputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(OutputContainerLayout.createSequentialGroup()                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)                .addGroup(OutputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(FirstAddress)                    .addComponent(stAdd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                .addGroup(OutputContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(SencondAddress)                    .addComponent(ndAdd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addGap(18, 18, 18)                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)                .addGap(18, 18, 18)                .addComponent(Log)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(LogArea_Scroll, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap())        );        javax.swing.GroupLayout RootLayout = new javax.swing.GroupLayout(Root);        Root.setLayout(RootLayout);        RootLayout.setHorizontalGroup(            RootLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addComponent(TitleContainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)            .addComponent(OutputContainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)            .addComponent(InputContainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)        );        RootLayout.setVerticalGroup(            RootLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(RootLayout.createSequentialGroup()                .addComponent(TitleContainer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(InputContainer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(OutputContainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addComponent(Root, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addComponent(Root, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)        );        pack();    }//                             static String appendZeros(String s){        String temp = “00000000”;        return temp.substring(s.length())+ s;    }    // to clear spaces from string    static String clearSpaces(String str){        String out = “”;                        //if user enter ”  1″, “1  ” , or even ” 1 ”        for (int i = 0; i < str.length(); i++) {            if (str.charAt(i)!=' ') {                out+=str.charAt(i);             //if not space take it             }        }        return out;                             //then return last String    }             private void CalcBTNActionPerformed(java.awt.event.ActionEvent evt) {                                                        LogArea.setText("");                            // empty the log area        String bip = "";                                // bip means binary ip        String split_ip = {Ip1.getText(), Ip2.getText(), Ip3.getText(), Ip4.getText()};   //get all ip into string array        String split_bip = new String4; //split binary ip        for(int i=0;i<4;i++){            split_bipi = appendZeros(Integer.toBinaryString(Integer.parseInt(clearSpaces(split_ipi)))); // for converting ip to binary            bip += split_bipi;        }                LogArea.append("IP in binary is "+bip+" ");              // append log data to log area                int n = Integer.parseInt(address_num.getText());          //get the address number                //Calculation of mask        int bits = (int)Math.ceil(Math.log(n)/Math.log(2));         //for Example : if address = 120, log 120/log 2 gives log to the base 2 => 6.9068, ceil gives us upper integer = 7        LogArea.append(“Number of bits required for address = “+bits+”
“);                int mask = 32-bits;             // get the mask        LogArea.append(“The subnet mask is = “+mask+”
“);  //append it to log area                //Calculation of first address        int fbip = new int32;        for(int i=0; i<32;i++)             fbipi = (int)bip.charAt(i)-48; //convert cahracter 0,1 to integer 0,1                for (int i = 31; i > 31-bits; i–)            fbipi &= 0;                   //Get first address by ANDing last n bits with 0                String fip = {“”,””,””,””};                for(int i=0;i<32;i++)            fipi/8 = fipi/8+fbipi;                                //for appending the ip to stadd                stAdd.setText("");        for(int i=0;i<4;i++){            stAdd.setText(stAdd.getText()+Integer.toString(Integer.parseInt(fipi,2)));            if(i!=3)                 stAdd.setText(stAdd.getText()+".");        }                LogArea.append(" ");                        //Calculation of last address        int lbip = new int32;        for(int i=0; i<32;i++)             lbipi = (int)bip.charAt(i)-48; //convert cahracter 0,1 to integer 0,1                for (int i = 31; i > 31-bits; i–)            lbipi |= 1;                   //Get first address by ORing last n bits with 1                String lip = {“”,””,””,””};                for(int i=0;i<32;i++)            lipi/8 = lipi/8+lbipi;                //for appending the ip to ndadd        ndAdd.setText("");        for(int i=0;i<4;i++){            ndAdd.setText(ndAdd.getText()+Integer.toString(Integer.parseInt(lipi,2)));            if(i!=3)                ndAdd.setText(ndAdd.getText()+".");        }    }                                           /**     * @param args the command line arguments     */    public static void main(String args) {        /* Set the Nimbus look and feel */        //        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html          */        try {            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {                if (“Nimbus”.equals(info.getName())) {                    javax.swing.UIManager.setLookAndFeel(info.getClassName());                    break;                }            }        } catch (ClassNotFoundException ex) {            java.util.logging.Logger.getLogger(Subnet_Calculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (InstantiationException ex) {            java.util.logging.Logger.getLogger(Subnet_Calculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (IllegalAccessException ex) {            java.util.logging.Logger.getLogger(Subnet_Calculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (javax.swing.UnsupportedLookAndFeelException ex) {            java.util.logging.Logger.getLogger(Subnet_Calculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        }        //        /* Create and display the form */        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new Subnet_Calculator().setVisible(true);            }        });    }    // Variables declaration – do not modify                         private javax.swing.JButton CalcBTN;    private javax.swing.JLabel FirstAddress;    private javax.swing.JPanel InputContainer;    private javax.swing.JLabel Ip;    private javax.swing.JFormattedTextField Ip1;    private javax.swing.JFormattedTextField Ip2;    private javax.swing.JFormattedTextField Ip3;    private javax.swing.JFormattedTextField Ip4;    private javax.swing.JLabel Log;    private javax.swing.JTextArea LogArea;    private javax.swing.JPanel OutputContainer;    private javax.swing.JPanel Root;    private javax.swing.JLabel SencondAddress;    private javax.swing.JLabel Title;    private javax.swing.JPanel TitleContainer;    private javax.swing.JTextField address_num;    private javax.swing.JLabel dot1;    private javax.swing.JLabel dot2;    private javax.swing.JLabel dot3;    private javax.swing.JSeparator jSeparator1;    private javax.swing.JSeparator jSeparator2;    private javax.swing.JTextField ndAdd;    private javax.swing.JLabel numOfadd;    private javax.swing.JTextField stAdd;    // End of variables declaration                   }