Home arrow Java arrow Page 2 - 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 JToggleButton
(Page 2 of 5 )

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

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

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

The above code is the main heart of our application. According to the code in the previous section, you can understand that when the toggle buttons are hit the JRE tries to execute either "tbtnBoldActionPerformed" or "tbtnItalicActionPerformed" (based on the button hit). The implementations for both of those methods are as above. According to the above code, any of those events would simply execute another method, "repaintTextBox."

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

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

The above would simply test which toggle button is switched on (by using "isSelected") and apply the respective font style (bold or italic).


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 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials