/** * * @author AMIT RAWAT */public class atm extends javax.swing.JFrame { private double total1=0.0; private double total2=0.0; private char math_operator ; private void getOperator(String bt) { math_operator =bt.charAt(0); total1=total2 + Double.parseDouble(t1.getText()); t1.setText(""); } public atm() { initComponents(); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">private void initComponents() { ba = new javax.swing.JButton(); bs = new javax.swing.JButton(); bm = new javax.swing.JButton(); bd = new javax.swing.JButton(); t1 = new javax.swing.JTextField(); b1 = new javax.swing.JButton(); b2 = new javax.swing.JButton(); b3 = new javax.swing.JButton(); b4 = new javax.swing.JButton(); b5 = new javax.swing.JButton(); b6 = new javax.swing.JButton(); b7 = new javax.swing.JButton(); b8 = new javax.swing.JButton(); b9 = new javax.swing.JButton(); b0 = new javax.swing.JButton(); eq = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); ba.setText("+"); ba.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { baActionPerformed(evt); } }); bs.setText("-"); bs.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bsActionPerformed(evt); } }); bm.setText("*"); bm.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bmActionPerformed(evt); } }); bd.setText("/"); bd.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bdActionPerformed(evt); } }); t1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N b1.setText("1"); b1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { b1ActionPerformed(evt); } }); b2.setText("2"); b2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { b2ActionPerformed(evt); } }); b3.setText("3"); b3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { b3ActionPerformed(evt); } }); b4.setText("4"); b4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { b4ActionPerformed(evt); } }); b5.setText("5"); b5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { b5ActionPerformed(evt); } }); b6.setText("6"); b6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { b6ActionPerformed(evt); } }); b7.setText("7"); b7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { b7ActionPerformed(evt); } }); b8.setText("8"); b8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { b8ActionPerformed(evt); } }); b9.setText("9"); b9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { b9ActionPerformed(evt); } }); b0.setText("0"); b0.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { b0ActionPerformed(evt); } }); eq.setText("="); eq.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { eqActionPerformed(evt); } }); jButton1.setText("clear"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18NjLabel1.setText("CALCULATOR"); 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() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent
(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 177,javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(104, 104, 104)) .addGroup(layout.createSequentialGroup() .addGap(34, 34, 34) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, 388, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent
(b1, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE) .addComponent(b4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE) .addComponent
(b7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE) .addComponent
(b0, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)) .addGap(29, 29, 29) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup
(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent
(b8, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE) .addComponent(b5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE) .addComponent
(b2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)) .addGap(29, 29, 29) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent
(b6, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE) .addComponent(b3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)) .addComponent
(b9, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() .addComponent(jButton1) .addGap(28, 28, 28) .addComponent(eq, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE))) .addGap(59, 59, 59) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(bd, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(bs, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(ba, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(bm, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap(25, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 37,javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(28, 28, 28) .addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(28, 28, 28) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup
(layout.createSequentialGroup() .addComponent(b1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(b4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)) .addGroup
(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(b3) .addGap(20, 20, 20) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(b6) addComponent(bs)))) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(b7,
javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(b8)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(b9) .addComponent(bm)))) .addGroup(layout.createSequentialGroup() .addComponent(b2) .addGap(20, 20, 20) .addComponent(b5))) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(b0) .addGroup(layout.createParallelGroup
(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(eq) .addComponent(bd)))) .addComponent(ba)) .addContainerGap(40, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void b1ActionPerformed(java.awt.event.ActionEvent evt) { String b1text=t1.getText()+ b1.getText(); t1.setText(b1text); } private void b2ActionPerformed(java.awt.event.ActionEvent evt) { String b2text=t1.getText()+ b2.getText(); t1.setText(b2text); } private void b3ActionPerformed(java.awt.event.ActionEvent evt) { String b3text=t1.getText()+ b3.getText(); t1.setText(b3text); } private void b4ActionPerformed(java.awt.event.ActionEvent evt) { String b4text=t1.getText()+ b4.getText(); t1.setText(b4text); } private void b5ActionPerformed(java.awt.event.ActionEvent evt) { String b5text=t1.getText()+ b5.getText(); t1.setText(b5text); } private void b6ActionPerformed(java.awt.event.ActionEvent evt) { String b6text=t1.getText()+ b6.getText(); t1.setText(b6text); } private void b7ActionPerformed(java.awt.event.ActionEvent evt) { String b7text=t1.getText()+ b7.getText(); t1.setText(b7text); } private void b8ActionPerformed(java.awt.event.ActionEvent evt) { String b8text=t1.getText()+ b8.getText(); t1.setText(b8text); } private void b9ActionPerformed(java.awt.event.ActionEvent evt) { String b9text=t1.getText()+ b9.getText(); t1.setText(b9text); } private void b0ActionPerformed(java.awt.event.ActionEvent evt) { String b0text=t1.getText()+ b0.getText(); t1.setText(b0text); } private void baActionPerformed(java.awt.event.ActionEvent evt) { String bt=ba.getText(); getOperator (bt); } private void eqActionPerformed(java.awt.event.ActionEvent evt) { switch(math_operator) { case '+': total2=total1+Double.parseDouble(t1.getText()); break; case '-': total2=total1-Double.parseDouble(t1.getText()); break; case '*': total2=total1*Double.parseDouble(t1.getText()); break; case '/': total2=total1/Double.parseDouble(t1.getText()); break; } t1.setText(Double.toString( total2)); total1=0; } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { total2=0; t1.setText(""); } private void bsActionPerformed(java.awt.event.ActionEvent evt) { String bt=bs.getText(); getOperator (bt); } private void bmActionPerformed(java.awt.event.ActionEvent evt) { String bt=bm.getText(); getOperator (bt); } private void bdActionPerformed(java.awt.event.ActionEvent evt) { String bt=bd.getText(); getOperator (bt); } /** * @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(atm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(atm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(atm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(atm.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 atm().setVisible(true); } }); } // Variables declaration - do not modifyprivate javax.swing.JButton b0; private javax.swing.JButton b1; private javax.swing.JButton b2; private javax.swing.JButton b3; private javax.swing.JButton b4; private javax.swing.JButton b5; private javax.swing.JButton b6; private javax.swing.JButton b7; private javax.swing.JButton b8; private javax.swing.JButton b9; private javax.swing.JButton ba; private javax.swing.JButton bd; private javax.swing.JButton bm; private javax.swing.JButton bs; private javax.swing.JButton eq; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JTextField t1; // End of variables declaration}
Android Tutorial -Learn Android Programming and how to develop android application,activity,lifecycle,service,layout,architecture,debugging,bugs ,handling event others.
- HOME
- JAVA
- ANDROID
- 1.Material Search View (google play store search bar)
- 2.RecyclerView with a SearchView with filter
- 3.Speed Up android studio process Class
- 4.load url image from the network by asych task
- 5.Convert string to MD5
- 6.pass arraylist through intent
- 7.Bitmap to base64 convert
- 8.Snackbar Getview
- 9.load images from url and load into ViewPager with json
- 10.Splash Screen with timer
- 11.java could not reserve enough space
- 12.Cannot load project java.lang.NullPointerException
- 13.selecting pic from gallery or camera through intent
- 14.View Pager with Circle Indicator(Image slider show)
- 15.Internet Connection Detector
- 16.WebView with Progress Dialog
- 17.Created animated GIF with images
- 18.Reduce Android Studio Project Size
- 19.unable to resolve dependency
- 20.call Fragment method in Main Activity by interface
- 21.Get RecyclerViewAdapter onclick postion in main activity
- 22.Circle ImageView
- Flutter
- C#
- 1.Array
- 2.Jagged Array
- 3.Small Application program
- 4.Inheritance hybrid
- 5.ReferenceType:PassByVal and PassByRef
- 6.PlaceHolder
- 7.Interface:Implementing Multiple Inheritance
- 8.Collections: ArrayList,HashTable,Stack
- 9.Scope Test
- 10.Boxing and Unboxing
- 11.Constructors
- 12.Polymorphism: Overload / Override
- UNIX
- Videos
- Download
- About
- Github
- Youtube
Calculator program in Netbean Java Code
Subscribe to:
Posts (Atom)
No comments:
Post a Comment