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;

}

[7665 byte] By [maggiemaggiea] at [2007-11-26 18:51:27]
# 1

Replace this

//How to make the button work

private void Exit(java.awt.event.WindowEvent evt)

{

System.exit(0);

}

with this

private void jButton6MouseMoved(java.awt.event.MouseEvent evt)

{

jButton6.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));

}

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt)

{

dispose();

}

Simmya at 2007-7-9 6:25:35 > top of Java-index,Java Essentials,New To Java...
# 2
Thankyou for replying.But this method doesnt work?
maggiemaggiea at 2007-7-9 6:25:35 > top of Java-index,Java Essentials,New To Java...
# 3

And also replace

jButton6.setText("Exit");

with this

jButton6.setText("Exit");

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

{

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

{

jButton6ActionPerformed(evt);

}

});

jButton6.addMouseMotionListener(new java.awt.event.MouseMotionAdapter()

{

public void mouseMoved(java.awt.event.MouseEvent evt)

{

jButton6MouseMoved(evt);

}

});

Simmya at 2007-7-9 6:25:35 > top of Java-index,Java Essentials,New To Java...