Results 1 to 11 of 11
  1. #1
    Darrarski is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default JApplet display problem

    Hello,

    I'm beginner in Java and totally new to making java (web) applets. I have made simple applet, my class is extending swing's JApplet class, there is a label and a button. I'm trying to test my applet in web browser, using <applet> html tag pointed to my jar file. I'm getting "Applet test3.Main started" info, but I can't see my applet on the page.

    My Java Console is giving me this information:
    basic: Making reference to classloader: sun.plugin.ClassLoaderInfo @ 1e3bb9e, refcount = 2
    basic: Added progress Client: sun.plugin.util.GrayBoxPainter $ GrayBoxProgressListener @ 1fc493
    basic: Loading applet ...
    Basic: Initiates applet ...
    basic: Starting applet ...
    basic: completed perf rollup
    Basic: I stop an applet ...
    basic: Removed customer's progress: sun.plugin.util.GrayBoxPainter $ GrayBoxProgressListener @ 653ad5
    Basic: Destruction applet ...
    Basic: Removing the applet ...
    Basic: Connecting thread applet ...
    Basic: Connected applet thread ...
    Basic: I find information ...
    Basic: fired classloader: sun.plugin.ClassLoaderInfo @ 1e3bb9e, refcount = 1
    Basic: Ready ...
    For me everything looks fine. Could you help me?
    I'm attaching all my project files.
    Attached Files Attached Files

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    Are there any error messages in the browser's Java console? Copy and paste them here.

  3. #3
    Darrarski is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    I'm using FireFox 3.6. I don't know if there is a browser's Java Console, I only know about the browser-independent Java Console that comes with Java on Mac OS X. I've already past messages form that console in previous post.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    Your code works for me with AppletViewer and FF on WinXP.
    I see a label "test 3" and a button.

  5. #5
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    when i import the class Main.java in eclipse i got a punch of errors saying

    org.jdesktop.layout.GroupLayout cannot be resolved to a type

    http://java.sun.com/docs/books/tutor...upExample.html
    Last edited by j2me64; 06-03-2010 at 11:25 PM.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    OP must be using netbeans. It likes to use its own classes for GUI. I dug out swing-layout-1.0.3.jar and used it to compile and execute.

    Using netbeans means you need to find its jar files and pass them out along with your applet's jar file. UGGGH!!
    Last edited by Norm; 06-03-2010 at 11:35 PM.

  7. #7
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    with the following code i could eliminate all compiling errors and run the code

    Java Code:
    import javax.swing.GroupLayout;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    
    public class Main extends javax.swing.JApplet {
    
    	/** Initializes the applet Main */
    	public void init() {
    		try {
    			java.awt.EventQueue.invokeAndWait(new Runnable() {
    				public void run() {
    					initComponents();
    				}
    			});
    		} catch (Exception ex) {
    			ex.printStackTrace();
    		}
    	}
    
    	/**
    	 * 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() {
    
    		jLabel1 = new JLabel("TEST 3");
    		jButton1 = new JButton("TEST BUTTON");
    
    		GroupLayout layout = new GroupLayout(getContentPane());
    		getContentPane().setLayout(layout);
    		layout.setHorizontalGroup(layout.createParallelGroup(
    				GroupLayout.Alignment.LEADING).addGroup(
    				layout.createSequentialGroup().addContainerGap().addComponent(
    						jLabel1).addContainerGap(18, 18).addComponent(jButton1)
    						.addContainerGap(GroupLayout.DEFAULT_SIZE,
    								Short.MAX_VALUE)));
    		layout.setVerticalGroup(layout.createParallelGroup(
    				GroupLayout.Alignment.LEADING).addGroup(
    				layout.createSequentialGroup().addContainerGap().addGroup(
    						layout.createParallelGroup(
    								GroupLayout.Alignment.BASELINE).addComponent(
    								jLabel1).addComponent(jButton1))
    						.addContainerGap(GroupLayout.DEFAULT_SIZE,
    								Short.MAX_VALUE)));
    	}// </editor-fold>//GEN-END:initComponents
    
    	// Variables declaration - do not modify//GEN-BEGIN:variables
    	private javax.swing.JButton jButton1;
    	private javax.swing.JLabel jLabel1;
    	// End of variables declaration//GEN-END:variables
    
    }

    i changed some lines, for example add(18, 18, 18) to addContainerGap(18, 18) only to run the code. you can look at the output in the attachment.
    Attached Thumbnails Attached Thumbnails JApplet display problem-applet.gif  

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    Why is the OP not able to get that output? Are there error messages in the Java console?

    @OP do you reference the jar file with the org.jdesktop.layout package in your html and have that jar file in folder with html file?

  9. #9
    Darrarski is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    Thank you guys, I'm glad to get your support. I think the problem is in browser cache or life cycle of an applet. I have to restart my browser (checked in FireFox and Chrome) any time I want to test some changes in applet. Otherwise the browser running old version of applet, even if I delete my browser's history and cache.
    Now I know that using NetBeans form designer for web applets it's not good choice. Btw there is so many limitation for JApplets, that I'm going to build desktop application first. Thanks a lot again.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default

    Quote Originally Posted by Darrarski View Post
    Now I know that using NetBeans form designer for web applets it's not good choice. Btw there is so many limitation for JApplets, that I'm going to build desktop application first. Thanks a lot again.
    Congratulations on discovering for yourself what most newbies are unwilling to accept even when told repeatedly.

    Indeed, you should avoid any visual GUI designer at least until you are competent to read and understand the code it generates. And desktop applications are indeed easier for a beginner than applets with their sandboxed environment and attendant security restrictions.

    Just don't make the only-too-common mistake of extending JFrame for all your desktop applications, even though that's the approach you'll find in many tutorials, including the one on the Sun/Oracle site.

    db

  11. #11
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Indeed as
    Daryl.Burke said earlier, coding GUI's by hand is so rewarding and providing the right layout manager, far more control, try GridBagLayout() complicated but rewarding.

    The reasons for applet restrictions is obvious when you think about it. If an applet could have access to an operating system e.g. a file then all kind of security breaches would happpen!!! better to get your own little server like xampp and sign your own applets for testing. I use xampp for testing out php and mysql and use the localhost webserver everybody has..Personally I think applets are dead and not worth it anymore....

    like I tell everybody read, read and read, the more serious you are about programming the more you are above your peers. and the more you WANT to read.

    good luck....

Similar Threads

  1. Loops and display problem
    By lk1001 in forum New To Java
    Replies: 6
    Last Post: 02-26-2010, 05:26 PM
  2. JFrame to JApplet or JApplet to JApplet
    By ramesh.8189 in forum AWT / Swing
    Replies: 13
    Last Post: 02-08-2009, 07:14 AM
  3. JApplet Problem
    By tanmoy.b81 in forum AWT / Swing
    Replies: 2
    Last Post: 07-28-2008, 07:56 AM
  4. Another problem in JApplet :S
    By juju in forum Java Applets
    Replies: 2
    Last Post: 12-30-2007, 08:46 PM
  5. How to display an image in JApplet
    By fred in forum Java Applets
    Replies: 1
    Last Post: 07-24-2007, 03:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •