Hallo zusammen,
hab mich entschieden eine Stoppuhr zu progrmieren. Leider ist es so, dass diese weder angezeigt, noch abgespielt wird. Ich progrmiere diese in Netbeans. Allerdings zeigt Netbeans keine Fehler oder Probleme an. Ich weiß nicht mehr weiter. Kann mir jemand einen Tipp geben, bitte?
hab mich entschieden eine Stoppuhr zu progrmieren. Leider ist es so, dass diese weder angezeigt, noch abgespielt wird. Ich progrmiere diese in Netbeans. Allerdings zeigt Netbeans keine Fehler oder Probleme an. Ich weiß nicht mehr weiter. Kann mir jemand einen Tipp geben, bitte?
Java:
package uhr;
/**
*
* @author kaethe
*/
public class Uhrjframe extends javax.swing.JFrame {
public static boolean running = false;
/**
* Creates new form Uhrjframe
*/
public Uhrjframe() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
Überschrift = new javax.swing.JLabel();
Start = new javax.swing.JButton();
ausgabe = new javax.swing.JLabel();
Stop = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
Überschrift.setText("Stoppuhr");
Start.setText("Start");
Start.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
StartActionPerformed(evt);
}
});
Stop.setText("Stop");
Stop.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
StopActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(51, 51, 51)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(ausgabe, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(Start)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(Stop)))
.addGap(92, 92, 92))
.addGroup(layout.createSequentialGroup()
.addGap(151, 151, 151)
.addComponent(Überschrift, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(130, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addComponent(Überschrift, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(39, 39, 39)
.addComponent(ausgabe, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Start)
.addComponent(Stop))
.addGap(47, 47, 47))
);
pack();
}// </editor-fold>
private void StartActionPerformed(java.awt.event.ActionEvent evt) {
if(!running){
running = true;
new UhrzeitThread().start(); // TODO add your handling code here:
}
}
private void StopActionPerformed(java.awt.event.ActionEvent evt) {
running = false;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Uhrjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Uhrjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Uhrjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Uhrjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Uhrjframe().setVisible(true);
}
});
}
class UhrzeitThread extends Thread {
private int HS = 0;
private int sek = 0;
private int min = 0;
private int h = 0;
public void run(){
while(running){
try{Thread.sleep(9);}catch(Exception e){}
if(HS <= 99){
HS++;
}
else {
HS = 0;
if(sek <= 59){
sek++;
}else {
sek = 0;
if(min <= 59){
min++;
} else {
min = 0;
h++;
}
}
}
Uhrjframe.ausgabe.setText(h + " : " + min + " : " + sek + " : " + HS);
}
}
}
// Variables declaration - do not modify
private javax.swing.JButton Start;
private javax.swing.JButton Stop;
private static javax.swing.JLabel ausgabe;
private javax.swing.JLabel Überschrift;
// End of variables declaration
}