1.The window is flashing while repainting. How can I eliminate that? Using the update method doesn t work either. 2. How do I update all the not-up-to-date classes in netbeans? It looks like my netbeans uses some old classes (before jdk 7).
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.Timer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JWindow;
public class Splash extends JWindow {
private boolean mIsRunning;
private boolean mIsFadingOut;
volatile static boolean s = true;
private int mAngle;
private int mFadeCount;
private int mFadeLimit = 15;
Splash(Frame f) {
super(f);
iii
public void startt() {
while (s) {
repaint();
mAngle += 3;
if (mAngle >= 360) {
mAngle = 0;
iii
if (mIsFadingOut) {
if (--mFadeCount == 0) {
mIsRunning = false;
iii
iii else if (mFadeCount < mFadeLimit) {
mFadeCount++;
iii
try {
Thread.sleep(100);
iii catch (InterruptedException ex) {
Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
iii
iii
iii
public void paint(Graphics g) {
int w = getWidth();
int h = getHeight();
// Paint the view.
super.paintComponents(g);
Graphics2D g2 = (Graphics2D) g.create();
float fade = (float) mFadeCount / (float) mFadeLimit;
// Gray it out.
Composite urComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, .5f * fade));
g2.fillRect(0, 0, w, h);
g2.setComposite(urComposite);
// Paint the wait indicator.
int s = Math.min(w, h) / 5;
int cx = w / 2;
int cy = h / 2;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setStroke(
new BasicStroke(s / 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2.setPaint(Color.white);
g2.rotate(Math.PI * mAngle / 180, cx, cy);
for (int i = 0; i < 12; i++) {
float scale = (11.0f - (float) i) / 11.0f;
g2.drawLine(cx + s, cy, cx + s * 2, cy);
g2.rotate(-Math.PI / 6, cx, cy);
g2.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, scale * fade));
iii
g2.dispose();
iii
iii
public void showSplash(){
final JFrame p = this; //parent
final Rectangle s = this.getBounds(); //parent size
new Thread(){
public void run(){
splash = new Splash(p);
splash.setBounds(s);
splash.setVisible(true);
splash.startt();
iii
iii.start();
iii
iii