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

Ads
 

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

Ads









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 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
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
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 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
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
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 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
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
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
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
Applet
Applet  how to run an applet on a web browser
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 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
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
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
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
insertion sort applet code
insertion sort applet code  i need Insertion Sort Applet Program
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
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 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
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
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" %>
<applet> tag requires code attribute.
applet tag requires code attribute.  import java.applet.*; import java.awt.*; import java.awt.image.*; /*<applet code...="swsm.jpg"> <applet/>
Applet in Java
Applet is a Java program designed for execution within the web browser... the Internet and run them. An Applet is a Java subclass that extends... applications. They run remotely on the client browser and cannot access system
Java Applet
Applets are Java programs that run on java enabled web browser. Java applets...: There are various advantages of using Java Applets: They can run on any...: Web browsers and operating system require Java plug-in to run applet
combo box code problem
combo box code problem  in this my problem related to : when i select state MP then i wil open the its corresponding city but in database it only...("Browser does not support XMLHTTP Request") return; } var url

Ads