aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Button Action using netbeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Button Action using netbeans" Watch "Button Action using netbeans" New topic
Author

Button Action using netbeans

v kishore
Greenhorn

Joined: Oct 23, 2010
Posts: 11
Hi Forum,
I am new to swing , netbeans . using netbeans ui components i set the button and text filed on the panel , set the button text to click ,

my intention is when i click on that button using mouse it have to show message " hai" in the text field . a simple example for my understand .

here i don't understand how can perform this action .

on the button while using the event action perform in the code it show the
following function.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextField1.setText("hai");
}

to show the hai message in the textfield i add jTextField1.setText("hai"); as shown,

but while check this using preview design there no action takes places .

so please help me how can i perform this action using netbeans ui and action perform in code


below i am pasting the code generated by netbeans through ui.

thanks in advance




public class NewJPanel extends javax.swing.JPanel {

/** Creates new form NewJPanel */
public NewJPanel() {
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 ">
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();

jTextField1.setText("jTextField1");

jButton1.setText("click");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(34, 34, 34)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jButton1))
.addContainerGap(248, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(16, 16, 16)
.addComponent(jButton1)
.addContainerGap(241, Short.MAX_VALUE))
);
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextField1.setText("hai");
}


// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JTextField jTextField1;
// End of variables declaration

}










Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

Dump the NetBeans visual designer. It may look like a beginners' tool, but it isn't.

http://download.oracle.com/javase/tutorial/uiswing/index.html
http://download.oracle.com/javase/tutorial/uiswing/components/button.html
http://download.oracle.com/javase/tutorial/uiswing/events/actionlistener.html


luck, db
There are no new questions, but there may be new answers.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3054
    
  33

Agree with Darryl. And you dont get to learn much once you use a designer tool.


Mohamed Sanaulla | My Blog
v kishore
Greenhorn

Joined: Oct 23, 2010
Posts: 11
Hi thanks for your replies and suggestions,
i designed it , here the problem appears only when i extend from jpanel if i use jframe i get the desired output .

i am able to run the code but see the out put only when i my class extend from jframe instead of jpanel .can you suggest why it happen .


thanks





 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Button Action using netbeans
 
Similar Threads
Reading RS232 and displaying contents on Frame
Insert an image in JScrollPane
Retriving jTextfield value from an other java file
Problem With GUI of Net Beans
Pressing a button to open a new window