Link to home
Start Free TrialLog in
Avatar of only1wizard
only1wizardFlag for United States of America

asked on

web page not finding applet

hello -

i have this java applet that grabs the users mac address for enhanced security, which we can log and have user approve wither the computer can access users account.

it runs fine in netbeans.

i tried to run in xampp with a .php web page to test it but it keeps erroring out. im new to using applets in web pages so i really dont know if im parsing it correctly.

heres code for web page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>MacAddress</title>
</head>

<body>
 
    <a href="" onClick="macs.getMacAddress();"> Get "first" MAC Address</a>
    <br/>
    <br/>
    <a href="" onClick="macs.getMacAddressesJSON();"> Get all MAC Addresses</a>

    <!--[if !IE]> Firefox and others will use outer object -->
    <embed type="application/x-java-applet"
           name="macaddressapplet"
           width="0"
           height="0"
           code="macaddressapplet"
           archive="macaddressapplet.jar"
           pluginspage="http://java.sun.com/javase/downloads/index.jsp"
           style="position:absolute; top:-1000px; left:-1000px;">
        <noembed>
        <!--<![endif]-->
            <!---->
            <object classid="clsid:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA"
                    type="application/x-java-applet"
                    name="macaddressapplet"
                    style="position:absolute; top:-1000px; left:-1000px;"
                    >
                <param name="code" value="macaddressapplet">
                <param name="archive" value="macaddressapplet.jar" >
                <param name="mayscript" value="true">
                <param name="scriptable" value="true">
                <param name="width" value="0">
                <param name="height" value="0">
              </object>
        <!--[if !IE]> Firefox and others will use outer object -->
        </noembed>
    </embed>
    <!--<![endif]-->

    <script type="text/javascript">
        var macs = {
            getMacAddress : function()
            {
                document.macaddressapplet.setSep( "-" );
                alert( "Mac Address = " + document.macaddressapplet.getMacAddress() );
            },

            getMacAddressesJSON : function()
            {
                document.macaddressapplet.setSep( ":" );
                document.macaddressapplet.setFormat( "%02x" );
                var macs = eval( String( document.macaddressapplet.getMacAddressesJSON() ) );
                var mac_string = "";
                for( var idx = 0; idx < macs.length; idx ++ )
                    mac_string += "\t" + macs[ idx ] + "\n ";

                alert( "Mac Addresses = \n" + mac_string );
            }
        }
    </script>

</body>
</html>

Open in new window


heres code for java applet

MacAddressApplet.java
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.ArrayList;
import java.applet.Applet;

public class MacAddressApplet extends Applet
{
    public static String sep = ":";
    public static String format = "%02X";

    /**
     * getMacAddress - return the first mac address found
     * separator - byte seperator default ":"
     * format - byte formatter default "%02X"
     *
     * @param ni - the network interface
     * @return String - the mac address as a string
     * @throws SocketException - pass it on
     */
    public static String macToString( NetworkInterface ni ) throws SocketException
    {
        return macToString( ni, MacAddressApplet.sep,  MacAddressApplet.format );
    }

    /**
     * getMacAddress - return the first mac address found
     *
     * @param ni - the network interface
     * @param separator - byte seperator default ":"
     * @param format - byte formatter default "%02X"
     * @return String - the mac address as a string
     * @throws SocketException - pass it on
     */
    public static String macToString( NetworkInterface ni, String separator, String format ) throws SocketException
    {
        byte mac [] = ni.getHardwareAddress();

        if( mac != null ) {
            StringBuffer macAddress = new StringBuffer( "" );
            String sep = "";
            for( byte o : mac ) {
                macAddress.append( sep ).append( String.format( format, o ) );
                sep = separator;
            }
            return macAddress.toString();
        }

        return null;
    }

    /**
     * getMacAddress - return the first mac address found
     *
     * @return the mac address or undefined
     */
    public static String getMacAddress()
    {
        try {
            Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();

            // not all interface will have a mac address for instance loopback on windows
            while( nis.hasMoreElements() ) {
                String mac = macToString( nis.nextElement() );
                if( mac != null )
                    return mac;
            }
        } catch( SocketException ex ) {
            System.err.println( "SocketException:: " + ex.getMessage() );
            ex.printStackTrace();
        } catch( Exception ex ) {
            System.err.println( "Exception:: " + ex.getMessage() );
            ex.printStackTrace();
        }

        return "undefined";
    }

