Working In NetBeans IDE (Integrated Development Environment)

In this article, you will learn about NetBeans IDE (Integrated Development Environment).

Hello Students.

Today, I am writing this article on how to start programming in NetBeans IDE. I hope this helps you.

To get started, download the latest stable version from the netbeans.org web site and install it on your machine. After installation, when you start your application, you should get a welcome screen similar to the image below.



Step 1 - Creating new project

To create new project, you can follow any of these methods.
  • Click File from the main menu and select New Project.
  • Click on New project icon toolbar.
  • Press shortcut keys like Ctrl+Shift+N.

The New Project Wizard will open up, as shown in the mage below,



Step 2 - Choose java as category type and select java application as project type

  • Click Next, then enter the project name, and select location within your file system.



     Click Finish. You now know how to start NetBeans IDE. Now, see how to start the program.



    Adding JFrame Form helps you. In the left side in project name right click on the project name and right click on the source package mode.

    From the shortcut menu, select new Jframe form a dialog image appears below.



After JFrame form, the below image appears.



Form Palatte: drag and drop one button and 4 textboxes and labels; right click button and click properties and edit text name as you want; you add name in your application as per project.

In this application, I will show total Fruit Quantities with message dialog.



After designing,  now the source code: click on button and add source code.

  1. import javax.swing.JOptionPane;  
  2. /* 
  3.  * To change this license header, choose License Headers in Project Properties. 
  4.  * To change this template file, choose Tools | Templates 
  5.  * and open the template in the editor. 
  6.  */  
  7. /** 
  8.  * 
  9.  * @author Krishna Rajput 
  10.  */  
  11. public class Javaworld extends javax.swing.JFrame {  
  12.     public Javaworld() {  
  13.             initComponents();  
  14.         }  
  15.         /** 
  16.          * This method is called from within the constructor to initialize the form. 
  17.          * WARNING: Do NOT modify this code. The content of this method is always 
  18.          * regenerated by the Form Editor. 
  19.          */  
  20.     @SuppressWarnings("unchecked")  
  21.         // <editor-fold defaultstate="collapsed" desc="Generated Code">   
  22.     private void initComponents() {  
  23.             jButton1 = new javax.swing.JButton();  
  24.             jTextField1 = new javax.swing.JTextField();  
  25.             jTextField2 = new javax.swing.JTextField();  
  26.             jTextField3 = new javax.swing.JTextField();  
  27.             jTextField4 = new javax.swing.JTextField();  
  28.             jLabel1 = new javax.swing.JLabel();  
  29.             jLabel2 = new javax.swing.JLabel();  
  30.             jLabel3 = new javax.swing.JLabel();  
  31.             jLabel4 = new javax.swing.JLabel();  
  32.             jButton2 = new javax.swing.JButton();  
  33.             setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);  
  34.             jButton1.setText("Total Fruits");  
  35.             jButton1.addActionListener(new java.awt.event.ActionListener() {  
  36.                 public void actionPerformed(java.awt.event.ActionEvent evt) {  
  37.                     jButton1ActionPerformed(evt);  
  38.                 }  
  39.             });  
  40.             jTextField1.addActionListener(new java.awt.event.ActionListener() {  
  41.                 public void actionPerformed(java.awt.event.ActionEvent evt) {  
  42.                     jTextField1ActionPerformed(evt);  
  43.                 }  
  44.             });  
  45.             jTextField3.addActionListener(new java.awt.event.ActionListener() {  
  46.                 public void actionPerformed(java.awt.event.ActionEvent evt) {  
  47.                     jTextField3ActionPerformed(evt);  
  48.                 }  
  49.             });  
  50.             jLabel1.setText("Enter Apples Quantites");  
  51.             jLabel2.setText("Enter Bananas Quantites");  
  52.             jLabel3.setText("Enter Orange Quantites");  
  53.             jLabel4.setText("Total Fruits Quantites");  
  54.             jButton2.setText("Exit");  
  55.             jButton2.addActionListener(new java.awt.event.ActionListener() {  
  56.                 public void actionPerformed(java.awt.event.ActionEvent evt) {  
  57.                     jButton2ActionPerformed(evt);  
  58.                 }  
  59.             });  
  60.             javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());  
  61.             getContentPane().setLayout(layout);  
  62.             layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(262626).addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap()).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(jButton2).addGap(282828)))).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addGroup(layout.createSequentialGroup().addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false).addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jTextField3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)))).addGap(919191)));  
  63.             layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(222222).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(272727).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(282828).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false).addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE).addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addGroup(layout.createSequentialGroup().addGap(161616).addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addGap(121212)).addGroup(layout.createSequentialGroup().addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))).addGap(242424)));  
  64.             pack();  
  65.         } // </editor-fold>   
  66.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {  
  67.         //String Fruits = null;  
  68.         //System.exit(0);  
  69.         int Apples, Bananas, Orange, Fruits;  
  70.         Apples = Integer.parseInt(jTextField1.getText());  
  71.         Bananas = Integer.parseInt(jTextField2.getText());  
  72.         Orange = Integer.parseInt(jTextField3.getText());  
  73.         Fruits = Apples + Bananas + Orange;  
  74.         jTextField4.setText(Integer.toString(Fruits));  
  75.         JOptionPane.showMessageDialog(null"Total Fruits are\n" + Fruits);  
  76.         // TODO add your handling code here:  
  77.     }  
  78.     private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {  
  79.         // TODO add your handling code here:  
  80.     }  
  81.     private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {  
  82.         // TODO add your handling code here:  
  83.     }  
  84.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {  
  85.             // TODO add your handling code here:  
  86.             System.exit(0);  
  87.         }  
  88.         /** 
  89.          * @param args the command line arguments 
  90.          */  
  91.     public static void main(String args[]) {  
  92.             /* Set the Nimbus look and feel */  
  93.             //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">  
  94.             /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. 
  95.              * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html  
  96.              */  
  97.             try {  
  98.                 for (javax.swing.UIManager.LookAndFeelInfo info: javax.swing.UIManager.getInstalledLookAndFeels()) {  
  99.                     if ("Nimbus".equals(info.getName())) {  
  100.                         javax.swing.UIManager.setLookAndFeel(info.getClassName());  
  101.                         break;  
  102.                     }  
  103.                 }  
  104.             } catch (ClassNotFoundException ex) {  
  105.                 java.util.logging.Logger.getLogger(Javaworld.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);  
  106.             } catch (InstantiationException ex) {  
  107.                 java.util.logging.Logger.getLogger(Javaworld.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);  
  108.             } catch (IllegalAccessException ex) {  
  109.                 java.util.logging.Logger.getLogger(Javaworld.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);  
  110.             } catch (javax.swing.UnsupportedLookAndFeelException ex) {  
  111.                 java.util.logging.Logger.getLogger(Javaworld.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);  
  112.             }  
  113.             //</editor-fold>  
  114.             /* Create and display the form */  
  115.             java.awt.EventQueue.invokeLater(new Runnable() {  
  116.                 public void run() {  
  117.                     new Javaworld().setVisible(true);  
  118.                 }  
  119.             });  
  120.         }  
  121.         // Variables declaration - do not modify   
  122.     private javax.swing.JButton jButton1;  
  123.     private javax.swing.JButton jButton2;  
  124.     private javax.swing.JLabel jLabel1;  
  125.     private javax.swing.JLabel jLabel2;  
  126.     private javax.swing.JLabel jLabel3;  
  127.     private javax.swing.JLabel jLabel4;  
  128.     private javax.swing.JTextField jTextField1;  
  129.     private javax.swing.JTextField jTextField2;  
  130.     private javax.swing.JTextField jTextField3;  
  131.     private javax.swing.JTextField jTextField4;  
  132.     // End of variables declaration   
  133. }  
Now I have done my project so let’s check output. So for running it,  go to projects section, select your project, right click and click Run File or shortcut Shift+F6.



Congrats! You have done Netbeans GUI Application.



Value is entered by user, See the output.



So friends, this article will help you create a Java GUI Application using NetBeans. Next time, I will put some more interesting commands. Thank you. I hope this is helpful for you. Enjoy :)