Computer Science, asked by Anonymous, 1 year ago

GUI program on button simulation

Answers

Answered by anuj
3

public class NewJFrameghhg extends javax.swing.JFrame {


 

    public NewJFrameghhg() 

{


        initComponents();

    }

            int a=0;

   

    private void initComponents()

{

 

        jButton1 = new javax.swing.JButton();

        jButton2 = new javax.swing.JButton();

        jButton3 = new javax.swing.JButton();

        jButton4 = new javax.swing.JButton();

        jButton5 = new javax.swing.JButton();

        jLabel1 = new javax.swing.JLabel();

 

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

 

        jButton1.setText("START");

        jButton1.addActionListener(new java.awt.event.ActionListener() 

{

            public void actionPerformed(java.awt.event.ActionEvent evt)

{

                jButton1ActionPerformed(evt);

            }

        });

 

        jButton2.setText("INCREMENT");

        jButton2.addActionListener(new java.awt.event.ActionListener() 

{

            public void actionPerformed(java.awt.event.ActionEvent evt) 

{

                jButton2ActionPerformed(evt);

            }

        });

 

        jButton3.setText("STOP");

        jButton3.addActionListener(new java.awt.event.ActionListener() 

{

            public void actionPerformed(java.awt.event.ActionEvent evt)

{

                jButton3ActionPerformed(evt);

            }

        });

 

        jButton4.setText("CLEAR");

        jButton4.addActionListener(new java.awt.event.ActionListener()

{

            public void actionPerformed(java.awt.event.ActionEvent evt) 

{

                jButton4ActionPerformed(evt);

            }

        });

 

        jButton5.setText("EXIT");

        jButton5.addActionListener(new java.awt.event.ActionListener()

{

            public void actionPerformed(java.awt.event.ActionEvent evt)

{

                jButton5ActionPerformed(evt);

            }

        });

 

 

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        

        // TODO add your handling code here:

        jLabel1.setText(" "+a);

       

    }                                        

 

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        

        // TODO add your handling code here:

         jLabel1.setText(" "+(++a));

    }                                       

 

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        

        // TODO add your handling code here:

       

           

            jButton1.setEnabled(false);

          jButton2.setEnabled(false);

            jButton3.setEnabled(false);

    }                                       

 

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                        

        // TODO add your handling code here:

           jButton3.doClick();

        jButton1.setEnabled(true);

          jButton2.setEnabled(true);

            jButton3.setEnabled(true);

    }                                       

 

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        System.exit(0);

    }                                       

 

    public static void main(String args[]) {

        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(NewJFrameghhg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (InstantiationException ex) {

            java.util.logging.Logger.getLogger(NewJFrameghhg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (IllegalAccessException ex) {

            java.util.logging.Logger.getLogger(NewJFrameghhg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (javax.swing.UnsupportedLookAndFeelException ex) {

            java.util.logging.Logger.getLogger(NewJFrameghhg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        }

        

 

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                new NewJFrameghhg().setVisible(true);

            }

        });

    }

 

   

    private javax.swing.JButton jButton1;

    private javax.swing.JButton jButton2;

    private javax.swing.JButton jButton3;

    private javax.swing.JButton jButton4;

    private javax.swing.JButton jButton5;

    private javax.swing.JLabel jLabel1;

}

Similar questions