    /**
     * getMacAddressesJSON - return all mac addresses found
     *
     * @return a JSON array of strings (as a string)
     */
    public static String getMacAddressesJSON()
    {
        try {
            String macs [] = getMacAddresses();

            String sep = "";
            StringBuffer macArray = new StringBuffer( "['" );
            for( String mac: macs ) {
                macArray.append( sep ).append( mac );
                sep = "','";
            }
            macArray.append( "']" );

            return macArray.toString();
        } catch( Exception ex ) {
            System.err.println( "Exception:: " + ex.getMessage() );
            ex.printStackTrace();
        }

        return "[]";
    }

    /**
     * getMacAddresses - return all mac addresses found
     *
     * @return array of strings (mac addresses) empty if none found
     */
    public static String [] getMacAddresses()
    {
        try {
            Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
            
            ArrayList<String> macs = new ArrayList<String>();
            while( nis.hasMoreElements() ) {
                String mac = macToString( nis.nextElement() );
                // not all interface will have a mac address for instance loopback on windows
                if( mac != null ) {
                    macs.add( mac );
                }
            }
            return macs.toArray( new String[0] );
        } catch( SocketException ex ) {
            System.err.println( "SocketException:: " + ex.getMessage() );
            ex.printStackTrace();
        } catch( Exception ex ) {
            System.err.println( "Exception:: " + ex.getMessage() );
            ex.printStackTrace();
        }

        return new String[0];
    }

   
     /**
     * getMacAddresses - return all mac addresses found
     *
     * @param sep - use a different separator
     */
    public static void setSep( String sep )
    {
        try {
            MacAddressApplet.sep = sep;
        } catch( Exception ex ) {
            //  don't care
        }
    }

    /**
     * getMacAddresses - return all mac addresses found
     *
     * @param format - the output format string for bytes that can be overridden default hex.
     */
    public static void setFormat( String format )
    {
        try {
            MacAddressApplet.format = format;
        } catch( Exception ex ) {
            //  don't care
        }
    }

    public static void main( String... args )
    {
        System.err.println( " MacAddress = " + getMacAddress() );

        setSep( "-" );
        String macs [] = getMacAddresses();

        for( String mac : macs )
            System.err.println( " MacAddresses = " + mac );

        setSep( ":" );
        System.err.println( " MacAddresses JSON = " + getMacAddressesJSON() );
    
       
    }
}

Open in new window


thanks in advance for your help!
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

I don't know much about java applets, but I believe the applet is the file "macaddressapplet.jar" which it is expecting to find in the same folder as the web page. If not, you'll need to enter an absolute url instead of a relative one.
Avatar of rrz
>web page not finding applet  
You have
>code="macaddressapplet"  
That should be  
code="MacAddressApplet.class"  
I don't know if this will work without signing your applet.
Avatar of only1wizard

ASKER

@xmediaman the file is in the same directory as the web page.

@rrz i will look into that and post my results

thanks in advance for your help!
thats not working so how do i sign the applet?
or what do i do know?
>thats not working so how do i sign the applet?  
What is not working ?
Is the applet being found ?
Are you getting error message ?  In order to see error messages, change your code. Move the applet on to the page and give it some actual dimensions. You should see a box on the page. Also use the control panel on the client machine to enable the java console.  
You can google for signing instructions, if it is necessary.  
the macaddressapplet.class is not working.

can you post the code the way it should be on html/php?

thanks for your help

yes im getting a web page error message saying that the applet can not be found and i dont know how and or where to begin because this is my first applet. i can get the applet to run fine no problem in netbeans ide but getting it to run on the web is a new learning lesson for me.

>the macaddressapplet.class is not working.  
Shouldn't  that be
MacAddressApplet.class
?  
Did you do what I suggested ?
move the applet on the page with real dimensions
enable Java Console    

Is the jar in the same directory as the HTML file that calls it ?
What is inside the jar ?


 


i have it as MacAddressApplet.class

i set the applet with real dimensions

enabled java console

the jar is in the same directory as the html

whats in side the jar is from the code post in .java i got the jar from that build of .java
its not finding the applet thanks i didnt know that the console was not turned on. please see attached for error message

ive tried the name different and here is the code that i have now how should this code go?

