※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
import java.awt.*;
import java.awt.event.*;
public class Test12 extends Frame implements ActionListener,Runnable {
MyCanvas c1;
Button b1,b2;
Thread t1;
int lastX,lastY,moveX,moveY;
boolean KissOfDeath;
public Test12() {
super();
setTitle("Hello");
setSize(300,250);
setLayout(null);
lastX = 0;
lastY = 0;
KissOfDeath = false;
c1 = new MyCanvas();
c1.setBounds(25,25,250,150);
this.add(c1);
b1 = new Button("GO");
b1.setBounds(25,200,100,25);
b1.addActionListener(this);
this.add(b1);
b2 = new Button("change");
b2.setBounds(175,200,100,25);
b2.addActionListener(this);
this.add(b2);
}
public static void main (String args []) {
new Test12().setVisible(true);
}
public void actionPerformed(ActionEvent ev) {
if (ev.getSource() == b1) {
KissOfDeath = ! KissOfDeath;
if (KissOfDeath){
t1 = new Thread(this);
t1.start();
}
}
if (ev.getSource() == b2) {
moveX = (int)(Math.random() * 21 - 11);
moveY = (int)(Math.random() * 21 - 11);
}
}
public void run(){
try {
while(KissOfDeath){
if (lastX + moveX < 0 || lastX + moveX > c1.getWidth()){
moveX *= -1;
}
if (lastY + moveY < 0 || lastY + moveY > c1.getHeight()){
moveY *= -1;
}
lastX += moveX;
lastY += moveY;
c1.repaint();
t1.sleep(100);
}
} catch(Exception e){
System.out.println(e);
}
}
class MyCanvas extends Canvas{
public void paint(Graphics g){
g.setColor(Color.blue);
g.fillOval(lastX - 10,lastY - 10,20,20);
}
}
}
| << 前へ | 次へ >> |