How can a button work in the Netbeans GUI
I am using NetBeans GUI to create a form.The form has been created ,but the problem is that I am not able to apply any action on the button.
I just want the guidance that what should be applied so that the buttons perform the action.
Foreg: the Exit button should take the command
System.exit(0);
Problem is I am not getting why is it not taking the command.
Please guide.
package process;
import javax.swing.JButton;
import javax.swing.JScrollPane;
publicclass NewJFrameextends javax.swing.JFrame{
/** Creates new form NewJFrame */
public NewJFrame(){
super("Processes");
initComponents();
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
privatevoid initComponents(){
jScrollPane1 =new javax.swing.JScrollPane();
jTextArea1 =new javax.swing.JTextArea();
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();
jButton6 =new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jButton1.setText("Application");
jButton2.setText("time");
jButton3.setText("date");
jButton4.setText("Number");
jButton5.setText("Dummy Register");
jButton6.setText("Exit");
org.jdesktop.layout.GroupLayout layout =new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(47, 47, 47)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jButton3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
.addContainerGap())
.add(layout.createSequentialGroup()
.add(jButton1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 17, Short.MAX_VALUE)
.add(jButton2)
.add(62, 62, 62))))
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
.addContainerGap()))
.add(layout.createSequentialGroup()
.add(75, 75, 75)
.add(jButton5)
.addContainerGap()))
.add(layout.createSequentialGroup()
.add(98, 98, 98)
.add(jButton6)
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(26, 26, 26)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 248, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(34, 34, 34)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton1)
.add(jButton2))
.add(20, 20, 20)
.add(jButton3)
.add(19, 19, 19)
.add(jButton4)
.add(18, 18, 18)
.add(jButton5)
.add(19, 19, 19)
.add(jButton6)))
.addContainerGap(26, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
//How to make the button work
privatevoid Exit(java.awt.event.WindowEvent evt)
{
System.exit(0);
}
/**
* @param args the command line arguments
*/
publicstaticvoid main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable(){
publicvoid run(){
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
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.JButton jButton6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
private JButton Process;
private JButton Priority;
private JButton Time;
private JButton StorageDummyProgrammeCounter;
private JButton DummyRegister;
private JButton Exit;
private JScrollPane jScrollPanel;
}

