Page 1 of 2 12 LastLast
Results 1 to 20 of 33
Like Tree1Likes

Thread: My applet is not running on browser.

  1. #1
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default My applet is not running on browser.

    Hi guys,
    I am working on java game web application. now for this I have created java applet and successful run on eclipse as run as ->java applet.
    now I have created class file from command prompt, its generate three class. Now the html code for applet is below:

    XML Code:
    <applet code="com/progresso/CardDemo.class"  width="675" height="550">
    			If your browser was Java-enabled, a "Hello, World"
    message would appear here.
    	       </applet>
    but its showing only white screen for the place of applet. My full code is:

    Java Code:
    package com.progresso;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.TextField;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    
    import java.io.File;
    import java.io.IOException;
    import java.util.Date;
    
    import javax.imageio.ImageIO;
    import javax.swing.*;
    
    public class CardDemo extends JApplet implements Runnable
    	{
    
    	private static final long serialVersionUID = 1L;
    	Thread clockThread; 
        TextField clockField; 
        Date date;
    //========================================================== method main
     /** Create JFrame, add the CardDemoPanel, display. */
        boolean running = true;
       
        public void init() 
        { 
        }
       
     //=================================================== applet constructor
     /** Constructor for applet */
     public CardDemo() {
    	  
         this.setContentPane(new CardDemoGUI());
     }
     
    
    class CardDemoGUI extends JPanel implements MouseListener, 
    MouseMotionListener {
    /**
    * 
    */
    private static final long serialVersionUID = 1L;
    private static final int IMAGE_WIDTH = 73;
    private static final int IMAGE_HEIGHT = 97;
    
    //--- instance variables
    /** Initial image coords. */
    private int _initX     = 105;   // x coord - set from drag
    private int _initY     = 210;   // y coord - set from drag
    Image image,Casinoimage; 
    /** Position in image of mouse press to make dragging look better. */
    private int _dragFromX = 0;  // Displacement inside image of mouse press.
    private int _dragFromY = 0;
    int cardPosition = 0;
    private Card[] _deck = new Card[104];
    
    private Card _currentCard = null;  // Current draggable card.
    
    
    //============================================================= constructor
    /** Constructor sets size, colors, and adds mouse listeners.
    * @param deck */
    public  CardDemoGUI() {
    //-- Read in the cards
    String suits = "shdcshdc";
    String faces = "a23456789tjqk";
    //String title_panel= "Progresso-Not The Soup";
    
    try {                
    //image = ImageIO.read(new File("cards/2c.gif"));
    for (int suit=0; suit<suits.length(); suit++) 
    {
    for (int face=0; face<faces.length(); face++) 
    {
    
    image = ImageIO.read(new File("cards/"+ faces.charAt(face)
    + suits.charAt(suit) + ".gif"));// all card fetch from here in loop
    
    Casinoimage = ImageIO.read(new File("cards/casino_table1.gif"));
    _deck[cardPosition++] = new Card(image, _initX++, _initY);
    setBackground(Color.PINK);
    
    }
    } 
    }catch (IOException ex) {
    
    }
    
    this.addMouseListener(this); 
    this.addMouseMotionListener(this);
    }//end constructor
    
    
    public void paint(Graphics g) {
    
    super.paintComponent(g);   // Required
    System.out.println("ok");
    g.drawImage(Casinoimage, 400, 200, this);
    for(int i=0;i<10;i++)
    {
    for (int crd=0; crd<_deck.length; crd++) 
    {
    	Card c = _deck[crd];
    	g.drawImage(c.image, c.x,c.y, this);
    }
    }
    
    }//end paintComponent
    
    public void mousePressed(MouseEvent e) {
    int x = e.getX();  
    int y = e.getY();   
    System.out.println(x);
    System.out.println(y);
    _currentCard = null;  // Assume not in any image.
    for (int crd=_deck.length-1; crd>=0; crd--) {
    Card testCard = _deck[crd];
    if (x >= testCard.x && x <= (testCard.x + IMAGE_WIDTH)
    && y >= testCard.y && y <= (testCard.y + IMAGE_HEIGHT)) 
    {
    _dragFromX = x - testCard.x;  // how far from left
    _dragFromY = y - testCard.y;  // how far from top
    _currentCard = testCard;  // Remember what we're dragging.
    System.out.println(_currentCard);
    
    break;
    
    }
    
    }
    }//end mousePressed
    
    public void mouseDragged(MouseEvent e) {
    if (_currentCard != null) {  
    _currentCard.x = e.getX() - _dragFromX;
    _currentCard.y = e.getY() - _dragFromY;
    
    //--- Don't move the image off the screen sides
    _currentCard.x = Math.max(_currentCard.x, 0);
    _currentCard.x = Math.min(_currentCard.x, getWidth()-IMAGE_WIDTH);
    
    //--- Don't move the image off top or bottom
    _currentCard.y = Math.max(_currentCard.y, 0);
    _currentCard.y = Math.min(_currentCard.y, getHeight()-IMAGE_HEIGHT);
    this.repaint(); 
    
    }
    }//end mouseDragged
    
    //====================================================== method mouseExited
    /** Turn off dragging if mouse exits panel. */
    public void mouseExited(MouseEvent e) {
    _currentCard = null;
    System.out.println("7");
    }//end mouseExited
    
    //=============================================== Ignore other mouse events.
    public void mouseMoved   (MouseEvent e) {  }  // ignore these events
    public void mouseEntered (MouseEvent e) {  }  // ignore these events
    public void mouseClicked (MouseEvent e) {  }  // ignore these events
    public void mouseReleased(MouseEvent e) {  }  // ignore these events
    
    }//endclass CardDemoGUI
    class Card{
    	   
    	private static final long serialVersionUID = 1L;
    	Image image;
        int x;
        int y;
        
        
        public Card(Image image, int x, int y) 
        {
            this.image = image;
            this.x = x;
            this.y = y;
          
            
        }//end Card
     }//end class CardDemoGui
    @Override
    public void run() {
    	// TODO Auto-generated method stub
    	
    }
    	 }//endclass CardDemo

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: My applet is not running on browser.

    What error messages are in the browser's java console?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: My applet is not running on browser.

    Quote Originally Posted by Norm View Post
    What error messages are in the browser's java console?
    Only white screen is showing. No error message.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: My applet is not running on browser.

    Look again at the browser's java console.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: My applet is not running on browser.

    Quote Originally Posted by Norm View Post
    Look again at the browser's java console.
    I am sure no error message in java console.
    I think this can be a problem?
    I have created class file, and three class file is create, but I have used only one CardDemo.class in html, is it?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: My applet is not running on browser.

    If you can not see the browser's java console, you need to turn it on so you can see error messages.
    There is a java icon in the Control Panel that has options to display the java console.

    If you are seeing it, add lots of println statements to the methods in your code that will print messages on the java console so you can see where it is executing.

    ONE BIG PROBLEM YOU HAVE IS AN EMPTY CATCH BLOCK!!!
    Add a call to the printStackTrace() method
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: My applet is not running on browser.

    Error Message Is.

    Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
    at com.progresso.CardDemo$CardDemoGUI.paint(CardDemo. java:155)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JLayeredPane.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    at javax.swing.BufferStrategyPaintManager.paint(Unkno wn Source)
    at javax.swing.RepaintManager.paint(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at java.awt.GraphicsCallback$PaintCallback.run(Unknow n Source)
    at sun.awt.SunGraphicsCallback.runOneComponent(Unknow n Source)
    at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
    at java.awt.Container.paint(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
    at javax.swing.RepaintManager.prePaintDirtyRegions(Un known Source)
    at javax.swing.RepaintManager.access$700(Unknown Source)
    at javax.swing.RepaintManager$ProcessingRunnable.run( Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: My applet is not running on browser.

    Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
    at com.progresso.CardDemo$CardDemoGUI.paint(CardDemo. java:155)
    Look at line 155 and find the variable with the null value. Then backtrack in the code to see why that variable does NOT have a valid non-null value.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: My applet is not running on browser.

    Quote Originally Posted by Norm View Post
    Look at line 155 and find the variable with the null value. Then backtrack in the code to see why that variable does NOT have a valid non-null value.
    At Line 155
    The code is:

    public void mouseExited(MouseEvent e) { // this line is 155
    _currentCard = null;
    System.out.println("7");
    }//end mouseExited
    now I have commented this code like:-

    public void mouseExited(MouseEvent e) {
    //_currentCard = null;
    System.out.println("7");
    }//end mouseExited
    Now again giving the same error as I have posted.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: My applet is not running on browser.

    Java Code:
    at com.progresso.CardDemo$CardDemoGUI.paint(CardDemo. java:155)
    Java Code:
    public void mouseExited(MouseEvent e) { // this line is 155
    That isn't line 155 of CardDemo.java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  11. #11
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: My applet is not running on browser.

    I have posted code as it is in #1 post, that indicates the 155 line same as that I have posted. I am not getting the error and not solving problem please- please help me.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: My applet is not running on browser.

    Find line 155 and then find what variable on that line is null by printing out the values of all the variables on line 155.

    Line 155 is in the paint() method.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: My applet is not running on browser.

    I am not running my applet on browser, same error is occur that I have posted in #7, I have tried many times and also comment the error code(because its not affect the applet functionality), but not running applet now...... now what can I do for this ...please tell me.

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: My applet is not running on browser.

    same error is occur
    What variable is null? Find the reason the variable is null and change the program so it is not null.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: My applet is not running on browser.

    Quote Originally Posted by Norm View Post
    What variable is null? Find the reason the variable is null and change the program so it is not null.
    I have shifted my code from this line ,no code on 155 line , after that create class from command line and run on browser with applet tag on my localhost

    at Java console giving the same error:-

    Exception in thread "AWT-EventQueue-4" java.lang.NullPointerException
    at com.progresso.CardDemo$CardDemoGUI.paint(CardDemo. java:155)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JLayeredPane.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    at javax.swing.BufferStrategyPaintManager.paint(Unkno wn Source)
    at javax.swing.RepaintManager.paint(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at java.awt.GraphicsCallback$PaintCallback.run(Unknow n Source)
    at sun.awt.SunGraphicsCallback.runOneComponent(Unknow n Source)
    at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
    at java.awt.Container.paint(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
    at javax.swing.RepaintManager.prePaintDirtyRegions(Un known Source)
    at javax.swing.RepaintManager.access$700(Unknown Source)
    at javax.swing.RepaintManager$ProcessingRunnable.run( Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    I am confused that no code on the line and giving the same error, please give the idea where I am wrong.

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: My applet is not running on browser.

    You could be executing an old version of the code. To be sure, add a println that will print out a unique message so you will know that the current code is the one being executed, not an old version.

    Delete all .class files and create new ones.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: My applet is not running on browser.

    Thanks for the quick reply.
    now when I am running my applet from eclipse, its working fine and print
    Ok1 and
    OK in my eclipse java console

    but when this applet run on browser, no print ok1 and ok on browser java console only giving the same error that I have posted.
    I think my applet is not running on browser, if yes why?,,, please give me the reason behind that........

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: My applet is not running on browser.

    give me the reason behind that..
    Your code has a bug in it.
    You need to find what variable is null and change the code so it is not null.

    What variable is null?
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    Join Date
    Apr 2012
    Posts
    90
    Rep Power
    0

    Default Re: My applet is not running on browser.

    I don't know that what variable is null.
    but when I am running this applet on eclipse from Run as->java applet its working fine....
    and not showing on browser only applet area is showing and contained white screen in this area, my applet output is not showing, I am very very tried to find out my problem as per your answer, but not solving properly, any other way that I can run this applet that will see the applet on browser properly.

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: My applet is not running on browser.

    Look at the line of code that is shown in the error message. Find the variable with the null value.
    You need to do that to be able to fix the problem.

    Waiting for you to find the variable with the null value.
    If you don't understand my response, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 7
    Last Post: 12-18-2011, 04:13 AM
  2. How to run applet in a web Browser?
    By elururajesh3 in forum Java Applets
    Replies: 4
    Last Post: 11-06-2011, 09:34 AM
  3. applet working in applet viewer, not browser
    By plasticfood in forum Java Applets
    Replies: 4
    Last Post: 06-24-2011, 06:47 PM
  4. Java Applets not running in Any browser
    By umair in forum Java Applets
    Replies: 1
    Last Post: 12-27-2009, 04:46 PM
  5. applet won't run in browser...
    By shwein in forum Java Applets
    Replies: 6
    Last Post: 10-17-2008, 06:24 PM

Tags for this Thread

Posting Permissions

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