Link to home
Create AccountLog in
Avatar of osama120
osama120

asked on

how to add the clock label class to my label in the form

i have this class Label clock i wan know how to add it to my label in the  form the class

import java.util.Date;
import java.awt.event.*;
import javax.swing.*;
 
public class ClockLabel extends JLabel implements ActionListener {
 
  public ClockLabel() {
    super("" + new Date());
    Timer t = new Timer(1000, this);
    t.start();
  }
 
  public void actionPerformed(ActionEvent ae) {
    setText((new Date()).toString());
  }
}

Open in new window

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Just add it to the content pane like any other component
contentPane.add(new ClockLabel());
I think you maybe ought to have a DateFormat in there ;-)
Avatar of osama120
osama120

ASKER

im using NetBeans the label is on the Jpanel how i wil do it
ASKER CERTIFIED SOLUTION
Avatar of cmalakar
cmalakar
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account

    private void initComponents() {
        jButton1 = new ColorSelectionButton();

        jButton1.setText("jButton1");
where i will the clocklabel
What does this have to do with the link posted btw?