Results 1 to 4 of 4
Thread: show a array in a window
- 01-03-2013, 03:34 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 5
- Rep Power
- 0
show a array in a window
hi,
I have a problem. I have this class Vettore
and "n" is a array , n is a instace of VettoreJava 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(); } }
the program is ok, but when I need of to print the array "v_nomi" in a window I can notJava 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() ; } }
can you help me? thanksJava 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); } }
- 01-03-2013, 03:49 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
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)
- 01-03-2013, 05:25 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 5
- Rep Power
- 0
Re: show a array in a window
how can I do?can you show me?please
- 01-03-2013, 05:42 PM #4
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
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
-
Can't seem to get my array table to show up :(
By juxta in forum New To JavaReplies: 2Last Post: 12-13-2011, 02:34 AM -
problems with program - cards show up only when I minimize/resize window
By AlphaScorpii in forum AWT / SwingReplies: 10Last Post: 07-03-2011, 01:07 PM -
Window needs to be re-sized to show components?
By mbutler755 in forum AWT / SwingReplies: 2Last Post: 10-09-2010, 01:18 AM -
How to show new window after click on button
By javahoush in forum SWT / JFaceReplies: 4Last Post: 12-29-2009, 09:25 AM -
How do i show all the values in one window(JOptionPane)??
By Antonioj1015 in forum Advanced JavaReplies: 1Last Post: 11-25-2009, 04:17 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks