mdzafir_alvi

firstLabB2

Dec 2nd, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.05 KB | None | 0 0
  1. package firstlabb2;
  2.  
  3. public class FirstLabB2
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         TestFrame1 obj = new TestFrame1();
  8.         obj.setVisible(true);
  9.     }
  10. }
  11. public class TestFrame1 extends javax.swing.JFrame {
  12.  
  13.     /**
  14.      * Creates new form TestFrame1
  15.      */
  16.     public TestFrame1() {
  17.         initComponents();
  18.     }
  19.  
  20.     /**
  21.      * This method is called from within the constructor to initialize the form.
  22.      * WARNING: Do NOT modify this code. The content of this method is always
  23.      * regenerated by the Form Editor.
  24.      */
  25.     @SuppressWarnings("unchecked")
  26.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  27.     private void initComponents() {
  28.  
  29.         nameLabel = new javax.swing.JLabel();
  30.         nameTextField = new javax.swing.JTextField();
  31.         showLabel = new javax.swing.JLabel();
  32.         showTextField = new javax.swing.JTextField();
  33.         showButton = new javax.swing.JButton();
  34.         num1TextField = new javax.swing.JTextField();
  35.         num2TextField = new javax.swing.JTextField();
  36.         resultTextField = new javax.swing.JTextField();
  37.         addButton = new javax.swing.JButton();
  38.         minusButton = new javax.swing.JButton();
  39.         multiplyButton = new javax.swing.JButton();
  40.         divideButton = new javax.swing.JButton();
  41.  
  42.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  43.  
  44.         nameLabel.setText("Enter you name");
  45.  
  46.         showLabel.setText("Hello");
  47.  
  48.         showTextField.addActionListener(new java.awt.event.ActionListener() {
  49.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  50.                 showTextFieldActionPerformed(evt);
  51.             }
  52.         });
  53.  
  54.         showButton.setText("SHOW");
  55.         showButton.addActionListener(new java.awt.event.ActionListener() {
  56.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  57.                 showButtonActionPerformed(evt);
  58.             }
  59.         });
  60.  
  61.         resultTextField.addActionListener(new java.awt.event.ActionListener() {
  62.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  63.                 resultTextFieldActionPerformed(evt);
  64.             }
  65.         });
  66.  
  67.         addButton.setText("ADD");
  68.         addButton.addActionListener(new java.awt.event.ActionListener() {
  69.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  70.                 addButtonActionPerformed(evt);
  71.             }
  72.         });
  73.  
  74.         minusButton.setText("Minus");
  75.         minusButton.addActionListener(new java.awt.event.ActionListener() {
  76.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  77.                 minusButtonActionPerformed(evt);
  78.             }
  79.         });
  80.  
  81.         multiplyButton.setText("Multiply");
  82.         multiplyButton.addActionListener(new java.awt.event.ActionListener() {
  83.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  84.                 multiplyButtonActionPerformed(evt);
  85.             }
  86.         });
  87.  
  88.         divideButton.setText("Divide");
  89.         divideButton.addActionListener(new java.awt.event.ActionListener() {
  90.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  91.                 divideButtonActionPerformed(evt);
  92.             }
  93.         });
  94.  
  95.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  96.         getContentPane().setLayout(layout);
  97.         layout.setHorizontalGroup(
  98.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  99.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  100.                 .addGap(53, 53, 53)
  101.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  102.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  103.                         .addComponent(nameLabel)
  104.                         .addComponent(showLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
  105.                     .addComponent(num1TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
  106.                 .addGap(18, 18, 18)
  107.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  108.                     .addGroup(layout.createSequentialGroup()
  109.                         .addComponent(num2TextField, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
  110.                         .addGap(18, 18, 18)
  111.                         .addComponent(resultTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
  112.                     .addComponent(showTextField)
  113.                     .addComponent(nameTextField))
  114.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  115.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  116.                     .addComponent(divideButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  117.                     .addComponent(multiplyButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  118.                     .addComponent(showButton)
  119.                     .addComponent(minusButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  120.                     .addComponent(addButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  121.                 .addGap(76, 76, 76))
  122.         );
  123.         layout.setVerticalGroup(
  124.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  125.             .addGroup(layout.createSequentialGroup()
  126.                 .addGap(99, 99, 99)
  127.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  128.                     .addComponent(nameLabel)
  129.                     .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  130.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  131.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  132.                     .addComponent(showLabel)
  133.                     .addComponent(showTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  134.                     .addComponent(showButton))
  135.                 .addGap(27, 27, 27)
  136.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  137.                     .addComponent(num1TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  138.                     .addComponent(num2TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  139.                     .addComponent(resultTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  140.                     .addComponent(addButton))
  141.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  142.                 .addComponent(minusButton)
  143.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  144.                 .addComponent(multiplyButton)
  145.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  146.                 .addComponent(divideButton)
  147.                 .addContainerGap(15, Short.MAX_VALUE))
  148.         );
  149.  
  150.         pack();
  151.     }// </editor-fold>                        
  152.  
  153.     private void showTextFieldActionPerformed(java.awt.event.ActionEvent evt) {                                              
  154.         // TODO add your handling code here:
  155.     }                                            
  156.  
  157.     private void showButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
  158.         // TODO add your handling code here:
  159.         String name = nameTextField.getText();
  160.         showTextField.setText(name);
  161.     }                                          
  162.  
  163.     private void resultTextFieldActionPerformed(java.awt.event.ActionEvent evt) {                                                
  164.         // TODO add your handling code here:
  165.     }                                              
  166.  
  167.     private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
  168.         // TODO add your handling code here:
  169.         int num1,num2,result;
  170.         num1=Integer.parseInt(num1TextField.getText());
  171.         num2=Integer.parseInt(num2TextField.getText());
  172.         result=num1+num2;
  173.         //resultTextField.setText(Integer.toString(result));
  174.         //another way to write the previous line :
  175.         resultTextField.setText(""+result);
  176.     }                                        
  177.  
  178.     private void minusButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
  179.         // TODO add your handling code here:
  180.         int num1,num2,result;
  181.         num1=Integer.parseInt(num1TextField.getText());
  182.         num2=Integer.parseInt(num2TextField.getText());
  183.         result=num1-num2;
  184.         //resultTextField.setText(Integer.toString(result));
  185.         //another way to write the previous line :
  186.         resultTextField.setText(""+result);
  187.     }                                          
  188.  
  189.     private void multiplyButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
  190.         // TODO add your handling code here:
  191.         int num1,num2,result;
  192.         num1=Integer.parseInt(num1TextField.getText());
  193.         num2=Integer.parseInt(num2TextField.getText());
  194.         result=num1*num2;
  195.         //resultTextField.setText(Integer.toString(result));
  196.         //another way to write the previous line :
  197.         resultTextField.setText(""+result);
  198.     }                                              
  199.  
  200.     private void divideButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
  201.         // TODO add your handling code here:
  202.         int num1,num2,result;
  203.         num1=Integer.parseInt(num1TextField.getText());
  204.         num2=Integer.parseInt(num2TextField.getText());
  205.         result=num1/num2;
  206.         //resultTextField.setText(Integer.toString(result));
  207.         //another way to write the previous line :
  208.         resultTextField.setText(""+result);
  209.     }                                            
  210.  
  211.     /**
  212.      * @param args the command line arguments
  213.      */
  214.     public static void main(String args[]) {
  215.         /* Set the Nimbus look and feel */
  216.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  217.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  218.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  219.          */
  220.         try {
  221.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  222.                 if ("Nimbus".equals(info.getName())) {
  223.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  224.                     break;
  225.                 }
  226.             }
  227.         } catch (ClassNotFoundException ex) {
  228.             java.util.logging.Logger.getLogger(TestFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  229.         } catch (InstantiationException ex) {
  230.             java.util.logging.Logger.getLogger(TestFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  231.         } catch (IllegalAccessException ex) {
  232.             java.util.logging.Logger.getLogger(TestFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  233.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  234.             java.util.logging.Logger.getLogger(TestFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  235.         }
  236.         //</editor-fold>
  237.  
  238.         /* Create and display the form */
  239.         java.awt.EventQueue.invokeLater(new Runnable() {
  240.             public void run() {
  241.                 new TestFrame1().setVisible(true);
  242.             }
  243.         });
  244.     }
  245.  
  246.     // Variables declaration - do not modify                    
  247.     private javax.swing.JButton addButton;
  248.     private javax.swing.JButton divideButton;
  249.     private javax.swing.JButton minusButton;
  250.     private javax.swing.JButton multiplyButton;
  251.     private javax.swing.JLabel nameLabel;
  252.     private javax.swing.JTextField nameTextField;
  253.     private javax.swing.JTextField num1TextField;
  254.     private javax.swing.JTextField num2TextField;
  255.     private javax.swing.JTextField resultTextField;
  256.     private javax.swing.JButton showButton;
  257.     private javax.swing.JLabel showLabel;
  258.     private javax.swing.JTextField showTextField;
  259.     // End of variables declaration                  
  260. }
Advertisement
Add Comment
Please, Sign In to add comment