Current Position:Home > 2 parts: 1) integer array to string 2) string out to a jTextField

2 parts: 1) integer array to string 2) string out to a jTextField

Update:11-30Source: network consolidation
Advertisement
I am completely new to Java and Netbeans, but I'm writing my 1st
application that takes a "hex" character input from a jTextField,
then converts it to an "binary" integer array. I then do a lot of bit
manipulation, and generate a new "binary" integer array.
String myhex = jTextField1.getText();
    int len = myhex.length();
    int[] binarray = new int[len*4];
        for (int i = 0; i < len; i++) {
           if (myhex.charAt(i) == '0'){
              binarray[4*i]=0;
              binarray[4*i+1]=0;
              binarray[4*i+2]=0;
              binarray[4*i+3]=0;
           else if (myhex.charAt(i) ==
           // repeat for '1 to 9' and 'a-f/A-F'
           // generate new integer array(s) using various bits from binarrayI realize it might not be the best way to do the
conversion, but my input can be of arbitrary length,
and it is my first time trying to write Java code.
All of the above I've completed and it works...(thanks Netbeans
for making the gui interface design a real breeze!)
So I end up with:
binarray[0]=0 or 1
binarray[1]=0 or 1
binarray[2]=0 or 1
binarray[n]=0 or 1
Where n can be any number from 0 to 63...
I then manipulate the bits in binarray creating a new integer array
and for the sake of expediency let's call it "newbinarray".
newbinarray[0]=0 or 1
newbinarray[1]=0 or 1
newbinarray[2]=0 or 1
newbinarray[n]=0 or 1
Where n can be any number from 0 to 63...
I first need to know how to convert this "newbinarray" integer array to a string.
In the simplest terms if the first three elements of the array are [0][1][1],
I want the string to be 011.
Then I want to take this newly formed string and output it to a jTextField.
string 011 output in JTextField as 011
I've scoured the net, and I've seen a lot of complex answers involving
formatting, but I'm looking for just a simple answer here so I can finish
this application as quickly as possible.
Thanks,
Thorne Kontos

The Best Answer

Advertisement
Here's an example, not using NetBeans:
import javax.swing.*;
public class TextDemo extends JPanel
    public TextDemo()
        int[] newbinarray = {0, 1, 1};
        StringBuffer sb = new StringBuffer();
        for (int value : newbinarray)
            sb.append(value);
        String st = new String(sb);
        this.add(new JTextField(st));
    private static void createAndShowGUI()
        JFrame frame = new JFrame("TextDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(new TextDemo());
        frame.pack();
        frame.setVisible(true);
    public static void main(String[] args)
        javax.swing.SwingUtilities.invokeLater(new Runnable()
            public void run()
                createAndShowGUI();
}
  • 2 parts: 1) integer array to string 2) string out to a jTextField Update:11-30

    I am completely new to Java and Netbeans, but I'm writing my 1st application that takes a "hex" character input from a jTextField, then converts it to an "binary" integer array. I then do a lot of bit manipulation, and generate a new &

  • Converting a string to an integer array Update:11-30

    This is kind of a newbie question, but: If I have a string which looks like this: "12,54,253,64" what is the most effective/elegant/best/etc. way to convert it into an integer array (of course not including the ","s :-) Any suggestions

  • An integer array with a string? Update:11-30

    Sockets in my server program are stored in an array of course. I want to attach a string with it in the array Conceptually like this: public static OutputStream usr [] = new OutputStream[6], "name" ; So i can track their login names with their s

  • Saving an integer array into a .txt file Update:10-11

    hii, im only a beginner in java, so this is the only code i've learned so far for saving array elements into a file      public static void saveNames(String [] name) throws IOException                FileWriter file = new FileWriter("Example\\names.t

  • How can i asign value to variables stored in an array of string? Update:11-30

    hi how can i asign value to variables stored in an array of string. i need to do it so that i can evaluate a math expression by usin those values. for example, i have a string array like [x, y, z, k]. now i need to asign 2.0 to x, 3.0 to y and so on.

  • How can i combine an array of string and an array of integers ? Update:11-30

    i have an array of string data [to be used as header], and an array of multiple column integer vakues;i need them together in one file.  Am not able to combine them so that i can write them into a single file. Solved! Go to Solution. Attachments: str

  • How can i cast array of string to int ? Update:11-30

                       while(st.hasMoreTokens()){                               test[count] = st.nextToken();                               count++;                       }Since token deal with string, i have to pass them into String of array, but how ca

  • Converting Array of string to an array of integers Update:11-30

    I have a problem converting a array of string to array of int's This is my code... String[] forminfo = request.getParameterValues("forsendur");       int[] forminfoInt = Integer.parseInt(forminfo); This is the error message: Incompatible type fo

  • Suggestion: Macros or a way to unroll loops? Integer array input? Shader Model 3 and 4? Update:11-30

    I think it would be nice if pixel bender supported a way to unroll loops. In it's current state certain shaders are really awkward to write or just get ugly when they're converted for flash player. I know it wouldn't be that hard for the developers t

  • Sorting an array of Strings Update:11-30

    Okay, my first concern is that I'm pretty new to Java. It's my first language that I've ever looked at, and I'm just getting into it. I'm trying to read from a .txt file a name and an integer value associated with that name, like for instance, Jimmy