Applet run with appletviewer but not in browser, any code problem.

Applet run with appletviewer but not in browser, any code problem.

Hi,My problem is when I am running my applet in appletviewer index.html, Its work fine but not run from the browser as http://localhost:8080/ProgressoApplication/index.html I am using "dynamic web application" in eclipse. I want all the 52 cards will be show in browser as by "appletviewer" and run as "java applet" I can be problem in code also. please check my code.


1) Card.java
 package com.progresso;


import java.awt.Image;

public class Card{

    private static final long serialVersionUID = 1L;
    Image image;
    int x;
    int y;


    public Card(Image image, int x, int y)  //here x and y is 0-51;
    {
        this.image = image;
        this.x = x;
        this.y = y;
       //System.out.println("Card is: "+this.image); // image name of the package cards.cards

    }


}



2) CardDemo.java
   I am running this file as java applet its working, but not on browser.
Please check can I call a CardDemoGUI constructor from CardDemo class constructor, because when I am comiling this .java file from command prompt with JDK set path, its giving ERROR.
ERROR is ----
CardDemo.java:94: cannot find symbol
symbol  : class CardDemoGUI
location: class com.progresso.CardDemo
  this.setContentPane(new **C**ardDemoGUI());// error on bold line,
please help me ASAP, because I am trying for three day's, please help me

am using class file that is generated in build/classes/com/progress/MyAll.class file

Code is for CardDemo.java------

package com.progresso;
import java.awt.TextField;

import java.util.Date;

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() 
    { 
         // a standard layout to place just one textfield 
         clockField = new TextField(); 
         add(clockField,"Center"); 
         // Create the thread. 
         clockThread= new Thread(this); 
         // and let it start running 
         clockThread.start(); 
    }
    public void destroy() 
    { 
         // will cause thread to stop looping 
         running = false; 
         // destroy it. 
         clockThread = null; 
    } 

    public void run() 
    { 
         // loop until told to stop 
         while (running) 
         { 
              // Construct the current date. 
              date = new Date(); 
              // Get the hours, minutes and hours 
              String time = date.getHours()+":"+date.getMinutes()+":"+date.getSeconds(); 
              // Put that result in the textfield 
              clockField.setText(time); 
              //Now the reason for threads 
              try 
              { 
                    // Wait 500milliseconds before continuing 
                   clockThread.sleep(500); 
              } 
              catch (InterruptedException e) 
              { 
                   System.out.println(e); 
               } 
              // he has wait and will now restart his actions. 

         } 
    } 
    /**public static void main(String[] args) {
     JFrame window = new JFrame();
     window.setTitle("Progresso-Not The Soup");
     //window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     //window.setContentPane(new CardDemoGUI());
     window.pack();
     window.show();
     window.dispose();
 }//end main*/

 //=================================================== applet constructor
 /** Constructor for applet */
 public CardDemo() {

    this.setContentPane(new CardDemoGUI());
 }

 }//endclass CardDemo

and 3) CardDemoGUI:-


package com.progresso;

import java.awt.*;
import java.awt.event.*;

