Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Dynamic Web Project : Applet not showing in browser
Dynamic Web Project : Applet not showing in browser [message #764783] Mon, 12 December 2011 20:57 Go to next message
javasee is currently offline javaseeFriend
Messages: 3
Registered: December 2011
Junior Member
Hi!

I recently finished my interactive GUI-application which I intend to put into a webpage, so I changed the application into an applet and started a dynamic web project. However, the applet doesn't show when I open the html file with internal browser. The applet contains quite a lot of java code, so I decided to make a test with very simple html and java, and the result was the same.

Here is the html body:

"This is HTML text before applet.
<applet code="TestApplet.class" width="200" height="200"></applet>
This is HTML text after applet."

And here is the applet:

"import java.awt.*;
import java.applet.*;
public class TestApplet extends Applet {
public void init() {
}
public void paint(Graphics g) {
g.drawString("This is applet text.", 50, 50 );
}
}"

When I open the html in the internal browser, the output is:
"This is HTML text before applet. This is HTML text after applet."

So it seems that something very basic is missing from my project settings. I've been using only default values and I don't have a clue. Any help here would be appreciated.
Re: Dynamic Web Project : Applet not showing in browser [message #764924 is a reply to message #764783] Tue, 13 December 2011 05:24 Go to previous messageGo to next message
Javak  is currently offline Javak Friend
Messages: 26
Registered: November 2011
Junior Member
The applet's compiled class file should be put at the same place as the HTML file. Please double check this.
Re: Dynamic Web Project : Applet not showing in browser [message #764981 is a reply to message #764924] Tue, 13 December 2011 08:12 Go to previous messageGo to next message
javasee is currently offline javaseeFriend
Messages: 3
Registered: December 2011
Junior Member
For some reason the class file is not shown in the project's "build"-directory (the directory seems to be empty instead). Anyhow outside of Eclipse from Windows' file system you can see that the file "TestApplet.class" really is in directory "TestProject/build/classes". The html file "TestHTML.html" is placed in "WebContent". To make sure that the two files are close enough, I copy-pasted the class file into WebContent-folder, but there was no change.

I added some System.out.println-lines to the javacode to see if it writes anything to the console (I guess this can be done in web-projects, too?) Well, there was no output. I also changed the width and height parameters in the html file to see if that produces any effect, and it does. So it seems that parameters in the html are ok but for some reason the javacode doesn't execute. But why?

[Updated on: Tue, 13 December 2011 08:25]

Report message to a moderator

Re: Dynamic Web Project : Applet not showing in browser [message #764995 is a reply to message #764981] Tue, 13 December 2011 08:39 Go to previous messageGo to next message
javasee is currently offline javaseeFriend
Messages: 3
Registered: December 2011
Junior Member
Hey thanks Javak! Now after copying the class file into WebContent the applet works in Internet Explorer though not in the internal browser and Firefox. So the applet code really runs at least in some browser.

But does this mean that this kind of copying should be done every time by hand? And does anyone have a clue why this doesn't run properly in Firefox and internal browser?
Re: Dynamic Web Project : Applet not showing in browser [message #770554 is a reply to message #764995] Sat, 24 December 2011 16:17 Go to previous messageGo to next message
Javak  is currently offline Javak Friend
Messages: 26
Registered: November 2011
Junior Member
The compile classes file should be placed under WebContent/WEB-INF/clases, so modify this line in the TestHTML.html file:

<applet code="TestApplet.class" width="200" height="200"></applet>

to:

<applet code="WEB-INF/classes/your/package/name/TestApplet.class" width="200" height="200"></applet>

Hope this helps.
Applet not showing in browser [message #837248 is a reply to message #770554] Thu, 05 April 2012 12:46 Go to previous messageGo to next message
Ganesh gothi is currently offline Ganesh gothiFriend
Messages: 1
Registered: April 2012
Junior Member
Hi have tried web application exactly like above problem,
Now I am really in trouble, Please help me ASAP.
I have created two class 1) Card.java and 2) cardDemo.java(It's Applet) in eclipse and create htmi page index.html in webcontent folder, now I am trying to run this applet in html form its gives a Application Error, I have also tried paste classes folder in WEB-INF and change path applet tag, but not working.
Now my CardDemo and Card class is related ,bellow is the code,

CardDemo.java:-

package com.progresso;



import java.awt.Button;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
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.applet.Applet;

import javax.imageio.ImageIO;


public class CardDemo extends Applet implements MouseListener,MouseMotionListener,ActionListener
{




Button PlayGmae;
Image image;
int x;
int y;

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
/** 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 _currentCard = null; // Current draggable card.

public void init()
{
System.out.println("init");

}
public void start()
{

}
public void stop()
{
System.out.println("stop");

}

public void distroy()
{
System.out.println("distroy");

}

//=================================================== applet constructor

//============================================================= constructor
/** Constructor sets size, colors, and adds mouse listeners.
* @param initY
* @param initX
* @param image */
public CardDemo() {
//-- Read in the cards

String suits = "shdc";
String faces = "a23456789tjqk";
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
_deck[cardPosition++] = new Card(image, _initX++, _initY++);
System.out.println("1");

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


//-- Initialize graphics
//setPreferredSize(new Dimension(600, 600));
setBackground(Color.gray);
setForeground(Color.BLACK);
//--- Add mouse listeners.
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
//-- Display the cards, starting with the first array element.
// The array order defines the z-axis depth.

for (int crd=0; crd<_deck.length; crd++) {
Card c = _deck[crd];
//System.out.println("ok");
//c.image.paintIcon(this, g, c.x, c.y);// here c.x=0-51 and c.y=0-51
g.draw3DRect(350, 150, 600, 450,true);
g.drawImage(c.image, c.x,c.y, null);

}

g.drawString("Progresso Application", 400, 50);



}//end paintComponent

public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub

}

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

//-- Find card image this is in. Check from top down.
_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; // 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);

repaint(); // Repaint because position changed.
}
}//end mouseDragged


//=============================================== 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
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub

}


}//endclass CardDemo


Card.java:-

package com.progresso;


import java.awt.Image;







/////////////////////////////////////////////////////////////////// Card
/** Card.java - Utility class for grouping the image and its position.
A real card game would expand this into a better class.
@author Fred Swartz
@version 2004-04-23
*/
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

}


public void setLayout(Object object) {
// TODO Auto-generated method stub

}
}
/*
<applet code="CardDemo.class" width=500 height=500>
</applet>
*/

My applet is running from Run as->Java Applet
please -please help me what can i do.
please see the broblem in attachment file
I am running using tomcate URL is

  • Attachment: problem.bmp
    (Size: 2.00MB, Downloaded 301 times)

[Updated on: Thu, 05 April 2012 12:56]

Report message to a moderator

Re: Applet not showing in browser [message #840440 is a reply to message #837248] Tue, 10 April 2012 04:57 Go to previous message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

NOTHING under WEB-INF is served to the browser (client). The classes folder there is meant to be used only for server-side code.

_
Nitin Dahyabhai
Eclipse Web Tools Platform
Previous Topic:Color code new file type
Next Topic:eclipse plugin for PHP files
Goto Forum:
  


Current Time: Tue Apr 16 23:28:40 GMT 2024

Powered by FUDForum. Page generated in 1.75565 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top