<!--[if !IE]> Firefox and others will use outer object -->
	<embed type="application/x-java-applet" name="macaddressapplet" width="100" height="10" 
    code="MacAddressApplet.class" 
    archive="http://Destiny/only1wizard/developement-multiple-scripts/web_computerInfo/macaddressapplet.jar" 
    pluginspage="http://java.sun.com/javase/downloads/index.jsp" 
    style="position:absolute; top:-1000px; left:-1000px;">
	<noembed>
<!--<![endif]-->
<!-- -->

<object classid="clsid:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA" type="application/x-java-applet" name="macaddressapplet" style="position:absolute; top:-1000px; left:-1000px;">
	<param name="code" value="MacAddressApplet.class">
	<param name="archive" value="http://Destiny/only1wizard/developement-multiple-scripts/web_computerInfo/macaddressapplet.jar" >
	<param name="mayscript" value="true">
	<param name="scriptable" value="true">
	<param name="width" value="100">
	<param name="height" value="10">
</object>
        
<!--[if !IE]> Firefox and others will use outer object -->
	</noembed>
	</embed>
<!--<![endif]-->

Open in new window

User generated image
You could try making a copy of the jar. Rename that jar file to a zip file and unzip it. Is the file MacAddressApplet.class in there ?
You could show us the complete error message.  
 If you can't get anywhere you could try deploying without the jar. Just put the class file with the HTML file and take out archive attribute from tags.  
heres the current error again its not finding the class in the jar i will remove the jar and try the class and remove the archive reference.
Screen-shot-2012-01-12-at-9.12.4.png

The way you invoke apllets form HTML pages is like that:

http://cs.wellesley.edu/~cs111/fall99/lectures/invoking-applets.html

      <applet codebase="http://www.vivids.com/java/assorted/Coalesce/"
              code=Coalesce.class
              width=400
              height=200>

You should not use object, etc.

>><param name="archive" value="http://Destiny/only1wizard/developement-multiple-scripts/web_computerInfo/macaddressapplet.jar" >

and other archive attributes are wrong. That should be a relative url (preferably) or if a full url, should have the hostname correctly defined
why do you need to ahve all these object, embed tags

You can just use applet, something like that:

<applet code=MacAddressApplet.class width="100" height="10">
ARCHIVE="macaddressapplet.jar"
<param name="mayscript" value="true">
<param name="scriptable" value="true">

</applet>

and put macaddressapplet.jar in the same folder where you have HTML page which contains
this applet tag

And first try to run it form a simple HTML page without
anything eles so that you at least see ho to ues applets in normal
way

I think this is corrected syntax -- archive should be attribute of APPLET tag

<applet code=MacAddressApplet.class width="100" height="10"
ARCHIVE="macaddressapplet.jar">
<param name="mayscript" value="true">
<param name="scriptable" value="true">

</applet>
The object tag is nothing to do with the problem
It has nothing to do - but better use applets in normal way - then it is easier to address anything else
Put this jar into the same folder as the HTML which cnatins APPLET tag
and check that is contains your class as rrz suggested - does jar contain the class?
Are you sure that the class iis in the default package in that jar?
only1wizard, let me know if you have difficulty in setting the archive attribute path
@for_yan i have a .jar file do i place the jar file name where the class name is?

@cehj that is a relative url on my lan. i dont have this on production yet.
wow wasnt aware of the other posts i will try out what you have said an ill repost
You can start by placing the jar in the same directory as the html

archive="macaddressapplet.jar"

Put everything in the same foldeer - the HTML page, .jar file and .class file
the MacAddressApplet.jar includes the .class or do you want me to include the seperate file?
No separate file needed
im getting nothing
It should not be neecssary to include separate file, but if you put it sisde by side - it will not be bad
Check if your class was compiled in the default package - is it in top folder within the jar?
Becuase if not - that may be a probem
>im getting nothing  - ?

Make sure you have Java console opneing in your browser

heres the web page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<applet code=MacAddressApplet.class width="341" height="68"
ARCHIVE="MacAddressApplet.jar">
<param name="mayscript" value="true">
<param name="scriptable" value="true">
</applet
></body>
</html>

Open in new window


heres MacAddressApplet.java
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.ArrayList;
import java.applet.Applet;

public class MacAddressApplet extends Applet
{
    public static String sep = ":";
    public static String format = "%02X";

    /**
     * getMacAddress - return the first mac address found
     * separator - byte seperator default ":"
     * format - byte formatter default "%02X"
     *
     * @param ni - the network interface
     * @return String - the mac address as a string
     * @throws SocketException - pass it on
     */
    public static String macToString( NetworkInterface ni ) throws SocketException
    {
        return macToString( ni, MacAddressApplet.sep,  MacAddressApplet.format );
    }

