0
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Main {
int FrameNum;  
static JButton LauB; 

public Main() { 
    FrameCraft MainPag = new FrameCraft(700,600);
    LauB = new JButton("Launch");
    LauB.setFocusPainted(false);
    LauB.setForeground(new Color(255, 255, 255));
    LauB.setBackground(new Color(50,30,60));
    LauB.setSize(200,80);
    LauB.setLocation(MainPag.getWidth()/3,MainPag.getHeight()-150);
    LauB.setContentAreaFilled(false);
    LauB.setOpaque(true);

    LauB.setBorder(BorderFactory.createLineBorder(new Color(255, 255, 255)));
    MainPag.BackG.add(LauB);

    EventMan Han = new EventMan();
    LauB.addActionListener(Han);
}


public static void main(String[]args) {
new Main();
}

public class EventMan implements ActionListener {
    public void actionPerformed(ActionEvent Eve) {
        if (Eve.getSource() == LauB) { 
        LauB.setText("Launching");
        LauB.setBackground(new Color(90,30,60));
            try {
                LauB.setText("Launching.");
                Thread.sleep(1000);
                LauB.setText("Launching..");
                Thread.sleep(1000);
                LauB.setText("Launching...");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            }

        }

    } 

}

-The problem is Thread.sleep(isn't running one at a time then executing next line of code). So may someone please tell me how to fix this problem; with a detailed solution and why it isn't working. One more thing if you happen to answer this question effectively for me - thankyou.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1) Don't block the EDT (Event Dispatch Thread). The GUI will 'freeze' when that happens. See [Concurrency in Swing](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/) for details and the fix. 2) Please learn common Java nomenclature (naming conventions - e.g. `EachWordUpperCaseClass`, `firstWordLowerCaseMethod()`, `firstWordLowerCaseAttribute` unless it is an `UPPER_CASE_CONSTANT`) and use it consistently. – Andrew Thompson May 02 '15 at 02:39
  • .. 3) `LauB.setSize(200,80);` See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) The same principle applies to `setSize(..)`. To make a big button, give it a big icon, a large font size, large insets or a large empty border. – Andrew Thompson May 02 '15 at 02:43

0 Answers0