Home arrow Java arrow Page 4 - Creating Control Buttons with NetBeans IDE
JAVA

Creating Control Buttons with NetBeans IDE


This article focuses on programming with the ToggleButtons, CheckBoxes and RadioButtons of JFC in Java using NetBeans IDE.

Author Info:
By: Jagadish Chaterjee
Rating: 4 stars4 stars4 stars4 stars4 stars / 17
May 17, 2006
TABLE OF CONTENTS:
  1. · Creating Control Buttons with NetBeans IDE
  2. · The nucleus of JToggleButton
  3. · Working with JCheckBox
  4. · The nucleus of JCheckBox
  5. · Working with JRadioButton

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Creating Control Buttons with NetBeans IDE - The nucleus of JCheckBox
(Page 4 of 5 )

This is the continuation of the previous section. Further proceeding we have the following:

  private void btnShowActionPerformed(java.awt.event.ActionEvent
evt) {
   
// TODO add your handling code here:
     
repaintTextBox();
 
}

The above code is the heart of our application. According to the code in the previous section, you can understand that when the button is hit, the JRE tries to execute "btnShowActionPerformed." The implementation for that method is as above. According to the above code, the event would simply execute another method, "repaintTextBox."

"repaintTextBox" is my own method, which is defined below:

  private void repaintTextBox() {
    int style=0;
    if (this.chkBold.isSelected()) {
      style += java.awt.Font.BOLD;
    }
    if (this.chkItalic.isSelected()) {
      style += java.awt.Font.ITALIC;
    }
    this.txtMsg.setFont(this.txtMsg.getFont().deriveFont(style));
  }

The above would simply test which check box is switched on (by using "isSelected") and apply the respective font style (bold or italic). This is very similar to what happened when we used the toggle buttons. The only issue is that the changes would not come about unless the "show" button is hit (unlike the previous example, in which they were automatic).


blog comments powered by Disqus
JAVA ARTICLES

- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...
- Generics and Limitations in Java
- Getting Started with Java Web Development in...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials