Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class pruebaText {
- private JFrame frame;
- private JLabel lblText;
- int cont = 0;
- private JLabel lblText5;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- pruebaText window = new pruebaText();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public pruebaText() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- lblText = new JLabel("");
- lblText.setBounds(89, 66, 46, 14);
- frame.getContentPane().add(lblText);
- JButton btnNewButton = new JButton("New button");
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try{
- while (cont<10) {
- Thread.sleep(1000);
- cont++;
- System.out.println(cont);
- if (cont==5) {
- lblText.setText("hola");
- }
- }
- }catch (Exception e1) {
- // TODO: handle exception
- System.out.println(e1);
- }
- }
- });
- btnNewButton.setBounds(89, 197, 89, 23);
- frame.getContentPane().add(btnNewButton);
- lblText5 = new JLabel("");
- lblText5.setBounds(341, 38, 46, 14);
- frame.getContentPane().add(lblText5);
- }
- }
- public static void mostarTexto() {
- for (int i = 0; i < 10; i++) {
- try {
- Thread.sleep(1000);
- //Para ver la evulocion de i en Console de eclipe
- System.out.println(i);
- if (i / 2 == 0) {
- lblTexto.setText("hola");
- } else {
- lblTexto.setText(" ");
- }
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment