Results 1 to 7 of 7
  1. #1
    vide91 is offline Member
    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Default 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:

    Java 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];		
    				
    		}
    	}
    }
    then I have a class for the window

    Java 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);
    	}
    }
    and last class for the main

    Java 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");
    	
    
    	}
    	
    }
    I would like to replace the "Corpo" with the array printed. Please, you correct the code, only for once for example. Thanks

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,958
    Rep Power
    8

    Default 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!

  3. #3
    vide91 is offline Member
    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Default 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

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default 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.

    ** This space for rent **

  5. #5
    vide91 is offline Member
    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Default 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.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default 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.

    ** This space for rent **

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,958
    Rep Power
    8

    Default Re: print an array into a window

    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

  1. show a array in a window
    By vide91 in forum Advanced Java
    Replies: 3
    Last Post: 01-03-2013, 05:42 PM
  2. Issue with printing a 2d array in a new window
    By rick2993 in forum New To Java
    Replies: 2
    Last Post: 12-20-2012, 11:02 PM
  3. two dimensional array print
    By Myles in forum New To Java
    Replies: 0
    Last Post: 04-26-2010, 11:10 AM
  4. Replies: 5
    Last Post: 05-25-2009, 09:03 PM
  5. main window & print dialog
    By roo7 in forum Advanced Java
    Replies: 3
    Last Post: 01-02-2008, 06:50 AM

Posting Permissions

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