Need help assigning values to an array of Strings

why do i get an error message saying this isn't a statement?
String customer[z] = {"::" + s1 + ":" + s2 + ":" + s3};
what is the correct syntax for assigning values to an array of strings?

help helpArrays in Java are static, meaning their size cannot change once they've been created. Somewhere in your code you need to declare the String array like this,
String[] costumer = new String[10];Now customer has 10 elements (room for 10 strings) and you can do for example this,
int z = 0;
costumer[z] = "string1" + "string2";This means the two strings are added and assigned to element 0 of the array.
If you can't take it from here you need to step back for a while and carefully study a beginners textbook on Java.

Similar Messages

  • How to assign values for boolean array in LabVIEW?

    I want assign values for boolean array.Iam not able to do that.For each boolen i want to assign each value.Plz help me......
    Please Mark the solution as accepted if your problem is solved and donate kudoes
    Solved!
    Go to Solution.

    Hi agar,
    values in an array are "assigned" by building an array (using BuildArray) or by replacing values in an existing array (ReplaceArraySubset)!
    Good starting point could be this...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Assign values from one array to another

    Hi, I am trying to solve a problem that asks that I assign values in the array that is input, which meet a certain criteria, into another array. isFunny will determine if a given integer is funny, countFunnies will determine how many integers in the given array are funny or not. collectFunnies should assign elements from the first array that are funny into the new array. Please take a look at the code, I am at a loss, everything looks good to me.
    public class BatchOne
    public boolean isFunny(int x) {
    if (x%2 == 0) {return true;}
    else {return false;}
    public int countFunnies(int[] a) {
    int count = 0;
    for (int funCheck :a) {
    if(isFunny(funCheck)) {
    count++;
    return count;
    public int[] collectFunnies(int[] a) {
    int count = 0;
    int i = 0;
    for (int funCheck :a) {
    if(isFunny(funCheck)) {
    count++;
    int[] array = new int[count];
    for (int funCheck : a) {
    if(isFunny(funCheck)) {
    array[i] = funCheck;
    i++;
    return array;
    Thanks,
    T

    Ok, I am new to programming and posting so likely need some refinement to my posts.
    I am using BlueJ to write my code, the above posted is my entire code. It is compiling correctly but when I run, the return was giving me back something strange, I am not sure if I can post a screenshot because it would be hard to explain.
    However, upon further review, it seems that there are some intricacies with BlueJ that I am obviously not used to, because when I select to inspect the return, the program seems to be returning an array of values that is in line with my intended goal.
    Thank you for your guidance in terms of how to use the forums.
    T

  • Need to store values in an array from a file

    My input file is a series of float numbers in a single line. I need to copy these values and store them in an array. Likewise i need to write these files stored in the array to a new file. can someone help me with the code.
    My data is something like this.
    0.000000000000000E+00 -9.983341664682815E-02 -1.986693307950612E-01 -2.955202066613396E-01 -3.894183423086505E-01 -4.794255386042030E-01 -5.646424733950355E-01 -6.442176872376911E-01 -7.173560908995228E-01 -7.833269096274834E-01 -8.414709848078965E-01 -8.912073600614354E-01 -9.320390859672264E-01 -9.635581854171930E-01 -9.854497299884603E-01 -9.974949866040544E-01 -9.995736030415051E-01 -9.916648104524686E-01 -9.738476308781951E-01 -9.463000876874145E-01 -9.092974268256817E-01 -8.632093666488737E-01 -8.084964038195901E-01 -7.457052121767200E-01 -6.754631805511506E-01 -5.984721441039565E-01 -5.155013718214642E-01 -4.273798802338298E-01 -3.349881501559047E-01 -2.392493292139820E-01 -1.411200080598672E-01 -4.158066243329049E-02 5.837414342758009E-02 1.577456941432487E-01 2.555411020268317E-01 3.507832276896198E-01 4.425204432948525E-01 5.298361409084934E-01 6.118578909427193E-01 6.877661591839741E-01 7.568024953079282E-01 8.182771110644108E-01 8.715757724135882E-01 9.161659367494549E-01 9.516020738895160E-01 9.775301176650970E-01 9.936910036334645E-01 9.999232575641008E-01 9.961646088358406E-01 9.824526126243325E-01 9.589242746631385E-01 9.258146823277321E-01 8.834546557201531E-01 8.322674422239008E-01 7.727644875559871E-01 7.055403255703919E-01 6.312666378723208E-01 5.506855425976376E-01 4.646021794137566E-01 3.738766648302360E-01 2.794154981989259E-01 1.821625042720950E-01 8.308940281749640E-02

    ram.west wrote:
    hi,
    i tried using string tokenizer, but i need to pass the values as float values to the array..The recommendation for StringTokenizer was a mistake. You could use split instead. Or a Scanner.
    At any rate so you have some Strings. Which you want to turn into floats.
    If only Java had a class, I don't know, let's call it java.lang.Float, and if only such a class existed wouldn't it be just brilliant if it had some sort of method that could parse a float primitive out of a given String?
    I mean wouldn't that be just amazing ?

  • Problem in assigning value to an array element

    hi all
    in the following prog i am not able to assign the value to the array element
    i am not getting why it is giving me error
    //my program is as follows
    public class ArrayTest
         static int [] intArray = new int[5];
         static int [] intArray1 = new int[1];
         intArray1[0] = 5; // this line gives error
         static char [] charArray = new char[5];
         public static void main(String args[])
              System.out.println(charArray);
              intArray1 = intArray;
    }thanx in advance as usual

    The problem is that you try to execute code outside a method. This can be only done in form of a variable declaration or as a static initilization block which will be executed once when the class is loaded:public class ArrayTest
         static int [] intArray = new int[5];
         static int [] intArray1 = new int[1];
         static char [] charArray = new char[5];
         static {
              intArray[0] = 5;
         public static void main(String args[])
              System.out.println(charArray);
              intArray1 = intArray;
    }

  • Get numerical values from 2D array of string

    Hello! 
    I start by saying that I have a base knowledge of LabView. I'm using LabView 2011. I'm doing some communications test via Can-Bus protocol. As you can see in pictures of the block diagram and of the front panel that I've attached I'm using "Transmit Receive same Port" LabView example. It works very good but I would need to insert the 8 data bytes that I receive from the server in 8 different numerical variables so that I could use them to make some operations. How can I get numerical values from the 2D array of string that I attached? 
    Every example that you can provide is important! 
    Thank you very much! 
    Attachments:
    1.jpg ‏69 KB
    2.jpg ‏149 KB

    Hi martiflix,
    ehm: to unbundle data from a cluster I would use the function Unbundle(ByName)…
    When you are new to LabVIEW you should take all the FREE online resources offered by NI on their website!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Need help assigning 2 values to each choice in a drop down

    I'm trying to create a tool for tracking students' grades and credits.  There is a drop down menu with A - F as choices, and I assigned export values 4,3,2,1,0.  I can then get weighted average by using the simple average calculation in a text field box somewhere else on the page. 
    What I want to do is also assign grades A-D a value of .5 so that we can keep track of how many credits a student has.  Then all I will need is to find the sum in another box. 
    How do I pull this off?  Thank you for your help.

    You have to use unique values in a drop down, combo, or list box.
    You could sort this out based on the selection made within a JavaScript like a keystroke, on blur action, or in a calculation.

  • Need help with persistance using an array of values

    I have an array of values, say:
    String[] fruit = {apples, oranges, pears}
    And I want to know how to send this into a database table that is separate from the rest of the class. for example, the fruit array is part of a class Food. Food has the following fields:
    @Column(Name= food_type)
    private String foodType;
    String[] fruit
    Say that the Food class places the foodType variable in the Food table, but I want to place each item of the fruit array into a separate table that has the fruit type, and Food_id that links it back to the food table.
    What is the correct code for this?

    jobocop17 wrote:
    I have an array of values, say:
    String[] fruit = {apples, oranges, pears}that won't compile without quotes around the strings
    And I want to know how to send this into a database table that is separate from the rest of the class. there are a number of ways to do this
    i recommend you start with JDBC
    for example, the fruit array is part of a class Food. Food has the following fields:
    @Column(Name= food_type)
    private String foodType;
    String[] fruit
    Say that the Food class places the foodType variable in the Food table, but I want to place each item of the fruit array into a separate table that has the fruit type, and Food_id that links it back to the food table.
    What is the correct code for this?When you write the code and it does what you want, you will then know the answer to this question.

  • Need help assigning ringtone to contact

    I have followed all the instructions regarding assigning a ringtone to a contact, but when that individual calls, the phone uses the default ringtone. How do I get this to work?

    help helpArrays in Java are static, meaning their size cannot change once they've been created. Somewhere in your code you need to declare the String array like this,
    String[] costumer = new String[10];Now customer has 10 elements (room for 10 strings) and you can do for example this,
    int z = 0;
    costumer[z] = "string1" + "string2";This means the two strings are added and assigned to element 0 of the array.
    If you can't take it from here you need to step back for a while and carefully study a beginners textbook on Java.

  • Need help regarding Value Object Concept in flex/java

    I need to map the java objects to flex use value objects in flex.
    The problem is I have a class in java which is referring to another class and again that class referring another class.
    For instance
    Class A
         protected User user;
    Class User
         protected Address address;
    Now I need to map class A to the flex using value object concept and I have to display the user info in the grid as well.
    Need some help to get started.

    You need to set the "scope" property in your remoting destination definition to "session" or "application".

  • Need help getting information out of array and into text/object files

    Im having alot of trouble with this i have the classes for the array, text reader and writer, and object reader and writer mostly done. I originally had a getInfo method in my object and text classes to input the data needed, but that wasnt how the instructor wanted. So my question is how do i take the infomation in the array in class studentarray and send that information to the text and object classes? I have looked online for an example and cant seem to find one that looks like it would work. I am pretty sure what i need will be put in the class StudentArray
    here is requirements i havent figured out how to implement
    - read student records from a �text� file
    - write student records into a �text� file (new data after sorting)
    - read student records from an �object� file
    - write student records into an �object� file (new data after sorting)
    I have sorting methods below in StudentArray just didnt post them
    public class StudentArray {
    private static Scanner input = new Scanner(System.in);
    private static student sArray[] = new student[5];
    public static void insert() throws NegativeIDException
    for(int i = 0; i < 5; i++)
    System.out.println("Please enter firstname:");
    String Fname = input.next();
    System.out.println("Please enter lastname:");
    String Lname = input.next();
    System.out.println("Please enter id:");
    int Id = 0;
    try
    Id = input.nextInt();
    NegativeIDException nide = new NegativeIDException("No negative number for id.");
    if(Id < 0)
    throw nide;
    scanner.nextLine();
    System.out.println("you must enter a positive number try again");
    catch(InputMismatchException ime)
    System.err.printf("\nException: %s\n", ime);
    scanner.nextLine();
    System.out.println("you must enter an integer try again");
    System.out.println("Please enter year admitted:");
    int Admitted = 0;
    try
    Admitted = input.nextInt();
    NegativeIDException nide = new NegativeIDException("No negative number for id.");
    if(Admitted < 0)
    throw nide;
    scanner.nextLine();
    System.out.println("you must enter an integer try again");
    catch(InputMismatchException ime)
    System.err.printf("\nException: %s\n", ime);
    scanner.nextLine();
    System.out.println("you must enter an integer try again");
    System.out.println("Please enter Gpa:");
    double Gpa = input.nextDouble();
    int t = 0;
              int q = 0;
              System.out.println("Please select your track");
                   System.out.println("1 for doctoral student");
                   System.out.println("2 for graduate student");
                   System.out.println("3 for major student");
                   System.out.println("4 for minor student");
                   t = input.nextInt();
                   if (t == 1)
                             System.out.println( "Please select your doctoral topic");
                             System.out.println("1 for Video Games");     
                             System.out.println("2 for CPU History");     
                             System.out.println("3 for Other");     
                             int c = input.nextInt();                         
                             String diss = "";
                             if (c == 1)
                                  diss = "Video Games";     
                             else if (c == 2)
                                  diss = "CPU History";
                             else if (c == 3)
                                  diss = "Other";
                             sArray[i] = new CSDoctStudent(Fname, Lname, Id, Admitted, Gpa, diss);
                             q++;                              
                        else if (t == 2)
                        System.out.println( "Please enter the number for your graduate course");
                        System.out.println("1 for Software Engineering");     
                        System.out.println("2 for Theory");     
                        System.out.println("3 for Other");     
                        int b = input.nextInt();
                        String Theory = "";
                        if (b == 1)
                             Theory = "Software Engineering";     
                        else if (b == 2)
                             Theory = "Theory";
                        else if (b == 3)
                             Theory = "Other";
                        sArray[i] = new CsGradStudent(Fname, Lname, Id, Admitted, Gpa, Theory);
                   q++;     
                        else if (t == 3)
                             System.out.println( "Please enter the number for your major course");
                             System.out.println("1 for Hardware");     
                             System.out.println("2 for IS");     
                             System.out.println("3 for Theory");     
                             int m = input.nextInt();
                             String track = "";
                             if (m == 1)
                             track = "Hardware";
                        else if (m == 2)
                             track = "IS";
                        else if (m == 3)
                             track = "Theory";
                             sArray[i] = new CSMajorStudent(Fname, Lname, Id, Admitted, Gpa, track);
                             q++;     
                   else if ( t == 4)
                             System.out.println( "Please enter the number for your minor course");
                             System.out.println("1 for Computer Application");     
                             System.out.println("2 for Multimedia");     
                             System.out.println("3 for Web Technology");
                             int d = input.nextInt();
                             String Hardware = "";
                             if (d == 1)
                                  Hardware = "Computer Application";     
                             else if (d == 2)
                                  Hardware = "Multimedia";
                             else if (d == 3)
                                  Hardware = "Web Technology";
                             sArray[i] = new CSMinorStudent(Fname, Lname, Id, Admitted, Gpa, Hardware);
                             q++;     
                   else;
    sArray= new student(Fname,Lname,Id,Admitted, Gpa);
    //trying to write it to a text file with this
    import java.io.PrintWriter;
    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;
    public class TStream {
    private Scanner input = null;
    private PrintWriter output = null;
    private student [] sArray = new student[5];
    public TStream()
    public void write()
    try
    output = new PrintWriter("tdatabase.txt");
    for(int i = 0; i < 5; i++)
    output.print(sArray[i].getFname() + "\t");
    output.print(sArray[i].getLname() + "\t");
    output.print(sArray[i].getId() + "\t");
    output.print(sArray[i].getAdmitted() + "\t");
    output.print(sArray[i].getGpa() + "\t");
    output.println();
    output.close();
    catch(FileNotFoundException fnfe)
    System.err.printf("\nException: %s\n", fnfe);
    System.out.println("Can not open this file.\n");
    public void read()
    try
    input = new Scanner(new File("tdatabase.txt"));
    for(int i = 0; i < 5; i++)
    String Fname = input.next();
    String Lname = input.next();
    int Id = input.nextInt();
    int Admitted = input.nextInt();
    double Gpa = input.nextDouble();
    sArray[i] = new student(Fname,Lname,Id,Admitted,Gpa);
    input.close();
    catch(FileNotFoundException fnfe)
    System.err.printf("\nException: %s\n", fnfe);
    System.out.println("Can not open this file.\n");

    Use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • Need help assigning range for an integer for subtracting time.

    Ok, so I'm having a little trouble getting this program to work. :x Maybe somebody could give me some help on what to do next. I'm new to Java, and I'm trying to write a program using NetBeans 6.9.1, and I ran into a problem. I'm trying to write a program for a time traveler Marty, who is going back in time. The time is set on a 24 hour clock, so am and pm is not an issue.
    I have the program written, but I'm having trouble with the subtraction of the time. Whenever I do the subtract, and the time traveled back (either in hours, minutes or seconds), is bigger than the current time, I just end up with negative numbers. I don't know how to set the value so it will just recycle through the 24 hours, the 60 minutes, or 60 seconds, instead of giving me negative numbers. Any help would be greatly appreciated. Also, I'm not sure how to make the users input italic. Here is what I got so far.
    package timetravel;
    * @author Jeff
    import java.io.*;
    import java.util.*;
    public class Main {
    * @param args the command line arguments
    public static void main(String[] args) {
    int hours, minutes, seconds, hoursback, minutesback, secondsback;
    Scanner keyboard = new Scanner (System.in);
    System.out.println("Hi Marty!");
    System.out.println("Enter current hour:");
    hours = keyboard.nextInt();
    System.out.println("Enter current minute:");
    minutes = keyboard.nextInt();
    System.out.println("Enter current second:");
    seconds = keyboard.nextInt();
    System.out.println("Enter how many hours you want to travel back");
    hoursback = keyboard.nextInt();
    System.out.println("Enter how many minutes you want to travel back");
    minutesback = keyboard.nextInt();
    System.out.println("Enter how many seconds you want to travel back");
    secondsback = keyboard.nextInt();
    System.out.println("When you arrive, the local time will be " + (hours - hoursback)
    + " hours, " + (minutes - minutesback) + " minutes, and " + (seconds - secondsback)
    + " seconds.");

    Well, basically, here's how I want the program to run
    Example program run:
    Hi Marty!
    Enter current hour: 8
    Enter current minute: 12
    Enter current second: 11
    Enter how many hours you want to travel back: 9
    Enter how many minutes you want to travel back: 36
    Enter how many seconds you want to travel back: 39
    When you arrive, the local time will be: 22 hours, 35 minutes, and 32 seconds
    (program input is written in italic)
    instead of how it runs now
    Hi Marty!
    Enter current hour: 8
    Enter current minute: 12
    Enter current second: 11
    Enter how many hours you want to travel back: 9
    Enter how many minutes you want to travel back: 36
    Enter how many seconds you want to travel back: 39
    When you arrive, the local time will be: -1 hours, -24 minutes, and -28 seconds
    I want it to cycle through the 24 hour clock, so if I travel back in time from 18 (1800 or 6pm) and i want to travel back in time 20 hours, I should get 22 (2200 or 10 pm) instead of -2.
    Same with minutes and seconds, except for it to cycle through 60 instead of 24, since there are 60 minutes in an hour, and 60 seconds in a minute. Also, if the minutes end up being negative, I need it to take away one from the hour spot, and so on for the other ones. Hopefully I explained it well enough... Sorry, I'm new to Java.
    Edited by: halo2jak on Sep 7, 2010 12:24 AM

  • NEED HELP! passing an object array to a method

    Hi, i need to make a method called public Server[] getServers() and i need to be able to see if specific server is available for use.
    I have this so far:
    public abstract class AbstractServer
    protected String serverName;
    protected String serverLocation;
    public AbstractServer(String name,String location)
    this.serverName=name;
    this.serverLocation=location;
    public abstract class Server extends AbstractServer
    public Server(String name,String location)
    super(name,location);
    public class CreateServers
    Server server[];
    public CreateServers()
    public Server create()
    for(int i=0; i<10; i++)
    server=new Server(" ", " "); //i was going to fill in something here
    return server;
    OK NOW HERE IS THE PROBLEM
    i have another class that is supposed to manage all these servers, and i dont understand how to do the public Server[] getServers(), this is what i have tried so far
    public class ServerManager()
    public Server[] getServers(Server[] AbstractServer)
    Server server=null; //ok im also confused about what to do here
    return server;
    in the end i need this because i have a thread class that runs the servers that has a call this like:
    ServerManager.getServers("serverName", null);
    Im just really confused because i need to get a specific server by name but i have to go through AbstractServer class to get it
    Any help?

    ok, right
    since i have to call this method in the thread class saying
    ServerManger.getServer(AbstractServer[]) //to see if i have all the servers i need to proceed
    im confused about how it should be declared in the actual ServerManager
    should it be like
    public Server[] getServers(AbstractServer[]) ???? and then have it return all the servers it has
    thats the part i dont get, because instead of saying ServerManager.getServer(string, string) i want it to go and find out if i have all the servers i need to continue
    does that make sense? sort of?

  • Newbie at Illustrator scripting needs help assigning image

    I am trying to copy a graphic stored in a vb.net picturebox.image into an activeLayer of an illustrator document. Can anyone supply me with code as to how to do it. Also is there a way to lookup a swatch by name and not have to rely on knowing it's index as in this line of code : pathRef.StrokeColor = docRef.Swatches(3).Color. I know the swatch's name is "CutContour" I would like to assign it by name. And lastly does anybody know any good books, links, etc.. that show you how to do this kind of stuff.
    Thanks,
    Bruce
    Imports IDAutomation.Windows.Forms.LinearBarCode
    Imports Illustrator
    Public Class FormMain
        Dim barcode As IDAutomation.Windows.Forms.LinearBarCode.Barcode = New Barcode()
        Dim illustrator As Illustrator.Application = CreateObject("Illustrator.Application")
        Dim filePath As String = My.Application.Info.DirectoryPath
        Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            barcode.SymbologyID = barcode.Symbologies.Code39Ext
            barcode.BarHeightCM = 1
            barcode.XDimensionCM = 0.03
            barcode.NarrowToWideRatio = 2
            barcode.LeftMarginCM = 0.201
            barcode.TopMarginCM = 0.201
            barcode.TextMarginCM = 0.051
            barcode.ShowText = False
            barcode.CaptionBottomAlignment = StringAlignment.Center
            barcode.CaptionBottomSpace = 0.03
            Dim barcodeText As String = "CODE39UPC" 'hard code barcode content for this test
            barcode.DataToEncode = "*" + barcodeText + "*"
            barcode.CaptionBelow = barcodeText
            PictureBox1.Image = barcode.BMPPicture 'Display Barcode
            barcode.SaveImageAs(".\upc.png", System.Drawing.Imaging.ImageFormat.Png)
            Dim fileName As String = filePath + "\Roland VersaWorks.eps"
            Try
                 illustrator.Open(fileName)
             Catch err As Exception
                 MsgBox("Missing File: " + fileName)
                 illustrator.Quit()
                 Me.Close()
             End Try
            Dim docRef As Illustrator.Document = illustrator.ActiveDocument
            Dim pathRef As Illustrator.PathItem = docRef.ActiveLayer.PathItems.Rectangle(100, 0, 300, 100)
            pathRef.StrokeColor = docRef.Swatches(3).Color 'Set strokeColor to CutContour Swatch
            pathRef.Filled = False ' Don't Fill rectangle with anything
            docRef.ActiveLayer = docRef.Layers(2) 'Activate UPC Layer
            '############## I need to copy PictureBox1.image into this activeLayer! How do I do it? ###########
            Dim epsOptions As Illustrator.EPSSaveOptions = CreateObject("Illustrator.EPSSaveOptions")
            epsOptions.CMYKPostScript = True
            docRef.SaveAs(filePath + "\test.eps", epsOptions)
            illustrator.Quit()
            Me.Close()
        End Sub
    End Class

    Hi,
    Hodge-Podge wrote:
    Also is there a way to lookup a swatch by name and not have to rely on knowing it's index as in this line of code : pathRef.StrokeColor = docRef.Swatches(3).Color. I know the swatch's name is "CutContour" I would like to assign it by name.
    I have no knowledge in VB, but in javascript
    it should be called by:
    var mySwatche=app.activeDocument.swatches.getByName("CutContour");
    Regarding how to copy, i guess that you can load picture as raster / placed items or cut() & paste()... it's just ideas,
    Sorry, art.chrome

  • Need help creating actionListener for an array of text fields

    I am working on a school project, so I am very new to Java. I have a program which is basically a unit converter. Each unit type has its own tab. I was able to dynamically create text fields in each tab and now I need to add actionListener to each of those text fields. Probelm is, the text fields are not really unique. I guess they're only unique within their tab. So now I am having difficulty referring to my text fields. If you look at my actionListener in the code below, I am trying to refer to it as unitTFs[0].getText() and that's not working. Please help. Thanks in advance.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class UnitConverter extends JPanel
    public UnitConverter()
    String[] lengthUnits = {"cm","m","inch","feet","yard","mile"};
    String[] areaUnits = {"m2","a","feet2","yd2","Acre","ha"};
    String[] massUnits = {"g","kg","ton","ounce","pound"};
    String[] volumeUnits = {"liter","m3","inch3","feet3","Gallon","Barrel"};
    String[] tempUnits = {"C","F"};
    ImageIcon lengthICN = new ImageIcon("java-swing-tutorial.JPG");
    ImageIcon areaICN = new ImageIcon("java-swing-tutorial.JPG");
    ImageIcon massICN = new ImageIcon("java-swing-tutorial.JPG");
    ImageIcon volumeICN = new ImageIcon("java-swing-tutorial.JPG");
    ImageIcon tempICN = new ImageIcon("java-swing-tutorial.JPG");
    JTabbedPane tabPaneJTP = new JTabbedPane();
    JPanel lengthPNL = tabContents(lengthUnits);
    tabPaneJTP.addTab("Length", lengthICN, lengthPNL);
    tabPaneJTP.setSelectedIndex(0);
    JPanel areaPNL = tabContents(areaUnits);
    tabPaneJTP.addTab("Area", areaICN, areaPNL);
    JPanel massPNL = tabContents(massUnits);
    tabPaneJTP.addTab("Mass", massICN, massPNL);
    JPanel volumePNL = tabContents(volumeUnits);
    tabPaneJTP.addTab("Volume", volumeICN, volumePNL);
    JPanel tempPNL = tabContents(tempUnits);
    tabPaneJTP.addTab("Temperature", tempICN, tempPNL);
    //Add the tabbed pane to this panel.
    setLayout(new GridLayout(1, 1));
    add(tabPaneJTP);
    protected JPanel tabContents(String[] units)
    JPanel tabPNL = new JPanel();
    JTextField[] unitTFs = new JTextField[units.length];
    JLabel[] unitLs = new JLabel[units.length];
    for (int i = 0; i < units.length; i++)
    unitTFs[i] = new JTextField("0");
    unitLs[i] = new JLabel(units);
    tabPNL.add(unitTFs[i]);
    tabPNL.add(unitLs[i]);
    tabPNL.setLayout(new GridLayout(units.length, 1));
    return tabPNL;
    private class CmHandler implements ActionListener
    public void actionPerformed(ActionEvent e)
    double cm, m;
    cm = Double.parseDouble(unitTFs[0].getText());
    public static void main(String[] args)
    JFrame frame = new JFrame("Unit Converter Demo");
    frame.getContentPane().add(new UnitConverter(), BorderLayout.CENTER);
    frame.setSize(500, 500);
    frame.setVisible(true);

    Variables only have scope in the method (or block) in which they are created. That means if you create a variable in one function, you can't use it in another.
    If you want to use a variable in two different functions, you have to make it a member variable.
    [Declaring Member Variables|http://java.sun.com/docs/books/tutorial/java/javaOO/variables.html]

Maybe you are looking for

  • Updated to OS5, restoration failed with error -50.

    I updated the phone to OS5. Restoration failed with an error -50. I lost all my contacts, email setup, photos and other configuration. How do I get back my contacts?

  • Rich Text Editor bug

    Hello, My flex website at http://www.theplaygrounds.co.uk/The_Playground.swf throws the below error when I click on Contact or B/I/U on the Rich Text Editor. ReferenceError: Error #1069: Property string not found on mx.controls.RichTextEditor and the

  • RAW in Photoshop Elements 11

    I like to make photos in RAW but Photoshop lements 11 does not take it from my Canon 700D. What can  do

  • Built-in iSight with Lion

    There was a thread here in the discussion forums a few weeks ago about the camera not working with Adobe flash and a "workaround" was given.  Does anyone have quick access to that by chance? John (NYC)

  • Multiple Item Master Organizations

    We are working on an Oracle Implementation for a large firm in South Korea. Our client covers many different industires and operate nationally, it is inevitable to use Multi-Organization structure. And we are also considering implementing multiple it