日期:2014-05-20 浏览次数:20828 次
import javax.swing.*; import java.awt.*; public class Window extends JFrame { public Window() { super("螃蟹过街"); setIconImage(Toolkit.getDefaultToolkit().createImage("game/icon.png")); setSize(700,400); init(); setLocation((Toolkit.getDefaultToolkit().getScreenSize().width-700)/2,(Toolkit.getDefaultToolkit().getScreenSize().height-400)/2); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void init() { Container rongqi=getContentPane(); } public void paint(Graphics g) { Color c1=new Color(255,0,0,100); g.setColor(c1); g.setFont(new Font("",Font.BOLD,30)); new Load_line(g).start(); g.drawRect(200, 200, 100, 100); //画矩形 g.fillRect(220, 220, 60, 60); //填充矩形 } public static void main(String[] args) { new Window(); } } -------------- import java.awt.Graphics; public class Load_line extends Thread { Graphics q2; public Load_line(Graphics q1) { q2=q1; } public void run() { for(int i=40;i<300;i+=4) { q2.drawLine(20, i, 300, i); try { sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } } } }