By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,092 Members | 1,597 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,092 IT Pros & Developers. It's quick & easy.

miffed and need help to run application

P: n/a
gg
I was playing with some free java code but I was miffed.

In the current working directory, I have xyz.jar and a subdirectory
coresrvlets. The classes of the package coreservlets are naturally all in
the subdirectory coreservlets. Furthermore xyz.jar has the library that some
of the coreservlets classes may cay on.

I can't run the ShadowedTextFrame class from the current directory with
java -classpath .;xyz.jar coreservlets\ShadowedTextFrame
nor
java -classpath .;xyz.jar;coreservlets coreservlets\ShadowedTextFrame

( I get something like
Exception in thread "main" java.lang.NoClassDefFoundError:
coreservlets\ShadowedTextFrame (wrong name: coreservlets/ShadowedTextFrame)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java :486)

)
However, I could run an applet which calls the above ShadowedTextFrame from
the current directory like this
appletviewer ShadowedText.html
where ShadowedText.html has an applet tag like this
<applet
code=coreservlets\ShadowedTextApplet.class
name=ShadowedTextApplet
archive=xyz.jar
width=320
height=300 >
<param name="MESSAGE" value="TEST text shadow">

</applet>
What do I need to do so I can run the ShadowedTextFrame class directly with
the java command?
ShadowedTextFrame.java looks to me perfectly like a regular swing java
application to me with its main. and the source code is as follows

The package coreservlets;

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

import java.awt.event.*; // for the listeners
/** Interactive interface to MessageImage class.
* Enter message, font name, and font size on the command
* line. Requires Java2.
* <P>
* Taken from Core Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
* &copy; 2000 Marty Hall; may be freely used or adapted.
*/

public class ShadowedTextFrame extends JPanel {
private Image messageImage;

public static void main(String[] args) {
String message = "Shadowed Text";
if (args.length > 0) {
message = args[0];
}
String fontName = "Serif";
if (args.length > 1) {
fontName = args[1];
}
int fontSize = 90;
if (args.length > 2) {
try {
fontSize = Integer.parseInt(args[2]);
} catch(NumberFormatException nfe) {}
}
JFrame frame = new JFrame("Shadowed Text");
frame.addWindowListener(new ExitListener());
JPanel panel =
new ShadowedTextFrame(message, fontName, fontSize);
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
}

public ShadowedTextFrame(String message,
String fontName,
int fontSize) {
messageImage = MessageImage.makeMessageImage(message,
fontName,
fontSize);
int width = messageImage.getWidth(this);
int height = messageImage.getHeight(this);
setPreferredSize(new Dimension(width, height));
}

public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(messageImage, 0, 0, this);
}

}


Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.