import javax.imageio.ImageIO;
import javax.swing.*;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
/////////////////////////////////////////////////////////// class CardDemoGUI
/** CardDemoGUI.java - Panel that allows dragging playing card images.
    @author Fred Swartz
    @version 2004-04-23
*/
public 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     = 0;   // x coord - set from drag
    private int _initY     = 0;   // 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;

    private Card[] _deck = new Card[52];
    private Card[] _deck1 = new Card[52];
    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 = "shdc";
        String faces = "a23456789tjqk";
        String title_panel= "Progresso-Not The Soup";
        int cardPosition = 0;
        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++) 
            {
                 //ImageIcon img = new ImageIcon("cards/"+ faces.charAt(face)
                                             //+ suits.charAt(suit) + ".gif");
                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_table.gif"));
                _deck[cardPosition++] = new Card(image, _initX++, _initY++);

                setBackground(Color.PINK);

             }
        } 
        }catch (IOException ex) {
            // handle exception...
       }

        this.addMouseListener(this); 
        this.addMouseMotionListener(this);
    }//endconstructor

      //=================================================== method paintComponent
    /** Ball is drawn at the last recorded mouse listener coordinates. */
    public void paint(Graphics g) {

        super.paint(g);   // Required
        g.drawImage(Casinoimage, 400, 200, this);
        //-- Display the cards, starting with the first array element.
        //   The array order defines the z-axis depth.

        for(int i=0;i<10;i++)
        {
        for (int crd=0; crd<_deck.length; crd++) 
            {
                    for (crd=0; crd<_deck1.length; crd++) 
                        {
                            Card c = _deck[crd];
                            //c.image.paintIcon(this, g, c.x, c.y);// here c.x=0-51 and c.y=0-51
                            //g.drawOval(20, 27, 50, 50);
                            g.drawImage(c.image, c.x+50,c.y+50, this);
                            //c.setBound(100,100,100,100);
                        }
                   }
       }


    }//end paintComponent
    //===================================================== method mousePressed

    public void mousePressed(MouseEvent e) {
        int x = e.getX();   // Save the x coord of the click
        int y = e.getY();   // Save the y coord of the click

        _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);
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        repaint(); 
                    }
                });
                break;   // Stop when we find the first match.

            }
        }
    }//end mousePressed


    //============================================================ mouseDragged
    /** Set x,y to mouse position and repaint. */
    public void mouseDragged(MouseEvent e) {
        if (_currentCard != null) {   // Non-null if pressed inside card image.
            _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);
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {

                    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
    public static void invokeAndWait(Runnable doRun) throws InterruptedException,InvocationTargetException
    {
           final Runnable doHelloWorld = new Runnable() {
        public void run() {
            System.out.println("Hello World on " + Thread.currentThread());
        }
    };
    Thread appThread = new Thread() {
        public void run() {
            try {
                SwingUtilities.invokeAndWait(doHelloWorld);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("Finished on " + Thread.currentThread());
        }
    };
    appThread.start();
    }


}//endclass CardDemoGUI
View Answers









Related Tutorials/Questions & Answers:
Applet run with appletviewer but not in browser, any code problem.
Applet run with appletviewer but not in browser, any code problem.  Hi,My problem is when I am running my applet in appletviewer index.html, Its work... the 52 cards will be show in browser as by "appletviewer" and run as "java applet" I
Problem In applet Its run on browser but hang and blinking when image is draging some where.
Problem In applet Its run on browser but hang and blinking when image is draging some where.  I am Created applet in working properly on browser. In my applet 52 card images is draw and drage and move on the applet, but when I am
Advertisements
how to run applet - Applet
then if you got any problem, please send the code. Thanks... in applet program. this is executed successfully with appletviewer command >appletviewer -J-Djava.security.policy=A0.txt A0.html but cannot in browser
how to run a applet from browser
how to run a applet from browser  hi, iam sending the code of an applet. it is working in cmd prompt,but not working from browser. <APPLET CODE... error. plz suggest me the related code to execute from browser. import
Code Problem - Applet
Code Problem  How to set a background color for frame and panel ...? What is the difference btw these two(in setting background color)..?  ...().setBackground(Color.RED); } } If we use panel or any other container
The Java Applet Viewer
in a web page and run within a web browser. The applet's code gets transferred.... It is included in the SDK. It helps you to test an applet before you run it in a browser... that code and displays the output.. So for running the applet,  the browser
to run html code in web browser - JSP-Servlet
to run html code in web browser  how to run jsp file which calls html file on web browser??  Hi Friend, Try the following code: 1)form.jsp: Enter Name: 2)welcome.html: Add Profile Edit
Need change in code to make website compatible with any browser
website but the problem is the website will open in only IE not any other browser. So i should make changes in code so that website can open in any browser. What...Need change in code to make website compatible with any browser  I
Java - Applet Hello World
. You will learn how to develop applet code and run in the browser. Applet... console: java HelloWorldApplet Running Applet from Web browser:ADS_TO_REPLACE_3 Running applet in browser is very easy job, create an html file
The Java Applet Viewer
in a web page and run within a web browser. The applet's code gets transferred.... It is included in the SDK. It helps you to test an applet before you run it in a browser... that code and displays the output.. So for running the applet,  the browser
The Java Applet Viewer
to test an applet before you run it in a browser. Before going any further, lets... a web browser. The applet's code gets transferred to the system... the applet viewer and the web browser to run the applet is that the applet viewer only
Java Code to Block a website accessed by any browser in windows
Java Code to Block a website accessed by any browser in windows  I want create an application in Java through Netbean IDE to block any website to be accessed by any browser. I also want to display only its html contents. please
applet program code - Applet
applet program code  hello sir, i did't get the code for below problem... please help me... 1.An applet program to draw a line graph for y=2x+5.[for suitable values of x & y
I am new to java applets. When i run this code on applet viewer status is displayed that applet not initialized
I am new to java applets. When i run this code on applet viewer status is displayed that applet not initialized  import java.awt.*; import java.awt.event.*; import java.applet.*; public class Textfields extends Applet implements
problem with applet plugin - Applet
problem with applet plugin  hello friends, iam using Eclipse IDE. i created one applet and i want to plugin that applet into webpage.. when i am...-->com.ezsoft.applets.Upload.java please friends how can i resolve that problem
Problem in show card in applet.
On Run as Java Applet then only show the Applet, not show any one card,hence any...Problem in show card in applet.  The following link contained...-tips/45examples/30graphics/cardDemo/cardDemo.shtml Now I am trying to run this code in eclipse
applet problem - Applet
applet problem  How can I create a file in client side by a java applet . Surely it will need a signed applet .But how can a signed applet create a file in the client side
java applet problem - Applet
java applet problem  i was doing a program using java applet. I want... and to exit from the applet respectively.Now i want to display a message when... Friend, Try the following code: import java.applet.*; import java.awt.event.
this is my code but i cant able to run it wt is the problem
this is my code but i cant able to run it wt is the problem  import java.io.*; class createthread { int thread=4,i; class thread1 extends createthread { public void run() { for(i=0;i
this is my code but i cant able to run it wt is the problem
this is my code but i cant able to run it wt is the problem  import java.io.*; class createthread { int thread=4,i; class thread1 extends createthread { public void run() { for(i=0;i
Problem with display of images in applets - Applet
Problem with display of images in applets  Hi all, When I run this program, the appletviewer window is showing no output (i.e. no image). I'm... java.applet.*; public class image extends Applet { Image img; public
Applet code parameter - Applet
Applet code parameter  Hi... I've designed an applet where i placed... How can i get that class... I used code="MyProgram.class" codebase="WEB-INF/classes" but this didn't worked i also tried code="WEB
Browser Crashes Suddenly : Application uses applet - Applet
Browser Crashes Suddenly : Application uses applet   Hello All, All of sudden, when the application is running the browser IE6 gets crashed . JRE used is 1.5.0_05. Can anyone please help me out . Its urgent.. Vishal
The Java Applet Viewer
be stored in a web page and run within a web browser. The applet's code gets... it in a browser. Before going any further, lets see what an applet is? An applet... tags. The difference in using the applet viewer and the web browser to run
Change in website page to any browser compatible
but the problem is the website will open in only IE not in any other browser. When it open in any other browser it shows source code. So i should make changes in code so...Change in website page to any browser compatible  I have newly joined
Moving Applet Problem
Moving Applet Problem  When image scroll in applet then a blinking... java.awt.Image; public class PlaneAnimation extends Applet implements Runnable...(),"AnimatedAirplane.gif"); t1.start(); } @Override public void run
java applet run time error - Applet
java applet run time error  Hi, Im new to java applet.please help me. i have create a MPEG movie player in applet. when i run that program...: " My code is below: //html code //PlayerApplet file
Applet versus Application
browser's window or in an appletviewer. To run the applet in an appletviewer... browser. On the other hand applet have the accessibility criteria of the resources... the native methods, run any program on the user system or load shared libraries
Security Issues with the Applet
;     Java applet is run inside a web browser. But an applet is restricted in some areas, until it has been deemed... programs on the client. That means any applet, which you visited, cannot start any
Java Web Browser Problem
Java Web Browser Problem  Hello When run my web browser this is not displaying complete page any of the website like other browser.So Plz help me...."); setTitle("NextVision Browser"); setSize(600,400); Container
applet code - Java Beginners
applet code  hi friends.. i have to oen one applet, in that applet code should be apper what we have written for the applet... this is my...://www.roseindia.net/java/example/java/applet/ Hope that it will be helpful
Crop Image Code in Applet
Crop Image Code in Applet  Sir, Can somebody please provide me with code to crop and save an image in applet
Crop Image Code in Applet
Crop Image Code in Applet  Sir, Can somebody please provide me with code to crop and save an image in applet
Java code - Applet
Java code  I want java applet code for drawing an indian flag
Applet
Applet  how to run an applet on a web browser
JSP run problem
JSP run problem  type Exception report message description...; Post your code. It seems that there is a programming error. Check your code.   OK this the code plz help me as quik as possible thnk u
Run time problem
Run time problem  when i run a project,it shows an exception like "unable to create MIDlet".It also shows "running with locale:English_united States.1252 running in the identified third party security domain" "please help
insertion sort applet code
insertion sort applet code  i need Insertion Sort Applet Program
servlet code - Applet
servlet code  how to communicate between applet and servlet  Hi Friend, We are providing you the code that will display the message sent from the servlet to applet. Here is the code of 'ServletExample.java
Java Code - Applet
Java Code  How to Draw various charts(Pie,Bar,and Line etc.)using Applet
Code not working
in appletviewer. but not in browser. how to run it in browser also plz tell me soon...Code not working  i want to write my first applet. I wrote the java program and html code for that. while im running in appletviewer it is asking
problem of writing to a local file ( JApplet ) - Applet
to a file from JApplet. it is working without any problem if i run the program using java GuestBook or if I run it using the appletviewer, but if I put the class file into the applet code it is not working, means when i click the Submit button
need code for file browser
need code for file browser  hi, i need to write a code to browse the file in my computer using Jsp or java.. what is the code for file browser?   JSP Code for browsing: 1)page.jsp: <%@ page language="java" %>
run php code online
run php code online  Is it possible to run PHP Code online
Run a simple EJB code
Run a simple EJB code  I found the code this. However, as I have no idea with EJB, I can't understand how to run it. Can anybody help me by giving steps (by giving snapshots or writing full procedure)how to run it (any platform
Run a simple EJB code
Run a simple EJB code  I found the code this. However, as I have no idea with EJB, I can't understand how to run it. Can anybody help me by giving steps (by giving snapshots or writing full procedure)how to run it (any platform
code to disable back button of browser
code to disable back button of browser  code to disable back button of browser
code to disable back button of browser
code to disable back button of browser  code to disable back button of browser
Closing any kind of browser window without confirmation using javascript
help me in resolving this problem. It should support any kind of browser and any...Closing any kind of browser window without confirmation using javascript  Here is my requirement, I have to close a browser window on onload event
Hibernate code problem - Hibernate
.....How can i solve this problem. Am i need to Kept any other jars in path. ... problem please send me code. Visit for more information. http...Hibernate code problem  Hi This is Raju.I tried the first example

Ads