Hallo Ich möchte einen Thread zur Anzeige der Uhr machen, aber mit diesem Code kann ich nur die Uhr laufen lassen, nachdem ich den Alarm eingegeben habe, obwohl der Alarm auch nicht funktioniert. Möchten Sie den Alarm von der Uhr getrennt MakeWillst du Threaded Clock initiieren, ohne zuerst etwas anzuklicken und Alarm zu geben
Dies ist die Uhr (Arbeits)
public class ClockAlarm extends Thread{
private String txt;
private JLabel Clock;
ClockAlarm(JLabel lbl) {
this.Clock = lbl;
}
ClockAlarm(){
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void run()
{
while(true)
{
try
{
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
Date date = new Date();
String s = sdf.format(date);
Thread.sleep(1000);
Clock.setText(s);
}
catch(Exception e){}
}
}
}
Dies ist die GUI ist, Idk wo Alarm Validierung setzen, wenn ihre Gleichen mit der Uhr, und ich weiß nicht, wo setzen myThread.start oder das Verfahren, das es zu der Zeit seinen Lauf
public class GUI extends javax.swing.JFrame {
ClockAlarm myThread1;
String Alarm;
/**
* Creates new form GUI
*/
public GUI() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(jButton1.getText().equalsIgnoreCase("Set Alarm (hh:mm:ss)")){
Alarm = jTextField1.getText();
}
myThread1 = new ClockAlarm(jLabel1);
myThread1.start();
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}