Results 1 to 7 of 7
Thread: print an array into a window
- 01-31-2013, 01:33 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 5
- Rep Power
- 0
print an array into a window
hi!
I want to print a array into a window. I have the class for a select on my database:
then I have a class for the windowJava Code:package query; import java.util.Iterator; import java.util.Vector; import connessione.DbConnection; public class SelectProva { String query="SELECT * FROM persona"; Vector<String[]> res=DbConnection.getInstance().eseguiQuery(query); public String StampaVettore(){ Iterator<String[]> i=res.iterator(); while(i.hasNext()) { String[] riga=i.next(); for(int j=0;j<riga.length;j++) System.out.print(riga[j]+" "); System.out.println(); return riga[j]; } } }
and last class for the mainJava Code:package interfaccia; import javax.swing.*; import java.awt.*; public class Finestra { private String intestazione; private String corpo; public String getIntestazione() { return intestazione; } public void setIntestazione(String intestazione) { this.intestazione = intestazione; } public String getCorpo() { return corpo; } public void setCorpo(String corpo) { this.corpo = corpo; } public void finestrella(){ JFrame win; win = new JFrame(intestazione); Container c = win.getContentPane(); c.add(new JLabel(corpo)); win.setSize(200,200); win.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); win.setVisible(true); } }
I would like to replace the "Corpo" with the array printed. Please, you correct the code, only for once for example. ThanksJava Code:package main; import interfaccia.Finestra; import query.SelectProva; public class Logica { public static void main(String[] args) { Finestra terza = new Finestra (); terza.setIntestazione("new intestazione"); terza.setCorpo("Corpo"); } }
- 01-31-2013, 02:17 PM #2
Re: print an array into a window
I'm not really sure what your question is. What does this code do? Does it work? Which part of this is giving you trouble? For example, if the database stuff is working fine, then you can get rid of that for the sake of asking the question. Is your question how to display a collection of Strings on a JFrame?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-31-2013, 11:13 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 5
- Rep Power
- 0
Re: print an array into a window
yes. the first class (the select is ok, if I delete the line n.24( I did a test), I have the array into the console, therefore it's ok), my problem is that I can't print this array on a JFrame
- 02-01-2013, 09:36 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: print an array into a window
What do you see then?
What do you need to see?
I notice you are not even trying to display that String at the moment.
Nothing is calling your db code (which, by the way, is returning a single String and not an array).Please do not ask for code as refusal often offends.
- 02-01-2013, 10:25 AM #5
Member
- Join Date
- Jan 2013
- Posts
- 5
- Rep Power
- 0
Re: print an array into a window
I want to see the array into the window, but now I have a error into class "SelectProva" line 24 "return riga[j]" eclipse underline "j", and I know that the class "Finestra" not is ok because there is to need of a "for" of the JLabel because the program works, but I practically can not.
- 02-01-2013, 10:50 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: print an array into a window
Well don't you think it would be an ideas to actually tell us which bits have errors?
We are not going to put this in an IDE and compile it to find out your problems.
That error is because 'j' is out of scope.
Since we have no idea what your requirements are for this method I can't offer a solution.
And since it's the output of this that needs to be displayed in the JFrame then I think you need to explain exactly what it is that this database code is supposed to be returning.Please do not ask for code as refusal often offends.
- 02-01-2013, 03:20 PM #7
Re: print an array into a window
Recommended reading: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
show a array in a window
By vide91 in forum Advanced JavaReplies: 3Last Post: 01-03-2013, 05:42 PM -
Issue with printing a 2d array in a new window
By rick2993 in forum New To JavaReplies: 2Last Post: 12-20-2012, 11:02 PM -
two dimensional array print
By Myles in forum New To JavaReplies: 0Last Post: 04-26-2010, 11:10 AM -
ArrayLists do not print to the terminal window, why? long code inside
By caps_lock in forum New To JavaReplies: 5Last Post: 05-25-2009, 09:03 PM -
main window & print dialog
By roo7 in forum Advanced JavaReplies: 3Last Post: 01-02-2008, 06:50 AM


LinkBack URL
About LinkBacks

Bookmarks