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

    Default show a array in a window

    hi,
    I have a problem. I have this class Vettore

    Java Code:
    package elementiBase ;
    
    
    public class Vettore {
    	
    	private String [] v_nomi;
    
    	public String [] getV_nomi() {
    		return v_nomi;
    	}
    
    	public void setV_nomi(String [] v_nomi) {
    		this.v_nomi = v_nomi;
    	
    	}
    	
    	
    	
    	public String getStampa() {
    		int i =0;
    		   StringBuilder sb = new StringBuilder();
    		   for (i=0; i<3; i++){
    		      sb.append( v_nomi[i] );
    		   }
    		   return sb.toString();
    		}
    	
    	
    }
    and "n" is a array , n is a instace of Vettore

    Java Code:
    package Test;
    
    import elementiBase.Vettore;
    
    public class StampaVettore {
    
    
    	public static void main(String[] args) {
    			
    			Vettore n = new Vettore();
    			n.setV_nomi(new String[]{"anna","luca","corrado"});
    			n.getStampa() ;
    	}
    }
    the program is ok, but when I need of to print the array "v_nomi" in a window I can not
    Java Code:
    package Grafica;
    
    import Test.StampaVettore;
    import elementiBase.Vettore;
    import javax.swing.*;   
    import java.awt.*;
    
    public class FinestraStampaVettore {
    
    		public static void main(String args[])
    		{
    		JFrame win;
    		win = new JFrame("Questa  l'intestazione della finestra");
    		
    		Container c = win.getContentPane();
    		c.add(new JLabel(n.getStampa()));   //the error
    		
    		win.setSize(200,200);         
    		win.setDefaultCloseOperation
    		(JFrame.EXIT_ON_CLOSE);      
    		win.setVisible(true);
    		}
    	}
    can you help me? thanks

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: show a array in a window

    Why do you have two main methods? In your second class/method there is no Vettore instance (n doesn`t exist)

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

    Default Re: show a array in a window

    how can I do?can you show me?please

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: show a array in a window

    Simplest solution: Copy the lines 10 to 11 from the main method out from the StampaVettore class and paste these lines to your other main method in class FinestraStampaVettore (e.g. after line 11).

    Better solution for the future: Model View Controller is a keyword for you.

Similar Threads

  1. Can't seem to get my array table to show up :(
    By juxta in forum New To Java
    Replies: 2
    Last Post: 12-13-2011, 02:34 AM
  2. Replies: 10
    Last Post: 07-03-2011, 01:07 PM
  3. Window needs to be re-sized to show components?
    By mbutler755 in forum AWT / Swing
    Replies: 2
    Last Post: 10-09-2010, 01:18 AM
  4. How to show new window after click on button
    By javahoush in forum SWT / JFace
    Replies: 4
    Last Post: 12-29-2009, 09:25 AM
  5. How do i show all the values in one window(JOptionPane)??
    By Antonioj1015 in forum Advanced Java
    Replies: 1
    Last Post: 11-25-2009, 04:17 PM

Posting Permissions

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