    /**
     * getMacAddress - return the first mac address found
     *
     * @param ni - the network interface
     * @param separator - byte seperator default ":"
     * @param format - byte formatter default "%02X"
     * @return String - the mac address as a string
     * @throws SocketException - pass it on
     */
    public static String macToString( NetworkInterface ni, String separator, String format ) throws SocketException
    {
        byte mac [] = ni.getHardwareAddress();

        if( mac != null ) {
            StringBuffer macAddress = new StringBuffer( "" );
            String sep = "";
            for( byte o : mac ) {
                macAddress.append( sep ).append( String.format( format, o ) );
                sep = separator;
            }
            return macAddress.toString();
        }

        return null;
    }

    /**
     * getMacAddress - return the first mac address found
     *
     * @return the mac address or undefined
     */
    public static String getMacAddress()
    {
        try {
            Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();

            // not all interface will have a mac address for instance loopback on windows
            while( nis.hasMoreElements() ) {
                String mac = macToString( nis.nextElement() );
                if( mac != null )
                    return mac;
            }
        } catch( SocketException ex ) {
            System.err.println( "SocketException:: " + ex.getMessage() );
            ex.printStackTrace();
        } catch( Exception ex ) {
            System.err.println( "Exception:: " + ex.getMessage() );
            ex.printStackTrace();
        }

        return "undefined";
    }

    /**
     * getMacAddressesJSON - return all mac addresses found
     *
     * @return a JSON array of strings (as a string)
     */
    public static String getMacAddressesJSON()
    {
        try {
            String macs [] = getMacAddresses();

            String sep = "";
            StringBuffer macArray = new StringBuffer( "['" );
            for( String mac: macs ) {
                macArray.append( sep ).append( mac );
                sep = "','";
            }
            macArray.append( "']" );

            return macArray.toString();
        } catch( Exception ex ) {
            System.err.println( "Exception:: " + ex.getMessage() );
            ex.printStackTrace();
        }

        return "[]";
    }

    /**
     * getMacAddresses - return all mac addresses found
     *
     * @return array of strings (mac addresses) empty if none found
     */
    public static String [] getMacAddresses()
    {
        try {
            Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
            
            ArrayList<String> macs = new ArrayList<String>();
            while( nis.hasMoreElements() ) {
                String mac = macToString( nis.nextElement() );
                // not all interface will have a mac address for instance loopback on windows
                if( mac != null ) {
                    macs.add( mac );
                }
            }
            return macs.toArray( new String[0] );
        } catch( SocketException ex ) {
            System.err.println( "SocketException:: " + ex.getMessage() );
            ex.printStackTrace();
        } catch( Exception ex ) {
            System.err.println( "Exception:: " + ex.getMessage() );
            ex.printStackTrace();
        }

        return new String[0];
    }

   
     /**
     * getMacAddresses - return all mac addresses found
     *
     * @param sep - use a different separator
     */
    public static void setSep( String sep )
    {
        try {
            MacAddressApplet.sep = sep;
        } catch( Exception ex ) {
            //  don't care
        }
    }

    /**
     * getMacAddresses - return all mac addresses found
     *
     * @param format - the output format string for bytes that can be overridden default hex.
     */
    public static void setFormat( String format )
    {
        try {
            MacAddressApplet.format = format;
        } catch( Exception ex ) {
            //  don't care
        }
    }

    public static void main( String... args )
    {
        System.err.println( " MacAddress = " + getMacAddress() );

        setSep( "-" );
        String macs [] = getMacAddresses();

        for( String mac : macs )
            System.err.println( " MacAddresses = " + mac );

        setSep( ":" );
        System.err.println( " MacAddresses JSON = " + getMacAddressesJSON() );
    
       
    }
}

Open in new window


thanks in advance for your help

i compiled the code posted and checked the jar and the class is in the jar i know because in the folder window in netbeans it has an arrow to query the file list and .class is in their.

Configure your browser to open Java Console

You expend Applet but do you add any elemets in there ?

If your whole output goes to System.out you'll not see it in the briowser obviously
I don't see any init() method and any creation of the GUI in your Applet - at least on the quick glance  - you'll see nothing in the browser if youi don't have that
You should probably see System.out.... and, I guess,  System.err.... messages on Java console
but Applet should have some visual elememnt - like JTextArea wher you should be writing output - then you'd see it in the browser
this is my first applet can you show me an example of how to properly execute the output statement on a browser instead of system.

