CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2017
    Posts
    2

    Help connecting jFrame button to excel

    I am new to coding and I am trying to figure out how to write a radio button selection to an excel file. So far I am able to create an excel file with the string that I wrote myself, but I am having trouble with the logic that connects the jFrame radio button to the excel file.

    Essentially, my code allows a user to select a radio button. The radio button text gets printed in a text field. The user can click the close button and the jFrame closes itself. I would like to achieve having the radio button selection stored in an excel file after it is selected. Currently, I see no errors in running individually, I'm just not sure how to connect the two together.

    Code:
    package javaapplication6;
    import javax.swing.ButtonGroup;
    
    
    public class NewJFrame1 extends javax.swing.JFrame {
    
       
        public NewJFrame1() {
            initComponents();
            btngp1();
        }
    
    private void btngp1() {
            ButtonGroup bg1 = new ButtonGroup();
        
            bg1.add(rbtn1);
            bg1.add(rbtn2);
            bg1.add(rbtn3);       
    }
        
        private void rbtn1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
            tfld1.setText("1");
        }                                     
    
        private void rbtn2ActionPerformed(java.awt.event.ActionEvent evt) {                                      
            tfld1.setText("2");
        }                                     
    
        private void rbtn3ActionPerformed(java.awt.event.ActionEvent evt) {                                      
            tfld1.setText("3");
        }                                     
    
        private void closebtnActionPerformed(java.awt.event.ActionEvent evt) {                                         
            this.dispose();
    
    public static void main(String args[])
    
      // Variables declaration - do not modify                     
        private javax.swing.ButtonGroup btngp1;
        private javax.swing.JButton closebtn;
        private javax.swing.JRadioButton rbtn1;
        private javax.swing.JRadioButton rbtn2;
        private javax.swing.JRadioButton rbtn3;
        private javax.swing.JTextField tfld1;
        // End of variables declaration                   
    }
    Code:
    package Writer;
    
    import java.io.File;
    import java.io.IOException;
    import jxl.*;
    import jxl.write.*;
    import jxl.write.Number;
    class writeExcel 
    {
        public static void main(String args[]) throws IOException, WriteException
        {
        try {
            String fileName = "C:\\Users\\kevin\\Desktop\\Project.xls";
            WritableWorkbook workbook = Workbook.createWorkbook(new File(fileName));
            WritableSheet sheet = workbook.createSheet("Sheet1", 0);
            
            Label label = new Label(0,0, btngp1);
            sheet.addCell(btngp1);
            
       
            workbook.write();
            workbook.close();
        } catch (WriteException e) {
     
        }}}

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,875

    Re: Help connecting jFrame button to excel

    Is there a website for users of the jxl packages? I've never seen that package.

    Where is the code that adds the listeners to the buttons?

    If you are getting compiler errors, you need to copy the full text of the error messages and paste it here.
    Norm

  3. #3
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,875

    Re: Help connecting jFrame button to excel

    Norm

  4. #4
    Join Date
    Jan 2017
    Posts
    2

    Re: Help connecting jFrame button to excel

    Yes, it has been posted elsewhere, that was me. However, I am in still in need of a reply. Would you be able to help?

    This is the video I used to code this: https://www.youtube.com/watch?v=A9866lBdmKo

    I am not getting a compiling error. I know that this code is wrong, I'm not sure what to do to make it correct. The question you referred to on code ranch is more concise. I feel that what I am trying to do may not be possible since I am not receiving any replies.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured