|
|
Re: Dynamic Web Project : Applet not showing in browser [message #764981 is a reply to message #764924] |
Tue, 13 December 2011 08:12 |
javasee 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
|
|
|
|
|
Applet not showing in browser [message #837248 is a reply to message #770554] |
Thu, 05 April 2012 12:46 |
Ganesh gothi 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 317 times)
[Updated on: Thu, 05 April 2012 12:56] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.09263 seconds