• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to make a variable public?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am brand new to coding and I am having trouble making a variable public. The project I am working on is one that takes a users radio button input and writes it into an excel document. So far, the radio button selection and the excel writer work fine independently. However, I can't seem to figure out how to get the excel code to read the radio button selection. I imagine I must make the text field (tfld2) public, so that the excel class can identify which button was selected and write that to excel. Below in bold is my crappy attempt at trying to make the variable public (lines 43-45). Below that is the code writes to excel. The code only manages to write "tfld2" as a string, and "1234" as a string in excel cells 0,0 and 0,1, respectively (lines 17 and 21).



 
Ranch Hand
Posts: 146
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also posted at: http://forums.codeguru.com/showthread.php?558391-Help-connecting-jFrame-button-to-excel
 
Kevin Smitherson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kevin,
It's fine to post in two places. We just ask you mention this so neither site wastes time answering a question that's been answered. That's what Norman did (with less words).

Anyway, back to your question. The main() method doesn't reference NewJFrame in any way. Nor does the NewJFrameClass reference WriteExcel. So the first step is to instantiate the frame before worrying about the variables.
 
Kevin Smitherson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to do what I am doing? I'm a little confused why I am not receiving any constructive replies.
 
Kevin Smitherson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jeane,

Thank you for your reply! However, I am not sure what that means. Could you elaborate?
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kevin,
Take a look at this example of creating a JFrame. Something like that needs to be in your main() method. That will cause it to create the frame. You need that before you worry about reading the variables.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kevin Smitherson wrote:Is it possible to do what I am doing? I'm a little confused why I am not receiving any constructive replies.


Yes it is possible. You posted two hours ago on a Friday night US time. Not that many people saw it yet!
 
Kevin Smitherson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne,

I am confused, as I already have a jFrame. The first block of code can produce a jFrame with 3 radio buttons that, when clicked, create text into the textfield.

I am using netbeans, so I am able to create the GUI without having to manually enter the code listed on that website.
 
Kevin Smitherson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:

Kevin Smitherson wrote:Is it possible to do what I am doing? I'm a little confused why I am not receiving any constructive replies.


Yes it is possible. You posted two hours ago on a Friday night US time. Not that many people saw it yet!



I have had this posted on other sites since Tuesday =P .
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kevin Smitherson wrote:. . . having trouble making a variable public.  . . .

But why? That is usually regarded as incorrect design.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also I see you are new, so

Welcome to the Ranch
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kevin Smitherson wrote:

Jeanne Boyarsky wrote:

Kevin Smitherson wrote:Is it possible to do what I am doing? I'm a little confused why I am not receiving any constructive replies.


Yes it is possible. You posted two hours ago on a Friday night US time. Not that many people saw it yet!



I have had this posted on other sites since Tuesday =P .


Well, I'm talking about this site .

IN any case, try creating the JFrame in my link. Then you can try adding a getter method and get the variable value from the main class.
 
Kevin Smitherson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Campbell,

Thank you for your reply! Let's just say, I am so new, I don't even know WHY this is wrong. This is why I am coming for help =D .

My intention to make it public is so that my second block of code can detect that there was a text field created in the NewjFrame. So far, I have successfully created a program that allows the user to select a radio button, and have that selection be placed in the textfield as a string. I thought that making this textfield public would allow the code that writes to excel to pick it up, and write it to an excel file on my desktop.

As I have said, both of these apps function fine on their own, but I need them to be able to communicate between each other.

Please let me know if this makes sense.
 
Kevin Smitherson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here, I have added a visual to what I have made so far =) .

I appreciate everyone's help.
Untitled.jpg
[Thumbnail for Untitled.jpg]
NewJFrame Code
1.jpg
[Thumbnail for 1.jpg]
Excel Code
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code is difficult to read, so please post it as text.
 
Kevin Smitherson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell,

The full code is posted in my original post. I just wanted to provide a picture to show what my Gui looked like.
 
Kevin Smitherson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like the excel file to spit out the radio button selection rather than "Stringstringstring".
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The most common way to do this would be to put a button on the GUI labeled "Post to Excel" or something, listen for an onAction event, and then pass the text to the Excel-writing program.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic