-
texte defilant via java
Bonjour,
J'aimerais inserer dans mon site, un teste défilant pour inscrire les news du site.
Seulement apres avoir essayé, je me suis rendu compte que j'ai pas reussi :cry: , je me suis aidé des conseils fournis par lycoshebergement pour le faire.
Voici mon site sur lequel vous pouvez apercevoir un rctangle blanc qui devrai etre ce texte defilant. http://www.jeepetlesuvs.fr
Donc, voila ma demande,
Quel(s) logiciel dois-je utiliser, et comment faire pour créer mon texte.
Merci,
Maxime
-
tu es sur de ne pas confondre java et javascript?
-
ha si c'est possible, je me suis deja srvis du site pour mette le site a jour, avant c'etait juste un grande page, il n'y avais pas de cadre.
je debute, je vais allé voir sur le site pour le javascript et reviendrais aux nouvelles.
merci pur ce petit detail
-
montre nous ton code on te diras si c'est du JAVA.
-
ca c'est ce que lycos "disais" de mettre sur la page internet :
<applet code="JeepetlesSUVsNEWS.class" height="40" width="1000">
Ensuite c'est divers code en .txt.
> href scroller.java :
/*
URL-clickable horizontal scrolling text applet.
Parameters (see also Scroller):
URL the URL to jump to when the applet is clicked
by a mouse
def: none - if none supplied or invalid, it's just a scrolling
text applet
TARGET for frames, etc.
def: "_top"
Copyright 1998 by E. A. Graham, Jr.
Free to use or modify.
*/
import java.awt.*;
import java.applet.*;
import java.net.URL;
import java.net.MalformedURLException;
public class HrefScroller extends Scroller {
String urlName;
String urlTarget;
URL nextURL = null;
public void init() {
super.init();
urlName = ReadText("URL");
if (urlName != null) {
int x = urlName.indexOf(',');
if (x > 0) {
urlTarget = urlName.substring(x+1);
urlName = urlName.substring(0,x);
}
else {
urlTarget = "_top"; // just to make sure we jump out of frames
}
try {
if (urlName.indexOf("http://") < 0) {
nextURL = new URL(getDocumentBase(),urlName);
}
else {
nextURL = new URL(urlName);
}
}
catch (MalformedURLException e) {};
}
borderWidth = Math.abs(borderWidth);
}
public boolean mouseDown(Event e,int x, int y) {
borderWidth = -borderWidth;
return true;
}
public boolean mouseUp(Event e,int x, int y) {
borderWidth = -borderWidth;
if (nextURL !=null) {
getAppletContext().showDocument(nextURL,urlTarget);
}
return true;
}
public boolean mouseEnter(Event e,int x,int y) {
if (nextURL != null) showStatus("Link to " + urlName);
return true;
}
public boolean mouseExit(Event e,int x,int y){
showStatus("");
return true;
}
}
------------------------------------------
------------------------------------------
> scroller.java :
/*
Reads "news" from text file with headlines and URLs.
Vertical scroll.
Parameters (see also WebBase):
DATAFILE File (relative to the HTML document) to get news from
def: news.txt
CLICKCOLOR Color of "clickable" text
def: blue
HEADCOLOR Color of headline text
def: red
FONT Font to use (Arial,Courier,Dialog,TimesRoman)
def: Dialog
FONTSIZE Size (in pts.) of message font
def: 12
MOUSEPAUSE Causes scrolling to stop while the mouse cursor
is over the applet - the value can be anything
def: null (no pause)
TOPPAUSE Pauses scrolling at the "top" of each message
(in milliseconds);
def: 0 (no pause)
Copyright 1998 by E. A. Graham, Jr.
Free to use or modify.
*/
import java.awt.*;
import java.applet.*;
import java.util.*;
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;
public class Scroller extends WebBase {
// fonts for the headline and message (headline is bold version of message)
Font fontHeadline,fontMessage;
// the various colors
Color clickColor,headColor;
// the current "top" message - used for pausing
NewsMessage msgTop = null;
// The File and the Messages
String fileName = null;
Vector vMessages = new Vector();
Vector vNewMessages = new Vector();
int gap = 15; // gap between messages - tweak if necessary
boolean mouse_pause = false; // stop messages from scrolling
boolean pause_now = false;
long top_pause = 0;
//************************************************************************
// initialization time!
//************************************************************************
public void init() {
super.init();
//********************************************************************
// get the HTML parameters or set to defaults
//********************************************************************
String sp;
sp = ReadText("DATAFILE");
fileName = (sp == null) ? "news.txt" : sp;
clickColor = ReadColor("CLICKCOLOR",Color.blue);
headColor = ReadColor("HEADCOLOR",Color.red);
sp = ReadText("MOUSEPAUSE");
mouse_pause = (sp != null);
sp = ReadText("TOPPAUSE");
top_pause = (sp != null) ? Long.parseLong(sp) : 0;
//********************************************************************
// get the HTML font parameters and set them up
//********************************************************************
sp = ReadText("FONTSIZE");
int fs = (sp != null) ? Integer.parseInt(sp) : 12;
sp = ReadText("FONT");
if (sp==null) sp = "Dialog";
fontMessage = new Font(sp,Font.PLAIN,fs);
fontHeadline = new Font(sp,Font.BOLD,fs);
updateNews();
}
public void stop() {
super.stop();
}
// draw the stuff
public synchronized void update(Graphics g) {
if(loaded) {
super.update(g);
// loop over the loaded news items...
for (Enumeration e = vMessages.elements() ; e.hasMoreElements() ;) {
((NewsMessage)e.nextElement()).draw(appGC,borderWidth,headColor,foreColor,clickColor);
}
//...next comes the border...
drawBorder(maxWidth,maxHeight,borderWidth);
//...fade the edges
g.drawImage(appImage, 0, 0, this);
}
}
public boolean handleEvent(Event event) {
return super.handleEvent(event);
}
// handle any clicks, okay?
public boolean mouseDown(Event ev,int x, int y) {
for (Enumeration e = vMessages.elements() ; e.hasMoreElements() ;) {
NewsMessage m = (NewsMessage)e.nextElement();
URL clicked = m.click(y);
if (clicked != null) {
getAppletContext().showDocument(clicked,m.getTarget());
break;
}
}
return true;
}
// start and stop the scrolling
public boolean mouseEnter(Event ev,int x, int y) {
if (mouse_pause) pause_now = true;
return true;
}
public boolean mouseExit(Event ev,int x, int y) {
pause_now = false;
return true;
}
// scroll all the messages
synchronized void doAppThing() {
int maxM = vMessages.size(),
maxN = vNewMessages.size(),
lastBottom;
NewsMessage m,lastM;
boolean reset = false;
// check for new messages - I don't know if this will work on updates, but it should be interesting
if (maxM==0) {
if (maxN > 0) {
vMessages = (Vector)vNewMessages.clone();
}
else {
return;
}
}
// has the top message gone off? take it off and stick it on bottom!
m = (NewsMessage)vMessages.firstElement();
lastM = (NewsMessage)vMessages.lastElement();
if (m.bottom() + scrollUnit <= 0) {
vMessages.removeElement(m);
lastBottom = lastM.bottom() + gap;
m.resetTop(lastBottom);
vMessages.addElement(m);
}
// check for the mouse pause conditions
if (pause_now) return;
// scroll the visible messages
for (Enumeration e = vMessages.elements() ; e.hasMoreElements() ;) {
m = (NewsMessage)e.nextElement();
m.move(scrollUnit);
}
m = (NewsMessage)vMessages.firstElement();
if (m.top() <= (Math.abs(borderWidth)+1) && top_pause > 0 && !m.equals(msgTop)) {
try {
Thread.sleep(top_pause);
msgTop = m;
}
catch (InterruptedException e) {}
}
}
// (re)read the news file
synchronized void updateNews() {
InputStream conn;
DataInputStream dis = null;
URL theURL = null;
if (fileName==null) return;
try {
if (fileName.indexOf("http://") >= 0 ) {
theURL = new URL(fileName);
}
else {
theURL = new URL(getDocumentBase(),fileName);
}
try {
int mode = 0,
lastbottom = maxHeight;
NewsMessage m = null;
String line;
conn = theURL.openStream();
dis = new DataInputStream(new BufferedInputStream(conn));
while( (line=dis.readLine())!=null) {
if (line.startsWith("#") || line.length()==0) continue;
if (line.substring(0,4).equalsIgnoreCase("@END")) {
if (m!=null) {
if (m.getTarget()==null) m.setTarget(frameTarget);
lastbottom = m.bottom() + gap;
vNewMessages.addElement(m);
}
mode = 0;
continue;
}
if (line.substring(0,4).equalsIgnoreCase("@URL") && m!=null) {
m.setLink(getDocumentBase(),line.substring(4));
continue;
}
if (line.substring(0,6).equalsIgnoreCase("@FRAME") && m!=null) {
m.setTarget(line.substring(6));
continue;
}
switch (mode) {
case 0:
if (line.substring(0,5).equalsIgnoreCase("@HEAD")) {
mode = 1;
m = new NewsMessage(lastbottom,maxWidth-(2*borderWidth),appGC,fontHeadline,fontMessage);
m.addHeadLine(line.substring(5));
}
break;
case 1:
if (line.substring(0,4).equalsIgnoreCase("@MSG")) {
mode = 2;
m.addMessageLine(line.substring(4));
}
else {
m.addHeadLine(line);
}
break;
default:
m.addMessageLine(line);
break;
}
}
}
catch (IOException e) {}
}
catch (MalformedURLException e) {}
}
}
class NewsMessage {
int top,height,
currentY,
maxWidth = 0;
URL link = null;
String target = null;
// the first element in each of these is the font, the second is the font metrics
Vector message = null;
Vector headline = null;
NewsMessage (int startat,int mw,Graphics g,Font fontHead,Font fontMessage) {
FontMetrics fm;
height = 0;
top = startat;
headline = new Vector();
headline.addElement(fontHead);
fm = g.getFontMetrics(fontHead);
headline.addElement(fm);
message = new Vector();
message.addElement(fontMessage);
fm = g.getFontMetrics(fontMessage);
message.addElement(fm);
maxWidth = mw - 10;
}
public void draw (Graphics g,int bw,Color headColor,Color msgColor,Color urlColor) {
// is this thing even in the picture?
if (top+height <= 0) return;
// set up and do the headline
// then do the message
currentY = top;
drawline(g,headline,bw,headColor);
drawline(g,message,bw,((link==null) ? msgColor : urlColor));
}
public void move(int amount) { top -= amount; }
public void resetTop(int startat) { top = startat; }
public int bottom() { return top+height; }
public int top() { return top; }
// set/return URL for this message
public void setLink(URL docbase,String s) {
try {
if (s.indexOf("http://") >= 0 ) {
link = new URL(s);
}
else {
link = new URL(docbase,s);
}
}
catch (MalformedURLException e) {};
}
public URL click(int y) {
if (y>=top && y<=top+height) return(link);
return(null);
}
// set/return the target
public void setTarget(String t) { target = new String(t); }
public String getTarget() { return target; }
public void addHeadLine(String s) {
addLine(headline,s);
}
public void addMessageLine(String s) {
addLine(message,s);
}
// calcuate where the lines will wrap and update the height of the message
void addLine(Vector v,String line) {
try {
FontMetrics fm = (FontMetrics)v.elementAt(1);
String s,t;
int x,y,
h;
h = fm.getHeight();
if (v.size() > 2) {
s = new String ((String)v.lastElement() + " " + line);
v.removeElementAt(v.size()-1);
height -= h;
}
else {
s = line;
}
for (x=0; s.length() > 0; x=y+1) {
y = s.indexOf(' ',x);
if (y== -1) {
if ((fm.stringWidth(s) > maxWidth) && x>0) {
v.addElement(s.substring(0,x));
s = s.substring(x);
height += h;
}
v.addElement(s);
height += h;
s = "";
}
else {
t = s.substring(0,y);
if (fm.stringWidth(t) > maxWidth) {
v.addElement(s.substring(0,x));
s = s.substring(x);
y = -1;
height += h;
}
}
}
}
catch (NoSuchElementException e) {}
}
// draw the indicated lines
void drawline(Graphics g,Vector v,int bw,Color c) {
try {
FontMetrics fm = (FontMetrics)v.elementAt(1);
int h,i,y;
h = fm.getHeight();
y = fm.getAscent(); // distance to baseline
g.setColor(c);
g.setFont((Font)v.firstElement());
for (i=2; i<v.size(); i++) {
String s = (String)v.elementAt(i);
g.drawString(s,bw+5,currentY+y);
currentY += h;
}
}
catch (NoSuchElementException e) {}
}
}
-------------------------------------
-------------------------------------
> WebBase.java :
/*
Base class for Ed's web applets
Provides some of the base functionality used for my
web applets.
Parameters:
SLEEPTIME Milliseconds between updates
def: DEFAULT_SLEEP
SCROLLBY Increment to scroll messages on updates
def: DEFAULT_SCROLL
BORDER Draw a border around it all
def: 0 Indicates width of the 3D border
Negative values makes an "inset" border
Uses background color to draw it
FOREGROUND Color of the text
def: black
BACKGROUND Color of the background
def: white
PICTURE Background image - must be .GIF or .JPG
def: none
TARGET Target frame name for URL jumps
def: _top
Copyright 1998 by E. A. Graham, Jr.
Free to use or modify.
*/
import java.awt.*;
import java.applet.*;
import java.net.URL;
import java.net.MalformedURLException;
public class WebBase extends Applet implements Runnable {
private final int DEFAULT_SLEEP = 150;
private final int DEFAULT_SCROLL = 10;
Thread myThread = null; //The main thread
int maxWidth,maxHeight, // Dimensions of the applet area
borderWidth; // draw a 3-D border around the thing
// adjust these two for scrolling parameters
int scrollUnit; // the incremental scrolling distance in pixels
long sleepTime; // controls the speed of the scroll
Image appImage; // The applet 'image' object
Graphics appGC; // GC used for applet 'image'
Color foreColor,backColor; // foreground and background colors
static boolean loaded = false; // helps determine if we're running or not
Image bPicture = null;
String frameTarget = null;
// initialization time!
public void init() {
String tparam;
// get the size of the applet
maxWidth = size().width;
maxHeight = size().height;
// used for children of this class to target URL jumps
// defaults to "_top"
tparam = ReadText("TARGET");
frameTarget = new String(tparam==null ? "_top" : tparam);
// get some numeric parameters
tparam = ReadText("SleepTime");
sleepTime = (tparam != null) ? Long.parseLong(tparam) : DEFAULT_SLEEP;
tparam = ReadText("ScrollBy");
scrollUnit = (tparam != null) ? Integer.parseInt(tparam) : DEFAULT_SCROLL;
tparam = ReadText("BORDER");
borderWidth = (tparam == null) ? 0 : Integer.parseInt(tparam);
// the color parameters
foreColor = ReadColor("FOREGROUND",Color.black);
backColor = ReadColor("BACKGROUND",Color.white);
setBackground(backColor);
// a background picture (go ahead and wait for full load)
tparam = ReadText("PICTURE");
if (tparam != null) {
MediaTracker imgTrack;
URL theURL = null;
try {
if (tparam.indexOf("http://") >= 0 ) {
theURL = new URL(tparam);
}
else {
theURL = new URL(getDocumentBase(),tparam);
}
bPicture = getImage(theURL);
if (bPicture != null) {
imgTrack = new MediaTracker(this);
imgTrack.addImage(bPicture,0);
try {
imgTrack.waitForAll();
}
catch (Exception e) {
System.out.println(e);
bPicture = null;
}
}
}
catch (MalformedURLException e) {}
}
appImage = createImage(maxWidth, maxHeight);
appGC = appImage.getGraphics();
}
// reads an HTML-supplied parameter
String ReadText(String myParam){
String tempString = null;
try {
tempString = getParameter(myParam);
}
catch (Exception e) {
System.out.println(e);
}
return tempString;
}
// reads in a color HTML-supplied parameter (either R,G,B or hex RGB value)
Color ReadColor(String sParam, Color defColor) {
String tparam = ReadText(sParam);
Color tcolor;
int rc,gc,bc;
rc = gc = bc = -1;
if (tparam != null) {
if (tparam.startsWith("#")) {
if (tparam.length()==7) {
rc = Integer.parseInt(tparam.substring(1,3),16);
gc = Integer.parseInt(tparam.substring(3,5),16);
bc = Integer.parseInt(tparam.substring(5),16);
}
}
else {
int x,y;
x = tparam.indexOf(',');
y = tparam.lastIndexOf(',');
if (x>0 && y>0 && x!=y) {
rc = Integer.parseInt(tparam.substring(0,x));
gc = Integer.parseInt(tparam.substring(x+1,y));
bc = Integer.parseInt(tparam.substring(y+1));
}
}
}
tcolor = (rc>=0 && rc<=255 && gc>=0 && gc<=255 && bc>=0 && bc<=255) ? new Color(rc,gc,bc) : defColor;
return(tcolor);
}
// start/stop the applet thread
public void start() {
if(myThread == null) {
myThread = new Thread(this);
myThread.start();
loaded = true;
}
}
public void stop() {
if((myThread != null) && myThread.isAlive()) {
myThread.stop();
}
loaded = false;
myThread = null;
}
// this triggers the update and scrolls the text by updating the X position
public void run() {
Thread me = Thread.currentThread();
me.setPriority(Thread.MIN_PRIORITY);
appImage = createImage(maxWidth, maxHeight);
appGC = appImage.getGraphics();
repaint();
while(myThread == me){
while(loaded){
doAppThing();
repaint();
try {
Thread.sleep(sleepTime);
}
catch(InterruptedException e){}
}
}
}
synchronized void doAppThing() {
}
// we don't want it to do anything here...
public void paint(Graphics g)
{
}
public synchronized void update(Graphics g) {
if (loaded) {
// if there's a background picture, use it
if (bPicture != null) {
appGC.drawImage(bPicture,0, 0, maxWidth, maxHeight,this);
}
// otherwise, draw background rectangle...
else {
appGC.setColor(backColor);
appGC.fillRect(0, 0, maxWidth, maxHeight);
}
}
}
// draws a 3-D border
void drawBorder(int w,int h,int bw) {
if (bw == 0) return;
Color bc_light,bc_dark;
int pWidth = Math.abs(bw);
Polygon bp_below = new Polygon();
Polygon bp_above = new Polygon();
if (backColor.equals(Color.white)) {
bc_light = backColor.darker();
bc_dark = bc_light.darker();
}
else {
bc_light = backColor.brighter();
bc_dark = backColor.darker();
}
// add the vertices to the polygons
bp_above.addPoint(0,0);
bp_above.addPoint(w,0);
bp_above.addPoint(w-pWidth,pWidth);
bp_above.addPoint(pWidth,pWidth);
bp_above.addPoint(pWidth,h-pWidth);
bp_above.addPoint(0,h);
bp_below.addPoint(w,0);
bp_below.addPoint(w,h);
bp_below.addPoint(0,h);
bp_below.addPoint(pWidth,h-pWidth);
bp_below.addPoint(w-pWidth,h-pWidth);
bp_below.addPoint(w-pWidth,pWidth);
// draw the border
if (bw < 0) {
appGC.setColor(bc_dark);
}
else {
appGC.setColor(bc_light);
}
appGC.fillPolygon(bp_above);
if (bw < 0) {
appGC.setColor(bc_light);
}
else {
appGC.setColor(bc_dark);
}
appGC.fillPolygon(bp_below);
}
// the next two methods make a default TimesRoman font
// to fit in a certain height
Font appFont(int ht) {
return appFont(ht,Font.PLAIN);
}
Font appFont(int ht, int fAttr) {
return appFont(ht,"TimesRoman",fAttr);
}
// makes a font for the applet
Font appFont(int ht,String fName,int fAttr) {
Font tf = new Font(fName, fAttr, 14);
setFont(tf);
FontMetrics tfm = getFontMetrics(tf);
int fh = tfm.getHeight();
fh = 14 * (maxHeight-2) / fh; // scale the font height
tf = new Font(fName, fAttr, fh); // "make" the font
return tf;
}
}
---------------------------------
---------------------------------
et je viens de decouvrir que le fichier réclamer par la page web est vide (.class), ce qui expliquerais l'erreur produite.
enfin bon, si je peux créer la meme chose en plus simple, je suis a votre ecoute.
-
desolé d'avoir mis tout les codes, mais je sais pas trop lequel metter alors voila:mrgreen:
-
C'est bien du JAVA.
Par contre faudrait-être plus précis sur ton besoin, et sur l'erreur rencontrée.
-
Pour l'erreur, voila ce que me met la console java sur le site :
Java Plug-in 1.5.0_09
Utilisation de la version JRE 1.5.0_09 Java HotSpot(TM) Client VM
Répertoire d'accueil de l'utilisateur = C:\Documents and Settings\Maxime TOULORGE
----------------------------------------------------
c: effacer la fenêtre de la console
f: finaliser les objets de la file d'attente de finalisation
g: libérer la mémoire
h: afficher ce message d'aide
l: vider la liste des chargeurs de classes
m: imprimer le relevé d'utilisation de la mémoire
o: déclencher la consignation
p: recharger la configuration du proxy
q: masquer la console
r: recharger la configuration des politiques
s: vider les propriétés système et déploiement
t: vider la liste des threads
v: vider la pile des threads
x: effacer le cache de chargeurs de classes
0-5: fixer le niveau de traçage à <n>
----------------------------------------------------
java.lang.ClassFormatError: Truncated class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.ClassFormatError: Truncated class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.ClassFormatError: Truncated class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
---------------------------------
---------------------------------
ce que je recherche, c'est mettre un texte defilant horizontal, pour y affiche les news du site sans avoir a recharger la page concernée sur le DD. J'aimerais juste avoir a modifier un fichier texte qui permettra d'afficher directement les news sur le site.
ne sachant pas comment faire et en comprenant mal les explications de lycos, je demande de l'aide directement sur le forum.
-
Je crois avoir trouvé l'erreur, le fichier .class etant vide, cela ne peut fonctionner puisque ca a l'ar d'etre lui le fichier relais entre la page internet e le serveur de l'hebergeur.
Donc, quelqu'un pouvais me preter:mrgreen: le code a mettre dans cette page, ou du moins un exemple.