import java.awt.*; import java.awt.event.*; import javax.swing.*; public class UFOGame01 { private JFrame frame = new JFrame("tenQ["); private JPanel pane = (JPanel)frame.getContentPane(); private int w = 400, h = 400; private int ux = 0, udx = 2; private int bx = 170; private Canvas canvas = new Canvas(){ @Override public void update(Graphics g){ paint(g); } @Override public void paint(Graphics g){ Rectangle rec = g.getClipBounds(); w = rec.width; h = rec.height; Image img = createImage(w, h); Graphics ofg = img.getGraphics(); ofg.setColor(Color.RED); ofg.fillOval(ux, 10, 80, 30); ofg.setColor(Color.WHITE); ofg.drawString("U F O", ux + 25, 30); ofg.setColor(Color.BLUE); ofg.fillRect(bx - 30, h - 50, 60, 20); ofg.fillPolygon(new int[]{bx, bx - 15, bx + 15}, new int[]{h - 65, h - 45, h - 45}, 3); g.drawImage(img, 0, 0, this); try{Thread.sleep(20);}catch(Exception ex){} if((udx > 0 && ux >= w - 80) || (udx < 0 && ux <= 0)){ udx = -udx; } ux += udx; repaint(); } }; public UFOGame01(){ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); canvas.setBackground(Color.WHITE); canvas.setSize(w, h); canvas.addMouseMotionListener(new MouseMotionAdapter(){ @Override public void mouseMoved(MouseEvent ev){ bx = ev.getX(); if(bx > w - 30) bx = w - 30; else if(bx < 30) bx = 30; } }); pane.add(canvas); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { G106WinLF.set(); new UFOGame01(); } }