package jamdigital;
import java.util.Date;
/**
*
* @author glaShSial
*/
public class JamDigital extends javax.swing.JFrame {
private int jam,menit,detik;
private String Sjam,Smenit,Sdetik;
private JLabel jmlbl;
public JamDigital() {
initComponents();
}
@SuppressWarnings("unchecked")
//
private void initComponents() {
jmlbl = new javax.swing.JLabel();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setAlwaysOnTop(true);
setResizable(false);
setUndecorated(false);
addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent evt) {
formWindowActivated(evt);
}
});
jmlbl.setFont(new Font("Arial Narrow", 1, 18)); // NOI18N
jmlbl.setText("jLabel1");
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jmlbl, GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jmlbl)
.addContainerGap(13, Short.MAX_VALUE))
);
pack();
}//
private void formWindowActivated(java.awt.event.WindowEvent evt) {
}
private void formComponentShown(java.awt.event.ComponentEvent evt) {
// TODO add your handling code here:
TimerTask tt=new TimerTask() {
@Override
public void run() {
//System.out.println("xx");
Date dt=new Date();
Calendar cld=Calendar.getInstance();
cld.setTime(dt);
jam=dt.getHours();
menit=dt.getMinutes();
detik=dt.getSeconds();
Sjam=Integer.toString(jam);
Smenit=Integer.toString(menit);
Sdetik=Integer.toString(detik);
jmlbl.setText(""+Sjam +" : "+Smenit +" : "+Sdetik+"");
}
};
Timer t=new Timer();
t.schedule(tt,0, 100);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new JamDigital().setVisible(true);
}
});
}
}
if you want to add some styles, you have to add these code at the main class this project is added with a substance library which is can be downloaded in the internet
the substance used to decorate the display
public static void main(String[] args) throws UnsupportedLookAndFeelException {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
UIManager.setLookAndFeel(new SubstanceMagmaLookAndFeel());
EventQueue.invokeLater(new Runnable() {
public void run() {
new JamDigital().setVisible(true);
}
});
}
Langganan:
Posting Komentar (Atom)

Tidak ada komentar:
Posting Komentar