Results 1 to 15 of 15
  1. #1
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default JApplet works in eclipse but refuses to show online

    So I got this JApplet that has a JPanel attached to it. (code below)
    When I run the program in Eclipse (Indigo) it works perfectly.

    So I build the entire .java to .class files and insert it in a html code:

    Java Code:
    <P><applet code="MaraudersOfDeepSpace.class" width="650" height="400">
    Your browser does not support the <code>applet</code> tag.
    </applet></P>
    But the problem doesn't seem to be related to the HTML code (that's my guess!! I could be wrong). All I see when I open the site is a white background (you can slightly see the contours of the applet)

    The code I'm trying to display on the site:

    JApplet:
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.Color;
    import java.awt.Graphics;
    
    import javax.swing.JApplet;
    import javax.swing.JPanel;
    
    public class MaraudersOfDeepSpace extends JApplet {
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    	
    	MenuPanel mainMenu;
    	final String MENU = "Menu";
    	final String LOAD = "Load";
    	final String OBJECTIVE = "Objective";
    	final String CONTROLS = "Controls";
    	private CardLayout cardsLayout = new CardLayout();
    	private JPanel cards = new JPanel(cardsLayout);
    	
    	public void init()
    	{
    		[COLOR="#FF0000"]System.out.print("1/");[/COLOR]
    		mainMenu = new MenuPanel(this);
    		cards.add(mainMenu, MENU);
            //cards.add(load, LOAD);
            //cards.add(objective, OBJECTIVE);
            //cards.add(controls, CONTROLS);
    		this.setSize(650, 400);
            this.add(cards, BorderLayout.CENTER);
            cards.setOpaque(true); 
            setContentPane(cards);
            [COLOR="#FF0000"]System.out.print("4/");[/COLOR]
    	}
    	
    	public void swapCards(String key) {
    		cardsLayout.show(cards, key);
    	}
    
    }
    JPanel:
    Java Code:
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Random;
    
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    
    public class MenuPanel extends JPanel implements ActionListener {
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    	
    	Image title,earth,jupiter;
    	Random random = new Random();
    	int[][] StarArray = new int[1000][2];
    	private MaraudersOfDeepSpace mar = null;
    	
    	public MenuPanel(MaraudersOfDeepSpace mar)
    	{
    		[COLOR="#FF0000"]System.out.print("2/");[/COLOR]
    		this.mar=mar;
    		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    		this.add(Box.createRigidArea(new Dimension(0,180)));
    		AddAButton("New", this); //NEEDS MODIFICATION WHEN TIME IS RIGHT
    		this.add(Box.createRigidArea(new Dimension(0,20)));
            AddAButton(mar.LOAD, this);
            this.add(Box.createRigidArea(new Dimension(0,20)));
            AddAButton(mar.OBJECTIVE, this);
            this.add(Box.createRigidArea(new Dimension(0,20)));
            AddAButton(mar.CONTROLS, this);
            [COLOR="#FF0000"]System.out.print("3/");[/COLOR]
            
    	}
    	
        private void AddAButton(String text, Container container) {
            JButton button = new JButton(text);
            button.setAlignmentX(CENTER_ALIGNMENT);
            button.addActionListener(this);
            container.add(button);
        }
        
        public void paintComponent(Graphics g) {
        	g.setColor(Color.BLACK);
        	g.fillRect(0, 0, getWidth(), getHeight());
        	System.out.print("5/");
        }
    
    	@Override
    	public void actionPerformed(ActionEvent arg0) {
    		// TODO Auto-generated method stub
    		
    	}
    
    }
    So it's actually just a simple JApplet with a JPanel...but it refuses to show on the site

    What did I already try?? (before you think I'm just too lazy!! :o)
    - Putting another JApplet in place in the HTML-code, works fine (my conclusion: nothing wrong with HTML code??)
    - Invoking a paint() procedure in the JApplet (simple one: just color the background black) and it works, the black JApplet is shown on the site (but it doesn't show the JPanel)
    - Adding setVisible(true) in the JPanel --> nope (would be too easy -_-)
    - Adding setContentPane(cards) or setContentPane(mainMenu) --> nothing..
    - Adding setOpaque(true) in the JPanel --> nope..
    - Reading the tutorial on Oracle about JApplet with JPanels, didn't get anything out of it...

    Thanks in advance,

    Resk

    (PS: sorry for disturbing peace and quiet again...:s)
    Last edited by Reskaillev; 09-10-2011 at 12:23 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: JApplet works in eclipse but refuses to show online

    Are there any error messages in the browser's java console?

  3. #3
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default Re: JApplet works in eclipse but refuses to show online

    Quote Originally Posted by Norm View Post
    Are there any error messages in the browser's java console?
    Nope it doesn't give any error messages whatsoever...

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: JApplet works in eclipse but refuses to show online

    Start adding some printlns so you can see where the execution flow is going.

  5. #5
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default Re: JApplet works in eclipse but refuses to show online

    Not sure how to add system.out.prints when I can't see the JApplet in the browser? (and thus can't see the prints)

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: JApplet works in eclipse but refuses to show online

    The printouts go to the java console.

  7. #7
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default Re: JApplet works in eclipse but refuses to show online

    Quote Originally Posted by Norm View Post
    The printouts go to the java console.
    Okay I added the printouts to the code:
    system.out.print("1/") <--at the start on the init() of JApplet
    system.out.print("2/") <--at the start of the constructor of my MenuPanel() class
    system.out.print("3/") <--at the end on the constructor of my MenuPanel() class
    system.out.print("4/") <--at the end of the init() of JApplet

    console in eclipse gives me: 1/2/3/4/

    Not sure if you wanted me to test this also when the JApplet is online when I open the site? I have enabled the java console but it doesn't show the 1/2/3/4/

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: JApplet works in eclipse but refuses to show online

    What do you see in the java console when you load the html page with the applet in a browser?

  9. #9
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default Re: JApplet works in eclipse but refuses to show online

    Err nothing much..it's supposed to show the prints right??

    none of that..this is what I get:

    Java Code:
    Java Plug-in 1.7.0
    Using JRE version 1.7.0-ea-b119 Java HotSpot(TM) Client VM
    User home directory = C:\Users\Pete Ravenshard
    ----------------------------------------------------
    c:   clear console window
    f:   finalize objects on finalization queue
    g:   garbage collect
    h:   display this help message
    l:   dump classloader list
    m:   print memory usage
    o:   trigger logging
    q:   hide console
    r:   reload policy configuration
    s:   dump system and deployment properties
    t:   dump thread list
    v:   dump thread stack
    x:   clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    UPDATE: well...this is certainly strange...
    I added "this.setcontentpane(cards);" and "cards.setOpaque(true)" to the init()
    Now when I try to load the webpage it gives nothing like always
    BUT if I reload the page a few times there's a CHANCE that the applet loads perfectly..
    really strange...

    Would be best if you were able to experience it yourself??
    Raw Menu Beta

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: JApplet works in eclipse but refuses to show online

    I see you are using java 1.7

    I have no idea why your prints are not showing on the java console.

  11. #11
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default Re: JApplet works in eclipse but refuses to show online

    Quote Originally Posted by Norm View Post
    I see you are using java 1.7
    Yes but I build them with java 1.6 in JDK. Could there be any conflict?

    Quote Originally Posted by Norm View Post
    I have no idea why your prints are not showing on the java console.
    Neither do I :(

    What do you make of the "chance" to get the black screen? or does the black screen always show for you?

    PS: updated the above JPanel and JApplet code to correspond the changes I made
    Last edited by Reskaillev; 09-10-2011 at 12:21 AM.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: JApplet works in eclipse but refuses to show online

    Can you find a 1.6 plugin on another computer and test your applet there?

  13. #13
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default Re: JApplet works in eclipse but refuses to show online

    not at the moment..

    I tried building the applet in 1.7 and see if the problem would be fixed then...but to no avail..still the "chance" and still no prints

  14. #14
    Reskaillev is offline Member
    Join Date
    Jul 2011
    Posts
    53
    Rep Power
    0

    Default Re: JApplet works in eclipse but refuses to show online

    Ok I found a pc with java 1.6, enabled the java console and loaded the website...

    The applet works now 100%, but it still doesn't show the printlns in the console?

    the biggest atm remains: why do I get the "chance" to see the applet on my java 1.7 pc?? (the printlns are strange, but don't really matter in the full run)

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: JApplet works in eclipse but refuses to show online

    still doesn't show the printlns in the console
    No idea what is wrong. I've never had a problem seeing what I print on the java console.

Similar Threads

  1. [ask] why doesn't eclipse show hints?
    By aegean247 in forum Eclipse
    Replies: 0
    Last Post: 08-29-2011, 08:51 PM
  2. Works in Eclipse but not in browser
    By panini in forum Java Applets
    Replies: 3
    Last Post: 12-14-2009, 03:34 AM
  3. JFrame to JApplet or JApplet to JApplet
    By ramesh.8189 in forum AWT / Swing
    Replies: 13
    Last Post: 02-08-2009, 06:14 AM
  4. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 06:20 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
  •