Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
int r, y;
/**
* Creates new form traficlight
*/
public traficlight() {
initComponents();
start();
}
public void start()
{
int speed = 1000;
r = lred;
y = lyellow;
mulai = awal;
ActionListener action;
action = new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
//To change body of generated methods, choose Tools | Templates.
if ((angka%2==0) && (angka <= 100)) {
nkuning.setText(null);
nkuning.setEnabled(true);
nmerah.setEnabled(false);
nkuning.setText(String.valueOf(angka));
angka=angka+1;
r--;
}
else if ((angka%1==0) && (angka <=100)) {
nmerah.setText(null);
nmerah.setEnabled(true);
nkuning.setEnabled(false);
nmerah.setText(String.valueOf(angka));
angka=angka+1;
y--;
}
}
};
timer = new Timer(speed, action);
timer.start();
}
/**
* 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() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(nkuning, javax.swing.GroupLayout.PREFERRED_SIZE,
255, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(nmerah, javax.swing.GroupLayout.PREFERRED_SIZE,
243, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(78, 78, 78))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(nmerah)
.addGap(30, 30, 30)
.addComponent(nkuning)
.addContainerGap(38, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @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(traficlight.class.getName()).log(java.util.logging.
Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(traficlight.class.getName()).log(java.util.logging.
Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(traficlight.class.getName()).log(java.util.logging.
Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(traficlight.class.getName()).log(java.util.logging.
Level.SEVERE, null, ex);
}
//</editor-fold>