aspose file tools*
The moose likes Applets and the fly likes Applet working in appletviewer but no browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet working in appletviewer but no browser" Watch "Applet working in appletviewer but no browser" New topic
Author

Applet working in appletviewer but no browser

hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56
hi all
i have been writeing the applets to use on y web page but it doesn't want to work in the browser, here is my code
note I think it's to do with the swing componet
/*
* ScrollingText.java
* Created on August 12, 2001, 10:28 PM
*/
import java.awt.*;
import java.util.StringTokenizer;
/**
* @author Hennie Louw
* @version 0.1 beta
*/
public class ScrollingText extends java.applet.Applet implements Runnable {
String displayText;
String text;
String textColor;
String backgroundColor;
Thread runner = null;
Color bgColor;
Color tColor;
char[] textArray;
int tR, tB, tG;
int bR, bB, bG;
int x;
boolean count = true;

/** Initializes the applet ScrollingText */
public void init () {

text = getParameter("TEXT");
textColor = getParameter("TEXTCOLOR");
backgroundColor = getParameter("BACKGROUNDCOLOR");
if (text == null) {
text = ("please enter the text you want to display in the applet in the html with <param name= text> tag ");
}
if (textColor == null) {
textColor = "255,255,255";
}
if (backgroundColor == null) {
backgroundColor = "0,0,0";
}
initComponents ();
initData();
}
/**
* This method is called from within the init() method to
* initialize the char[] with the correct data from
* the passed parrameter in the html page called "TEXT"
* the tag will look something like this
*<param name="text" value="It's a 20-hour Lan Party." >
*/
private void initData() {
textArray = text.toCharArray();
String tempString;
StringTokenizer stringTokenText = new StringTokenizer(textColor, ",");
x = 0;
while (stringTokenText.hasMoreTokens()) {
tempString = stringTokenText.nextToken();
if (x == 0) {
tR = Integer.parseInt(tempString);
}
if ( x == 1) {
tG = Integer.parseInt(tempString);
}
if (x == 2 ) {
tB = Integer.parseInt(tempString);
}
x++;
}
StringTokenizer stringTokenBack = new StringTokenizer(backgroundColor,",");
x = 0;
while (stringTokenBack.hasMoreTokens()) {
tempString = stringTokenBack.nextToken();
if (x == 0) {
bR = Integer.parseInt(tempString);
}
if ( x == 1) {
bG = Integer.parseInt(tempString);
}
if (x == 2 ) {
bB = Integer.parseInt(tempString);
}
x++;
}
tColor = new Color(tR,tG,tB);
bgColor = new Color(bR,bG,bB);
textArea.setBackground(bgColor);
textArea.setSelectedTextColor(tColor);
}

/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/


private void initComponents () {//GEN-BEGIN:initComponents
textPanel = new java.awt.Panel ();
textArea = new javax.swing.JTextArea ();
setLayout (new javax.swing.BoxLayout (this, 1));
setBackground (java.awt.Color.black);
setName ("mainPanel");
setForeground (java.awt.Color.black);
textPanel.setLayout (new java.awt.GridLayout (1, 1));
textPanel.setFont (new java.awt.Font ("Dialog", 0, 11));
textPanel.setName ("panel3");
textPanel.setBackground (java.awt.Color.black);
textPanel.setForeground (java.awt.Color.white);
textArea.setWrapStyleWord (true);
textArea.setLineWrap (true);
textArea.setEditable (false);
textArea.setSelectedTextColor (java.awt.Color.orange);
textArea.setFont (new java.awt.Font ("Lucida Bright", 0, 12));
textArea.setBackground (java.awt.Color.red);

textPanel.add (textArea);

add (textPanel);

public void start() {
runner = new Thread(this);
runner.start();
}

public void run() {
while (count) {
textArea.setText(" ");
for (int x = 1; x < textArray.length; x++) {
try {
displayText = new String(textArray,0,x);
textArea.setText(displayText);
Thread.sleep(150);
} catch (InterruptedException e) {}
}
}
}
private java.awt.Panel textPanel;
private javax.swing.JTextArea textArea;
}
and i can't use awt other wise it doen't wrap itself in the size of the TextArea
please help
thanks

Any Body can be paid to write good code, but brilliant code can only come from passion
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15632
    
  15

The java implementations in the two most popular browsers - Netscape and IE - are too old to support Swing. I don't know what Netscape's problem is, but Microsoft doesn't consider Java to be "innovative" enough.
You'll either have to find a way that works under AWT or use the Sun Java Plug-In - which means convincing users not to cancel when it pops up and wants to download over 5MB worth of Java.


Customer surveys are for companies who didn't pay proper attention to begin with.
hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56
Originally posted by Tim Holloway:
The java implementations in the two most popular browsers - Netscape and IE - are too old to support Swing. I don't know what Netscape's problem is, but Microsoft doesn't consider Java to be "innovative" enough.
You'll either have to find a way that works under AWT or use the Sun Java Plug-In - which means convincing users not to cancel when it pops up and wants to download over 5MB worth of Java.

thanks for thhe info if anyone can help me to find a way for it to work it will be a big help
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Hennie,
Your last comment gave you your answer. If you can't use AWT then you will require every user to download the Java 2 plug-in.
Regards,
Manfred.
hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56
Originally posted by Manfred Leonhardt:
Hi Hennie,
Your last comment gave you your answer. If you can't use AWT then you will require every user to download the Java 2 plug-in.
Regards,
Manfred.

I meant I don't know of a way to do it in awt, If someone knows of a way to make a awt TextArea do text warping please let me know
Regards
Hennie
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Hennie,

Here's a really basic way of doing it... I basically made a custom component to do it... it does text wrap, but not word wrap( I'm kinda busy at work, so I didn't have time to implement word wrap! )... you could get it to do it, though, by checking for spaces to get a word, checking if the word will exceed the line, if it does, increment currentLine, drawString( theWord ), then add to currentRow...

Hope this helps you out...



-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Januszs
Greenhorn

Joined: Aug 16, 2001
Posts: 4
you should consider using Suns webstart as opposed to using Applet technnology. Applets are a difficult technology to use and are likely to be supreseeded by webstart. Take a look at www.spidertop.com as well.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet working in appletviewer but no browser
 
Similar Threads
Fade text in and out???
Reading from a Text File in an Applet
displaying scroll messages at the bottom of page
problem with StringTokenizer
Put an Image into a Grid Bag Layout