Home Answers Viewqa Java-Beginners Applet run with appletviewer but not in browser, any code problem.

 
 


Ganesh Gothi
Applet run with appletviewer but not in browser, any code problem.
0 Answer(s)      a year and a month ago
Posted in : Java Beginners

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 Pages:
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
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
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
Applet versus Application
browser's window or in an appletviewer. To run the applet in an appletviewer... to point here is that applets are unable to use the native methods, run any program... with the java applets. If we talk at the source code level, then we don't extend any
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
and can be stored in a web page and run within a web browser. The applet's code... it in a browser. Before going any further, lets see what an applet is? An applet...) of the browser executes that code and displays the output.. So for running the applet
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
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
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
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
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
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
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
Applet
. Applet is designed to run remotely on the client browser, so there are some... of html page. The java enabled browser loads class file of applet and run in its... and type appletviewer appletParameter.html Appletviewer will run the applet
unable to see the output of applet. - Applet
://www.roseindia.net/java/example/java/applet/FirstApplet.html but the problem...unable to see the output of applet.  Sir, I was going through the following tutorial http://www.roseindia.net/java/example/java/applet
browser
browser  hello this is saurav srivastav, thank you for sending the cvode for creating the menu item, but I want the code for file open and save frame in the swing because I am working on my project Browser and one more problem
Applet
Applet  how to run an applet on a web browser
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
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 - Passing Parameter in Java Applet
appletParameter.html Appletviewer will run the applet for you and and it should show output... will see what has to be done in the applet code to retrieve the value from...;BODY> This is the applet:<P> <APPLET code="
Java - Applet Hello World
. You will learn how to develop applet code and run in the browser. Applet... Running Applet from Web browser: Running applet in browser is very easy job...; <body> <APPLET CODE="HelloWorldApplet.class" WIDTH=700 HEIGHT=500
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
What is Applet? - Applet
. Applet viewer is a command line program to run Java applets. It is included in the SDK. It helps you to test an applet before you run it in a browser. Before going any further, lets see what an applet is?http://www.roseindia.net/java/java
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
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.
applet servlet communication - Applet
project in eclipse and writing the applet code in ajava file which is present in src... into WebRoot it is working. So my problem is when I made some changes in any java... to applet. 1)Here is the code of 'ServletExample.java' import java.io.
Applet Write Files Example
;} } Download this code. For running an applet you have to need an HTML file that uses the applet class to run this in the Java based web browser. Here...;TITLE> Write file example </TITLE> <applet code="
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
Applet in Eclipse - Running Applet In Eclipse
browser. The purpose of an applet is to extend the functionality of a Web page in a browser. The HTML document tells the browser to load and run an applet using... and run Applet in Eclipse IDE. In this section, you will learn how to run applet
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 - Applet
. Applet is designed to run remotely on the client browser, so there are some...Applet  what is the concept of applet? what is different between the applet concept and HTML? what is mean by swing?  Hi friend
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
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
The <APPLET> Tag in Detail
the example below. [<] APPLET [CODEBASE = codebaseURL] CODE... the base URL of the applet -- the directory or folder that contains the applet's code... the applet's compiled Applet subclass.  ALT = alternateText Any text that should
Applet is not Working
applet is not working in the browser Are you running Mac OS 9? Firstly check... then try to run the applet applet on Internet Explorer or on different Operating... using at least version 5.0 (Netscape / IE). Is your browser set to run Java
Swings - Applet
to call that class in applet. is it possible. or otherwise is there any way to deploy java class in browser. Give an example... Thanks in advance...  Hi Friend, Try the following code: 1)CountCharacters.java: public class
Servlet and Applet - Applet
Invoke and run an Applet from Servlet  How can i invoke and run an applet from servlet. Can anyone provide me the sample code
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
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
java applet - Applet
java applet  wants to creat address bar on my java applet.  Hi Applet don't provide a facility to create a address bar directly. You just create a text box. In this text box if you enter any http address
loading Java Applet - Applet
loading Java Applet  Hi, I use the archive tag to download my applet into the Browser It takes too long to load. Can I do it in several steps? In the first step i only need code for the log in, after login the rest. Can I
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
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 - Drawing Shapes Example in java
;    Introduction Applet is a program to run...; of any appletApplet viewer is used to view or test the applet whether...; <div align="center"> <APPLET CODE="
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
Java Applet - Creating First Applet Example
browser loads class file of applet and run in its sandbox. Here is the java code... and embedded within HTML page. It run on the java enabled web browser such as Netscape... Java Applet - Creating First Applet Example   
What is an Applet
such as mozila and internet explorer. Applet is designed to run remotely on the client browser, so there are some restrictions on it. Applet can't access system resources... if user allows Disadvantages of Java Applet: Java plug-in is required to run

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.