J'ai l'erreur "non-static method repaint() cannot be referenced from a static context" sur la ligne testgraph.repaint();
Je vous accorde que mon prog est zarb mais je suis en train de faire des petits tests... Alors je fais comment moi ?
import java.net.*;
import java.io.*;
import java.lang.Thread;
import java.awt.*;
import java.awt.Graphics;
public class testgraph extends java.applet.Applet
{
static public int nb_msg=0;
static public int x1=0;
static public int y1=0;
static public int x2=0;
static public int y2=0;
Button a = new Button("ok" );
FlowLayout lm = new FlowLayout();
public testgraph()
{
}
public void init()
{
setLayout(lm);
add(a);
}
public void paint(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
}
public void start()
{
try
{
System.out.println("coucou" );
GraphTimer gt = new GraphTimer(2000);
gt.start();
}
catch (Exception e)
{
}
}
public boolean action(Event evt, Object arg)
{
if (evt.target instanceof Button)
{
String labl = (String)arg;
if (labl.equals("ok" ))
{
nb_msg++;
}
}
return true;
}
public void update()
{
repaint();
}
}
class GraphTimer extends Thread
{
static public int tsleep;
public GraphTimer(int tsleep)
{
this.tsleep = tsleep;
}
public void run()
{
try
{
while (true)
{
sleep(tsleep);
System.out.println(testgraph.nb_msg);
testgraph.nb_msg=0;
setp(0,0,50,50);
testgraph.repaint();
}
}
catch (Exception e)
{
}
}
public void setp(int x1, int y1, int x2, int y2)
{
testgraph.x1=x1;
testgraph.y1=y1;
testgraph.x2=x2;
testgraph.y2=y2;
}
}