GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Unable to output ResultSet into JTextArea in separate class/file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unable to output ResultSet into JTextArea in separate class/file." Watch "Unable to output ResultSet into JTextArea in separate class/file." New topic
Author

Unable to output ResultSet into JTextArea in separate class/file.

marsha bianco
Greenhorn

Joined: Aug 30, 2010
Posts: 4
all the other classes don't have a main method, so the only one is the GUI class. The re-declaration of the gui instance is to be able to call from gui class: gui.outputArea.append(); I have researched static and non-static, and still do not understand it. If you are trying to call anything in a {} block at att, its static and I can't call it. Even if I declare it as public in beginning, once you enter a block, no go... I as using the parsing as a means of taking input from the gui and placing it into variable

private void addMenuActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { int sID = Integer.parseInt(studentIDBox.getText()); float sGpa = Float.parseFloat(gpaBox.getText()); String fName = fNameBox.getText(); String lName = lNameBox.getText(); String sMentor = mentorBox.getText(); String sStatus = statusBox.getText(); String sLevel = levelBox.getText(); String sThesisTitle = thesisTitleBox.getText(); String sThesisAdvisor = thesisAdvisorBox.getText(); String sCompany = companyBox.getText(); Undergraduate undergrad = new Undergraduate(sID, fName, lName, sGpa, sStatus, sMentor, sLevel); Graduate grad = new Graduate(sID, fName, lName, sGpa, sStatus, sMentor, sThesisTitle, sThesisAdvisor); PartTime pTime = new PartTime(sID, fName, lName, sGpa, sStatus, sMentor, sCompany); if (sThesisTitle == null && sThesisAdvisor == null && sCompany == null) { undergrad.add(); } if (levelBox == null && companyBox == null) { grad.add(); } if (levelBox == null && thesisTitleBox == null && thesisAdvisorBox == null) { pTime.add(); } outputArea.append("\nStudent " + sID + " has been added"); } catch (Exception e) { } }
I didn't know it needed to be done any differently when I used a result set. Here is what I am dealing with, and I am unable to design it better because its the requirements of a school task. I am only finally asking for help now because my mentor said I could receive error corrections. Anyway, setup is this: not actual code.

Class 1: abstract class student (6 params)

Class 2: class Undergraduate (same 6, 1 new)

Class 3: class Graduate (first 6, 2 different new)

Class 4: class PartTime (first 6, 1 different new):

Class 5: class GUI (init components)

So the data is inputted from the GUI, then goes to student for validation and construction of first 6, then goes to one of the other three depending upon what additional data is given. From there it goes through its method: add, update, query, delete and executes action in database through mysql. Then user is either notified action is completed, or for query, I need the result to be outputted to the text area "outputArea" in GUI. This is quite confusing and complicated for a beginning Java programmer.
So anyway, there are no main methods in any class but GUI. I am working on query action. I am getting output to command window. It's not right because of no iteration, but at least its there. I get nothing to the text area. whatcha got now, and thank you very much for your earlier help and speedy reply.

>>Now I iterated and have correct output to command line, but cannot output to JTextArea in GUI class.
marsha bianco
Greenhorn

Joined: Aug 30, 2010
Posts: 4
I have iterated resultset, and changed code so parsing occurs in Student class instead. Now I cannot input null float value even though table allows. I must type a "0" in the GUI. I still cannot output to textarea in GUI class.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
I'm sorry, probably it's me, but I'm having a tough time finding an answerable question in this large post. Can you greatly simplify and clarify your question -- give us its essence in a few sentences? And also you may wish to consider creating a small compilable program that compiles, runs (if possible) and demonstrates your problem in a nutshell. This process is called creating an SSCCE, and to learn how to do this well (which will likely speed up your chances of getting a reply that is actually helpful), please look here: SSCCE

Much luck in solving your problems!
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1669
    
  11

Duplicate, locked thread here for future reference: http://www.coderanch.com/t/510583/java/java/do-output-results-resultset-text


When you do things right, people won't be sure you've done anything at all.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1669
    
  11

I did probably an identical or a painfully similar assignment as this in school. What, exactly, is the issue? Passing the information between classes?

Do you REALLY know what the difference is between static and non-static, as Campbell asked in your other thread?

I think the GUI is convoluting your problems.... and if you're going to WGU, they also recommend using an IDE.... I found this a distraction in figuring out what the issues are. I used notepad++ for all my assignments and got perfect scores.

Are you getting compile errors? What are they? What do you think they mean?
If you aren't getting compile errors, have you tried doing a System.out.println() to see if the data is going anywhere?

Are you trying to write the whole thing at once? I had massive issues trying to bite off more than I could chew. I ended up working on one class at a time, then one method at a time.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1669
    
  11

Oh, and right now, you're creating a Part Time, a Graduate, and an Undergrad Student, regardless of what the user inputs. The instantiation should be INSIDE the if statements.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
Janeice DelVecchio wrote: . . . Do you REALLY know what the difference is between static and non-static, as Campbell asked in your other thread?
I would repeat what I said; until you understand that distinction, you will have no end of difficulties.
Janeice DelVecchio wrote: . . .
Are you trying to write the whole thing at once? . . .
Janeice is right in everything she said. Trying to compile a whole class in one stage may be
trying to bite off more than I could [you can] chew.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1669
    
  11

marsha bianco wrote: I have researched static and non-static, and still do not understand it.


Ahh.... I reread your post and I'm seeing now that this is probably the cause of the issue here.

So we can get on the same page, check out this: http://download.oracle.com/javase/tutorial/java/javaOO/classvars.html

I'll wait.....


.....


.... ok. So the declaration static means that it happens once per class, regardless of how many instantiations you have. A simple use of this could be a class variable that keeps track of how many classes have been instantiated. Instance variables and methods are useful to work on data for that instance of the class.



So you're having trouble sending information to a class (static) method? How are you performing the method call... i.e. what syntax are you using? How about posting the method that's supposed to be doing the work, and isn't?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
If you have a method which does not take or query any information from any of the objects of that class.
If that same method does not write record manipulate or alter any information in any of the objects of that class . . .

Then it is probably worth marking that method static.
*******************************************************************
If you need access to a method when you know the class name, but might not have any objects of that class yet, you will have to mark it static. Then it cannot access any instance (non-static) members of any of the objects.

Instance members: called on the object name. If they are fields: one per object, and they may have different values or states.

You already know static methods are not allowed to call instance methods or instance fields, but any instance field can call a static method or field. And any static field they call is the same static field for all instances.

You can't use the keywords this and super in a static context.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to output ResultSet into JTextArea in separate class/file.