/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJApplet.java
 *
 * Created on Oct 14, 2009, 12:43:02 PM
 */
import java.awt.*;

/**
 *
 * @author root
 */
public class NewJApplet extends javax.swing.JApplet implements Runnable {

    private volatile Thread calculatorThread;

    /** Initializes the applet NewJApplet */
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {

                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void run() {
        Thread thisThread = Thread.currentThread();
        while (calculatorThread == thisThread) {
            try {
                thisThread.sleep(1);
            } catch (InterruptedException e) {
            }
            maxbyte();
            minbyte();
            maxshort();
            minshort();

            maxcharnr();
            mincharnr();
            maxi();
            mini();
            jTextArea1.append(" please wait, trying to find minimum and maximum long int \n");
            minl();
            maxl();
            jTextArea1.append(" ready ......\n");
            stop();
        }
    }

    public void start() {
        if (calculatorThread == null) {
            calculatorThread = new Thread(this);
            calculatorThread.start();
        }
    }

    public void stop() {
        Thread tmpcalculatorThread = calculatorThread;
        calculatorThread = null;
        if (tmpcalculatorThread != null) {
            tmpcalculatorThread.interrupt();
        }
    }

    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 657, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(645, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(256, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables

    public void maxbyte() {
        byte i, i1;
        double ih;

        i = 1;
        i1 = 2;



        while (i < i1) {
            i++;
            i1++;


        }

        //ih = Math.log(i) / Math.log(2.0);
        jTextArea1.append(" max byte is " + i + "  next is " + i1 +  "\n");

    }

    public void minbyte() {
        byte i, i1;



        i = 1;
        i1 = 0;

        while (i > i1) {
            i--;
            i1--;

        }


        jTextArea1.append(" min byte is " + i + "  next is " + i1 + "\n");

    }

    public void maxcharnr() {
        char i, ii;
        i = 1;
        ii = 2;
        while (i < ii) {
            i++;
            ii++;


        }
        jTextArea1.append(" max char is" + i + " Nr." + (int) i + "  next is" + ii + " Nr." + (int) ii + "\n");
    }

    public void mincharnr() {
        char i, i1;


        i = 1;
        i1 = 0;

        while (i > i1) {
            i--;
            i1--;

        }


        jTextArea1.append(" min char is Nr." + (int) i + "  next is Nr." + (int) i1 + "\n");
    }

    public void maxshort() {
        short i, i1;
        double ih;

        i = 1;
        i1 = 2;



        while (i < i1) {
            i++;
            i1++;


        }

        //ih = Math.log(i) / Math.log(2.0);
        jTextArea1.append(" max short is " + i + "  next is " + i1  + "\n");

    }

    public void minshort() {
        short i, i1;



        i = 1;
        i1 = 0;

        while (i > i1) {
            i--;
            i1--;

        }


        jTextArea1.append(" min short is " + i + "  next is " + i1 + "\n");


    }

    public void maxi() {
        int i, i1;
        double ih;

        i = 1;
        i1 = 2;



        while (i < i1) {
            i++;
            i1++;



        }
        //ih = Math.log(i) / Math.log(2.0);
        jTextArea1.append(" max integer is " + i + "  next is " + i1  + "\n");

    }

    public void mini() {
        int i, i1;



        i = 1;
        i1 = 0;

        while (i > i1) {
            i--;
            i1--;

        }


        jTextArea1.append(" min integer is " + i + "  next is " + i1 + "\n");


    }

    public void minl() {
        long i, i1;
        double ih;

        i = -1;
        i1 = 2;


        do {
            i *= 2;
            i1 = i - 1;
        } while (i > i1);
        jTextArea1.append(" min long integer is " + i + "  next is " + i1 + "\n");

    }

    public void maxl() {
        long i, i1;
        double ih;
        i = 1;
        i1 = 2;


        do {
            i *= 2;
            i1 = i - 1;
        } while (i > i1);
        //ih = Math.log(i1) / Math.log(2.0);
        jTextArea1.append(" max long integer is " + i1 + "  next is " + i  + "\n");

    }
}
