[HELP] Applet java: Pb de repaint()
Fred
-
choubaka Messages postés 39986 Date d'inscription Statut Modérateur Dernière intervention -
choubaka Messages postés 39986 Date d'inscription Statut Modérateur Dernière intervention -
Je fais une applet qui fait apparaitre des liens href toutes les 2 secondes. Mon problème est que mes textes s'écrivent les uns sur les autres. Toutes les 2 secondes, le texte suivant vient s'afficher sur le précédent et ainsi de suite ce qui est illisible. Pourtant repaint() doit effacer l'ecran avant d'écrire. Je ne comprends pas.
code:--------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import java.net.*;
public class revolve extends JApplet implements Runnable , ActionListener
{
String[] pagetitle = new String[6];
URL[] pagelink = new URL[6];
int current=0;
Thread runner;
public void init()
{
Color background = new Color(153,204,51);
setBackground(background);
pagetitle[0] = "site à la con qui ne mrche pas";
pagetitle[1] = "Un autre site de merde site n°2";
pagetitle[2] = "site n°3";
pagetitle[3] = "Putain de bordel de merde!!!!";
pagetitle[4] = "Encore un autre";
pagetitle[5] = "Et le dernier";
pagelink[0] = getURL("http://mastermedion/CTM/test.html");
pagelink[1] = getURL("http://mastermedion/CTM/test1.html");
pagelink[2] = getURL("http://mastermedion/CTM/test2.html");
pagelink[3] = getURL("http://mastermedion/CTM/test3.html");
pagelink[4] = getURL("http://mastermedion/CTM/test4.html");
pagelink[5] = getURL("http://mastermedion/CTM/test5.html");
Button gobouton = new Button("visiter");
FlowLayout flow = new FlowLayout();
Container pane = getContentPane();
pane.setLayout(flow);
pane.add(gobouton);
setContentPane(pane);
}
URL getURL(String urlText)
{
URL pageURL = null;
try
{
pageURL = new URL(getDocumentBase(), urlText);
}
catch (MalformedURLException m) {}
return pageURL;
}
public void paint(Graphics screen)
{
Graphics2D screen2D = (Graphics2D)screen;
screen2D.drawString(pagetitle[current].toString(),5,60);
screen2D.drawString(pagelink[current].toString(),5,80);
}
public void start()
{
if (runner==null)
{
runner = new Thread(this);
runner.start();
}
}
public void run()
{
Thread monthread = Thread.currentThread();
while(runner==monthread)
{
repaint();
current++;
if(current>5)
current=0;
try
{
Thread.sleep(2000);
}
catch (InterruptedException e) {}
}
}
public void stop()
{
if(runner!=null) runner=null;
}
public void actionPerformed(ActionEvent evt)
{
if(runner != null)
{
runner=null;
}
AppletContext browser = getAppletContext();
if(pagelink[current] != null)
{
browser.showDocument(pagelink[current]);
}
}
}
--------------------------------------------------------------------------------
code:--------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import java.net.*;
public class revolve extends JApplet implements Runnable , ActionListener
{
String[] pagetitle = new String[6];
URL[] pagelink = new URL[6];
int current=0;
Thread runner;
public void init()
{
Color background = new Color(153,204,51);
setBackground(background);
pagetitle[0] = "site à la con qui ne mrche pas";
pagetitle[1] = "Un autre site de merde site n°2";
pagetitle[2] = "site n°3";
pagetitle[3] = "Putain de bordel de merde!!!!";
pagetitle[4] = "Encore un autre";
pagetitle[5] = "Et le dernier";
pagelink[0] = getURL("http://mastermedion/CTM/test.html");
pagelink[1] = getURL("http://mastermedion/CTM/test1.html");
pagelink[2] = getURL("http://mastermedion/CTM/test2.html");
pagelink[3] = getURL("http://mastermedion/CTM/test3.html");
pagelink[4] = getURL("http://mastermedion/CTM/test4.html");
pagelink[5] = getURL("http://mastermedion/CTM/test5.html");
Button gobouton = new Button("visiter");
FlowLayout flow = new FlowLayout();
Container pane = getContentPane();
pane.setLayout(flow);
pane.add(gobouton);
setContentPane(pane);
}
URL getURL(String urlText)
{
URL pageURL = null;
try
{
pageURL = new URL(getDocumentBase(), urlText);
}
catch (MalformedURLException m) {}
return pageURL;
}
public void paint(Graphics screen)
{
Graphics2D screen2D = (Graphics2D)screen;
screen2D.drawString(pagetitle[current].toString(),5,60);
screen2D.drawString(pagelink[current].toString(),5,80);
}
public void start()
{
if (runner==null)
{
runner = new Thread(this);
runner.start();
}
}
public void run()
{
Thread monthread = Thread.currentThread();
while(runner==monthread)
{
repaint();
current++;
if(current>5)
current=0;
try
{
Thread.sleep(2000);
}
catch (InterruptedException e) {}
}
}
public void stop()
{
if(runner!=null) runner=null;
}
public void actionPerformed(ActionEvent evt)
{
if(runner != null)
{
runner=null;
}
AppletContext browser = getAppletContext();
if(pagelink[current] != null)
{
browser.showDocument(pagelink[current]);
}
}
}
--------------------------------------------------------------------------------
A voir également:
- [HELP] Applet java: Pb de repaint()
- Jeux java itel - Télécharger - Jeux vidéo
- Waptrick java football - Télécharger - Jeux vidéo
- Waptrick java voiture - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Eclipse java - Télécharger - Langages