@Raylan7 escreveu:
Estou criando um programa onde uma bolinha quica nos cantos da tela, mas o problema que essa bolinha fica um pouco piscando. O que eu faço?
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package so1; import java.awt.*; import javax.swing.*; import java.applet.*; import java.util.logging.Level; import java.util.logging.Logger; public class So1 extends Applet{ private static int x1 = 0; private static int x2 = 100; private static int y1 = 0; private static int y2 = 100; private static boolean aumX = true; private static boolean dimX = false; private static boolean aumY = true; private static boolean dimY = false; private static Toolkit tk = Toolkit.getDefaultToolkit(); public void paint (Graphics g) { g.setColor(Color.red); g.fillOval(x1, y1, x2 , y2); g.finalize(); } public static void main(String ad[]) { Dimension d = tk.getScreenSize(); int x = d.width - 100; int y = d.height - 100; JFrame jp1 = new JFrame(); So1 a=new So1 (); jp1.getContentPane().add(a, BorderLayout.CENTER); jp1.setSize(new Dimension(500,500)); jp1.setUndecorated(true); jp1.setExtendedState(JFrame.MAXIMIZED_BOTH); jp1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jp1.getContentPane().setBackground(Color.white); jp1.setVisible(true); new Thread() { @Override public void run() { while (true) { if ((aumX)) x1++; if ((aumY)) y1++; if ((dimX)) x1--; if ((dimY)) y1--; if ((y1 > y)) { aumY=false; dimY=true; } if ((y1 < 0)) { aumY=true; dimY=false; } if ((x1 > x)) { aumX=false; dimX=true; } if ((x1 < 0)) { aumX=true; dimX=false; } try { Thread.sleep(1); } catch (InterruptedException ex) { Logger.getLogger(So1.class.getName()).log(Level.SEVERE, null, ex); } a.repaint(); } } }.start(); } }
Mensagens: 3
Participantes: 2