• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Button Action using netbeans

 
v kishore
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Darryl. And you dont get to learn much once you use a designer tool.
 
v kishore
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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





 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic