📄 car.java
字号:
package accp.car;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Car extends JFrame implements Runnable{
Icon ico=new ImageIcon("image/car.gif");
MyJLabel mjl = new MyJLabel(ico);
Container cp = this.getContentPane();
//static{
// mjl.setText("wangbo");
//}
public Car(){
cp.setLayout(new FlowLayout());
cp.add(mjl);
mjl.addMouseListener(new MouseListener()
{
public void mouseClicked(MouseEvent e){
}
public void mousePressed(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
JOptionPane.showMessageDialog(null,"Car in "+mjl.getLocation().getX()+" "+mjl.getLocation().getY());
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
});
Thread runner = new Thread(this);
this.setSize(900,200);
this.show();
runner.start();
}
public void run(){
Thread t = new Thread(mjl);
t.start();
}
public static void main(String[] args){
new Thread(new Car()).start();
}
}
class MyJLabel extends JLabel implements Runnable{
MyJLabel(Icon ico){
super(ico);
}
/*
MyJLabel(String[] s){
super(s);
}
*/
public void run(){
for(int i=0;i<800;i++){
this.setLocation(30+i,60);
System.out.println(this.getLocation().getX()+","+this.getLocation().getY());
try{
Thread.sleep(100);
if(this.getLocation().getX()>200){
//this.invalidate();
//this.disable();
//this.show(false);
//Thread.currentThread().stop();
//System.out.println(Thread.currentThread().isInterrupted());
}
}catch(Exception e){
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -