Olá pessoal sou novo por aqui e em Java também, mas andei brincando um pouco e ai surgiu a seguinte dúvida:
Tenho uma classe BarraStatus:
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package view;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JLabel;
/**
*
-
@author Denir R. Tavares */ public class BarraStatus { JLabel data, hora, usuario, caps, num, scroll;
public JLabel Data(){ data = new JLabel(); Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { data.setText(new SimpleDateFormat(“dd/MM/yyyy”).format(new Date(System.currentTimeMillis()))); } }; timer.schedule(task, 1000, 1000); return data; }
public JLabel Hora(){ hora = new JLabel(); Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { hora.setText(new SimpleDateFormat(“HH:mm:ss”).format(new Date(System.currentTimeMillis()))); } }; timer.schedule(task, 1000, 1000); return hora; }
public JLabel Usuario(){
return usuario;
}
public JLabel CapsLock(){ boolean capsLigado = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK); if (capsLigado) { caps.setText(“MAI”); } else { caps.setText(“min”); } return caps; }
public JLabel NumLock(){ boolean capsLigado = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_NUM_LOCK); if (capsLigado) { num.setText(“NUM”); } else { num.setText(“num”); } return num; }
public JLabel ScrollLock(){ boolean capsLigado = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_SCROLL_LOCK); if (capsLigado) { scroll.setText(“SCR”); } else { scroll.setText(“scr”); } return scroll; } }
E na minha classe JFrame estou envocando o seguinte dentro de initComponentes
public Principal() {
initComponents();
BarraStatus br = new BarraStatus();
JLabel Data = br.Data();
jlblData.setText(Data.getText());
}
Dentro desta classe tenho uma barra de status com jlabels só que não aparece valor algum fica em branco. Como posso resolver esse problemão.