胶卷

来源:互联网 发布:java中缺省是什么意思 编辑:程序博客网 时间:2024/05/02 01:55

import javax.swing.JFrame;


public class 胶卷 extends JFrame implements Runnable {
private MoveLabel j = new MoveLabel(-200, this);
private MoveLabel j1 = new MoveLabel(-1200, this);




public 胶卷() {
this.setLayout(null);
this.setTitle("胶卷");


Thread th = new Thread(this);
th.start();


this.setSize(800, 600);
this.setVisible(true);
this.setDefaultCloseOperation(3);
this.setLocationRelativeTo(null);


}


public static void main(String[] args) {
胶卷 a = new 胶卷();


}


@Override
public void run() {
while (true) {
// int y = j.getY();
// int y1 = j1.getY();
// j.setLocation(0, y + 10);
// j1.setLocation(0, y1 - 10);
// if (y == 300) {
// j.setLocation(0, -1000);
// System.out.println(j);
// }
// if (y1 == 300) {
// j1.setLocation(0, -1000);
//System.out.println(j1);
// }
j.moves();
j1.moves();


try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();


}
}


}


}


import java.awt.Container;
import java.awt.Image;


import javax.swing.ImageIcon;
import javax.swing.JLabel;


public class MoveLabel extends JLabel {


public MoveLabel(int y, Container con) {
Image j = new ImageIcon("Img/love.jpg").getImage();
j = j.getScaledInstance(300, 1000, 1);


this.setIcon(new ImageIcon(j));
this.setBounds(250, y, 300, 1000);
con.add(this);
}


public void moves() {
int y = this.getY();

if (y > 800) {
y = -1190;

}
this.setLocation(this.getX(), y + 10);




}
}









0 0