it runs fine no problem in netbeans.

thanks in advance for your help!
i didnt know that it had seperate output statements i seen that it outputs on the command line properly and figuried that it works.

You need to make an application with GUI - have you ever done that?
Even as an application - extend JFrame and place JTextAre in there and write something on that JTextArea

Then change extends JFrame to JApllet and constructor where you acreate and add JTextAre into init() method and you'll have your applet
No, your command line oputput you should be able to see only in the Java consle of  the browser
not in the borowser itself
You were also quite unfair in closing the previous question, so I'm a little bit in doubt should I spend more time on that subject with you now, just to find later that you accepted sopmeone else's answer
@for_yan can you show me an example of the gui.

i would need to spend more time on clearly deciding who has done what next time i close an answer.
OK. I'll find and post for the code for  a simple applet.
i have an applet right here but how do i incorporate the browser output into these settings?

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

/*
 * GUI_MacAddressApplet.java
 *
 * Created on Jan 13, 2012, 8:35:25 PM
 */
/**
 *
 * @author theo werntz ii
 */
public class GUI_MacAddressApplet extends javax.swing.JFrame {

    /** Creates new form GUI_MacAddressApplet */
    public GUI_MacAddressApplet() {
        initComponents();
    }

    /** This method is called from within the constructor 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">
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextField1.setText("jTextField1");

        jLabel1.setText("jLabel1");

        jLabel2.setText("jLabel2");

        jTextField2.setText("jTextField2");

        jLabel3.setText("jLabel3");

        jTextField3.setText("jTextField3");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 32, Short.MAX_VALUE)
                        .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 188, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(20, 20, 20))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel3)
                            .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jTextField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .add(26, 26, 26)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* 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(GUI_MacAddressApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUI_MacAddressApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUI_MacAddressApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUI_MacAddressApplet.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 GUI_MacAddressApplet().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration
}

Open in new window

Thsi si the simplistic Applet:
Compile this code - create class TestApplet.class
and put it in the same folder and chacge class name in your APPLET tag
and then make sure you see how it pints the word hello in the browser

When you are done with this simple check
then apply the same to your more complex applet using JTextArea to print the output
as in this simple example

import javax.swing.*;
import java.awt.*;

public class TestApplet extends JApplet {
    JTextArea text;

   public void init() {
    text = new JTextArea(20,20);
       Container c = this.getContentPane();
       c.add(text);
       text.setText("hello");


}




}

Open in new window

The one you have there is too complex for your goals - of jkust printing a few strings.
Use my simple example
So in Applet there should be no main() method
It starts execution with init()
so create in init() JTextArea as I did and then
whateevr you want to print, instaed if using this
System.err.println(...)
just use textArea.setText(...)

But do all that later with your real applet - for the start - jayust make sure you see
how my TestApplet above works
Is your applet being found ?
Are you still getting the ClassNotFoundException ?    
ok will try but what i dont understand is how do i print the text from :

public static void main( String... args )
    {
        System.err.println( " MacAddress = " + getMacAddress() );

        setSep( "-" );
        String macs [] = getMacAddresses();

        for( String mac : macs )
            System.err.println( " MacAddresses = " + mac );

        setSep( ":" );
        System.err.println( " MacAddresses JSON = " + getMacAddressesJSON() );
    
       
    }

Open in new window


sorry but how do i incorporate this into my app to output into the applet? do i use something like

 public void init() {
    text = new JTextArea(20,20);
       Container c = this.getContentPane();
       c.add(text);
       text.setText(" MacAddress = " + getMacAddress(), " MacAddresses = " + mac , " MacAddresses JSON = " + getMacAddressesJSON());

Open in new window


thanks in advance for your help!
Yes, you eventually use something like that
but fisrt try to do the simplest thing
sorry thats just how i think! thats why i asked earier to be patient with me!
It is OK. Just appreciate the patience when it comes to that point.
the app works in netbeans testing on web now
Great!
its still not parsing

>its still not parsing

what that means ?
oh im not calling the applet from the main class
sorry parsing meaning not working
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you again for all your help! if you had a hire tag on your profile i will look you up next time i have a problem. thanks again and enjoy your weekend i have got to get coding this back end.
thanks for your help!
You are alwys welcome. I'm glad it worked for you.
Just go back to your original applet. It uses Javascript to access methods in your applet.  
Show us the err or messages.
Not is not fair. You accepted a solution that didn't have anything to do with your original question.
>>Not is not fair. You accepted a solution that didn't have anything to do with your original question.

Quite right. I gave you the actual solution at http:#37432002 but rrz@871311 was also very helpful. Also:

>>I don't see any init() method and any creation of the GUI in your Applet - at least on the quick glance  - you'll see nothing in the browser if you don't have that

>>Just go back to your original applet. It uses Javascript to access methods in your applet.

the above statement by rrz@871311 is right and the statement by for_yan is wrong.

IF the applet is now 'working', it is working by virtue of the fact that its original calling Javascript has been abandoned. So what's going on? only1wizard, you should split points between the people who actually helped.

To be fair, you DID say you didn't understand your original code properly and that's fine. What's not fine is that someone else has ignored/changed that original code, either because he *also* didn't understand it, or because he wanted to hijack the question.

This question should be reopened. Either I or rrz@871311 will advise on how to get the applet working as intended, which of course was misunderstood/ignored by for_yan






only1wizard


There is no need to have any interaction with javascript when there is a much simpler solution which can be achieved only through use of applet.
The author originally did not understand the possibilities of applet, and was happy when I expalined them to him.


Permanent attacks by CEHJ and use of unacceptable expressions  ("hijacking", etc).
are simply unacceptable - against all possible rules of EE and general ethical behavior.
>>There is no need to have any interaction with javascript

And how do you know that? The author doesn't. For all you know, the script is a small part of a bigger intended framework for scripting the applet.

If the author is happy abandoning the scripting, that's fine. Either way, i answered the question

The author explicitly stated that he is happy - read above.

Nothing came out of your posting http:#37432002.
I spent two more hours in close conversation with the author before he got any result and understood quite a lot about applets
in the process.


>>Nothing came out of your posting http:#37432002

That's nonsense. The thread could have ended right there with the problem solved. In the event you flood posted it, making changes that were not necessary. This question will be reviewed
only1wizard's original applet was ok. He posted  
>it runs fine in netbeans.  
I compiled and tested it myself. It had no problems. The javascript in his HTML page successfully accessed his applet methods.  
My comment at http:#37369271  pointed out an obvious problem.

At http:#37400807  told him how to able to see error messages.  He did enable the Java Console and gave the applet dimension's but never moved the box on the page.
At http:#37425441   for debugging purposes I suggested that he not use a jar and call the class file directly. But he never tried that.  
He just ignored CEHJ's comment at  http:#37432002    

At http:#37432206     only1wizard decided to abandon his original question.  

>>He just ignored CEHJ's comment at  http:#37432002  

Actually what really happened there is for_yan simply repeated my advice in a different form (thus obfuscating it) and only1wizard just subsumed it in the course of the question
I recommend  
1) Delete/refund  
The question author, only1wizard, abandoned his original code and accept entirely new code as the accepted solution. Since he gave up, we don't know what the solution was to his original question.
I recommend that the question stay as is. yes the original question had referenced javascript as accessing the object in the applet.

what is the name of my question? web page not finding applet

thus thats what for_yan did was help me achive what i was looking for i thought it was clear and a consise question. their were no errors with the code just how it was configured to access the applet thus my first web applet. the code would compile in netbean and run inside netbeans.

but when access from the web page the web page would not find the applet.

with out for_yans attentive and persistent help i would propably still be working on getting the applet to run.

i didnt abandon the question the question as to why the java script was being accessed was not apart of the question the original question was to help me get the applet running. nothing in the question or question memo states that the java script doesnt work.

after for_yans help i was able to configure the original posting to work and learn a new way to call applets.

thanks for your help!
>what is the name of my question? web page not finding applet  
Yes, that is why I pointed out an obvious problem at
http:#37369271 
because you need to use the correct class name in order to find it.  
Next I thought you should look at the java console to see if there was an error message. But now I can see that was the wrong way to go. I am sorry. But I thought that was the next logical step.  

Looking back at your code now, I would say that the problem is that you misconstructed the <object> tag. I didn't take a good look at it at the start. I am sorry. I went with obvious things first.  

>after for_yans help i was able to configure the original posting to work and learn a new way to call applets.  
The <applet> tag is not new. It is legacy.
The <applet> element is deprecated in HTML 4.01.  
The <applet> element is  not  supported in HTML5.