|
-
Dec 4th, 2001, 11:59 AM
#1
Thread Starter
Hyperactive Member
Canvas
Anyone know how to move a Canvas?
-
Dec 4th, 2001, 12:12 PM
#2
Code:
canvas1.setLocation(10,10);
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Dec 4th, 2001, 12:23 PM
#3
Thread Starter
Hyperactive Member
Thanks crptcblade,
I wonder if you could help me,
I have an applet class and a canvas class
I'm trying to put text in the canvas and scroll the canvas upwards, heres my code.
Code:
//applet class
import java.applet.*;
import java.awt.*;
public class NewsApplet extends java.applet.Applet
implements Runnable{
private Canvas news = new TextCanvas();
private Thread thread;
private long delay = 40;
public int x = 100;
public int y = 100;
public void init(){
news.setSize(100,100);
news.setLocation(10,10);
add(news);
}
public void start(){
thread = new Thread(this);
thread.start();
}
public void run(){
try {while (true) {
repaint();
Thread.sleep(delay);
};} catch (InterruptedException e) {
// end
};
}
public void stop(){
if (thread!=null) thread.stop();
thread=null;
}
public void paint(Graphics g){
x+=1;
y+=1;
news.setLocation(x,y);
}
}
//canvas class
import java.awt.*;
import java.applet.*;
public class TextCanvas extends Canvas
{
public void paint (Graphics g){
g.setColor(Color.black);
g.drawString("hello world",100,100);
}
}
running it in visual studio i just get a blank applet!!
Any help would be gratefully appreciated here !
-
Dec 4th, 2001, 12:27 PM
#4
Thread Starter
Hyperactive Member
I'm off home now but I'll check for a reply tommorow....
Thanks!
-
Dec 4th, 2001, 01:37 PM
#5
Code:
//applet class
import java.applet.*;
import java.awt.*;
public class NewsApplet extends Applet implements Runnable{
private TextCanvas news = new TextCanvas();
private Thread thread;
private long delay = 100;
public int x = 0;
public int y = 100;
public void init()
{
}
public void start()
{
this.setBackground(Color.red);
this.add(news);
news.setBounds(0,0,100,100);
thread = new Thread(this);
thread.start();
}
public void run(){
try
{
while (true)
{
this.repaint();
Thread.sleep(delay);
}
} catch (InterruptedException e) {}
}
public void stop(){
}
public void paint(Graphics g){
if (y<0) y = 100;
else y--;
news.setLocation(0,y);
news.repaint();
}
}
class TextCanvas extends Canvas
{
public void paint (Graphics g){
g.setColor(Color.black);
g.drawString("hello world",10,10);
}
}
I changed it a little bit, it starts at the bottom, and scrolls 'Hello World' to the top, then starts at the bottom again.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Dec 4th, 2001, 02:16 PM
#6
Thread Starter
Hyperactive Member
cheers M8
I'll try it at work tommorow!
-
Dec 5th, 2001, 05:22 AM
#7
Thread Starter
Hyperactive Member
I've tried this now, and it works!
Only thing is it goes at light speed no matter what i set the delay to !
Any Ideas
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|