⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nyp1.txt

📁 交通灯雏形
💻 TXT
字号:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class car extends JFrame implements ActionListener
{
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class car extends JFrame implements ActionListener
{
	public static void main(String[] args)
	{
	 car frame =new car();
	}
	Timer timer;
	int py;
	JLabel cp1,cp2;
	
	public car()
	{
	super("car");
	Container c=getContentPane();
	c.setLayout(null);
	c.setBackground(Color.white);
	ImageIcon icon1=new ImageIcon("3.gif");
	ImageIcon icon2=new ImageIcon("2.gif");
	cp2=new JLabel(icon2);
	cp2.setSize(25,35);
	cp2.setLocation(270,540);
	c.add(cp2);
	cp1=new JLabel(icon1);
	cp1.setSize(500,600);
	cp1.setLocation(0,0);
	c.add(cp1);
	//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setSize(500,620);
	setVisible(true);
	timer=new Timer(30,this);
	py=540;
	timer.start();
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==timer)
		{
		py-=1;
		if(py<1)
			py=540;
		cp2.setLocation(270,py);
		}
	}
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -