Make components like JPanel / Containers ..  from a String..

public class PuzzlePieces {
     private String area;
     private String *container* = area +"Container";
     private String panel = area +"Panel";
     private Container *container* = new Container();
     private int number;
     public PuzzlePieces(String area, int numbersOfPices) {
          this.area = area;
          this.number = numbersOfPices;
     }as you can see I want to make a Container out of a Sting. How can I do this? Please make an example if you have a solution. TY

Plexus81 wrote:
OK, I'll try to explain ..
I get a string in, as you can see. I want to make/add JButton, JPanel, Containers .. based on name of the String I get in.
String
StringPanel
StringContainer
But I cant write like this
Container String +"Container" = new Container();What's the best way to solve this..You want the variable names for those Containers to be based off the Strings? Is that what you mean? Why do you want/need to do that?
The go-to solution for stuff like this is to use a Map of String, Container pairs. But why over complicate your program with stuff you probably don't really need?

Similar Messages

  • Make Array of int's from a String

    Hi,
    Trying to transform a String into an array of ints. The following works, but seems a little longwinded for what must be quite a common function - specifically line 9 in the code (turning a char into an int). Can anyone suggest an easier way?
    public class IntArray {
        public static void main( String[] args ) {
            if ( args.length == 1 ) {
                String s = args[ 0 ] ;
                int sLength = s.length() ;
                int[] argIntArray = new int[ sLength ] ;
                for ( int j = 0 ; j < s.length() ; j++ ) {
                    // This line ...
                    argIntArray [ j ] = Integer.parseInt( s.charAt( j ) + "" );
                for ( int j = 0 ; j < argIntArray.length ; j++ ) {
                    System.out.println( argIntArray[ j ] );
            } else {
                System.out.print( "Please enter an int" );
    }Thanks,
    Rich

    I'm not sure how common it is, but since you are assuming that the input is a String that represents an int...
    public class IntArray {
         public static void main( String[] args ) {
              if ( args.length == 1 ) {
                   String s = args[ 0 ] ;
                   int sLength = s.length() ;
                   int[] argIntArray = new int[ sLength ] ;
                   for ( int j = 0 ; j < s.length() ; j++ ) {
                        // This line ...
                        argIntArray [ j ] = s.charAt( j ) - '0' ;
                        //I suggest checking for <0 or >9
                   for ( int j = 0 ; j < argIntArray.length ; j++ ) {
                        System.out.println( argIntArray[ j ] );
              } else {
                   System.out.print( "Please enter an int" );

  • How do I make my email look like it's from my main address?

    Hey Gang,
    I use me.com email to get it pushed to my phone, ipad, etc. 
    When sending an email, how can I make it look like it's from my "real" email address, and not my me.com address?
    Thanks,
    Rob

    You can't: the iCloud server won't allow it.

  • How do I make a Datagram Packet from a String?

    I am looking to make a Datagram Packet from a string. If I send a command to a server that allows remote connections via UDP, such as "restart" it will restart the server. I can accomplish this easily through the fput() method of PHP.
    I want a Java version of my utility, and am using the DatagramSocket and DatagramPacket classes. I see that I need to make a byte array and put it inside a DatagramPacket. How would I go about putting the string "restart" into a byte array?
    Thanks,

    Use the following code to send a Datagram:-
    import java.io.*;
    import java.net.*;
    // This class sends the specified text as a datagram to port 6010 of the
    // specified host.
    public class UDPSend {
        static final int port = 6010;
        public static void main(String args[]) throws Exception {
            if (args.length != 2) {
                System.out.println("Usage: java UDPSend <hostname> <message>");
                System.exit(0);
            // Get the internet address of the specified host
            InetAddress address = InetAddress.getByName(args[0]);
            // Convert the message to an array of bytes
            int msglen = args[1].length();
            byte[] message = new byte[msglen];
            args[1].getBytes(0, msglen, message, 0);
            // Initilize the packet with data and address
            DatagramPacket packet = new DatagramPacket(message, msglen,
                                   address, port);
            // Create a socket, and send the packet through it.
            DatagramSocket socket = new DatagramSocket();
            socket.send(packet);
    }This uses argments, if you want a string change the code accordingly.

  • Does the apple tv make the computer act like a receiver from the tv?

    does the apple tv make the computer act like a receiver from the tv?

    When using home sharing, the computer is on and running iTunes and the content is sent over the local network to the Apple TV.

  • What do I need to do to make a forum just like this one(from apple)

    What do I need to do to make a forum just like this one(from apple)

    Wendy, as a_a has explained, when power is removed, the data is gone.
    If you want to put this problem to rest, remove either of the battery connections; this will assure the data is gone forever!
    WyreNut
    Post relates to: Centro (AT&T)
    I am a Volunteer here, not employed by HP.
    You too can become an HP Expert! Details HERE!
    If my post has helped you, click the Kudos Thumbs up!
    If it solved your issue, Click the "Accept as Solution" button so others can benefit from the question you asked!

  • Is there an easy way to convert from a String with a comma, ie. 1,000.00 to

    Is there an easy way to convert from a String with a comma, ie. 1,000.00 to a float or a double?
    thanks,
    dosteov

    Like DrClap said: DecimalFormat. However, make sure you understand the Locale things, as explained at http://java.sun.com/j2se/1.3/docs/api/java/text/DecimalFormat.html (which refers to NumberFormat as well) and use them explicitly. Like
    public class FormatTest
      public static void main(String args[])
        try
          // see NumberFormat.getInstance()
          DecimalFormat fmt = new DecimalFormat();
          Number num = fmt.parse("1,000.01");
          System.out.println(num.doubleValue());
        catch(ParseException pe)
          System.out.println(pe);
    }most likely seems OK on your system, but may print "1.0" (or even fail) on some non-English platforms!
    When performing calculations, also see http://developer.java.sun.com/developer/JDCTechTips/2001/tt0807.html
    a.

  • Sticking components in JPanel to GridLayout

    Could please anyone help in the following.
    I have an application where some JPanel with several Swing components
    positioned with help of GridLayout. What I need is to
    remove and place components during runtime,
    but the problem is that when I remove component placed somewhere
    inbetween with use of the method remove() of the class JPanel,
    all components are shifted so that the empty space is filled and
    even one can see that the initial GridLayout is destroyed.
    How can I stick all components to the initial grid cells of GridLayout?
    I mean I do not want components to shift anywhere from their original
    cells.
    Thank you in advance.

    Well, that solution is what I came to also.
    I mean I replacing removed compenent with some other invisible component.
    But is this indeed the only way?
    I tryied the method removeLayoutComponent() in the class GridLayout, but
    I have not understood how it works and what it is for.
    When I tryied it instead of remove() (of JPanel) it did not remove anything,
    but it looks like something relevant to my situation.
    PS The second line of my orginal poster should be read
    "I have an application where some JPanel is created with several Swing components
    positioned with help of GridLayout in it".
    Sorry...

  • How to make a call  to service from site studio templates?

    Hi,
    May be this is very basic but I am not able to figure out how to make a call to a service from site studio templates (hcsp). I have seen one example of service call in the dynamic list fragment. It makes a call to SS_GET_SEARCH_RESULTS service using executeService() method. But it doesn't take any parameters and also not very how returned results are captured.
    I want to execute WCM_PLACEHOLDER service. It takes 2 main parameters dataFileDocName and templateDocName. The returned result is typically a html response.
    The service typically is executed using http request and the url would be something like this
    http://hd-pratapm/ucm/idcplg?IdcService=WCM_PLACEHOLDER&dataFileDocName=VIRTUSAINC&templateDocName=DETAILS_REGION_TEMPLATE
    I think SS_GET_SEARCH_RESULTS service works in the similar fashion. I want to execute WCM_PLACEHOLDER service too using executeService() method. How to work with this? How can we pass parameters and capture returned results?
    Regards,
    Pratap

    Hey Pratap,
    If you are on a standard Site Studio template (page or subtemplate) you should be able to call the wcmPlaceholder idoc function directly. In fact calling the idoc function provides a lot more functionality then the service call (they locked down a few things in the service call since it is designed to be called from an external application).
    The idoc call would look something like: <!--$wcmPlaceholder("Sales", "placeholderDefinitionDocName=placedef_salescontact")--> (taken from page 208 in this doc: http://download.oracle.com/docs/cd/E10316_01/SiteStudio/10gr4/Pdf/Site_Studio_10gR4_Designer_Guide.pdf)
    As a general note when you are in idoc script and want to execute a service you call <$executeService()$> as you saw in the dynamic list. The parameters that the service runs on are in the data binder of the current request. To set parameters for an execute service you simply set idoc variables on the page before it. Example:
    <!--$QueryText="dDocType <matches> `Document`" -->
    <!--$executeService("GET_SEARCH_RESULTS")-->
    As for the response when you execute an idoc function, like wcmPlaceholder, that returns a String the response is immediately output to the page in the location you called the function. This would be similar in concept to a jsp scriptlet that outputs a string <%=myResponseString%>
    Hope that helps,
    Andy Weaver - Senior Software Consultant
    Fishbowl Solutions < http://www.fishbowlsolutions.com?WT.mc_id=L_Oracle_Consulting_amw_OTN_ECM >
    Edited by: Andy Weaver on Jul 7, 2010 7:59 AM
    Added response detail.

  • Remove leading zeros from a string

    Hi,
    I have a string with some numeric value.
    e.g.
    String a = 54890001
    I want to make it 10 digits long by padding zeros at the begining
    Now a = 0054890001 ( this is for display purpose ) I know how to do it.
    Now How can strip these leading zeros from this number to get back the actual number. The user sees this 10 digit number and he can change it to something like 0067490001. Now I want to strip these leading zeros.
    and i shd get 67490001.
    In other words, how to strip leading zeros from a string ?
    Thanks for help
    Vinod

    I would try two things: First, just try a straightforward parsing of your String using the Integer.parseInt() method. This is only my first suggestion because the number could be interpreted as octals; only testing will really tell. Second, try a method like this:
    public static String removeLeadingZeros(String str) {
        if (str == null) {
            return null;
        char[] chars = str.toCharArray();
        int index = 0;
        for (; index < str.length; index++) {
            if (chars[index] != '0') {
                break;
        return (index == 0) ? str : str.substring(index);
    }Shaun

  • Generate sound(voice) from a String

    Hello everybody.
    I would like to generate sound from a String at Symbian devices automaticaly. I wil receive the value of this String remotely and then it will be generated to a sound.
    The String will not be very long (3 to 4 words).
    For example,
    String test="Hello everybody";Is it possible via J2ME API?
    Or do I need any external library?
    Regards,
    kalgik

    You can't easily do it... you can using reflection:
    MyStaticClass.class.getField().getXXX("MyVariable") //depending on what type the field is...But this seems like it may be a flawed design. Maybe you should try making a static HashMap in the class, use a Static init block and static get/set methods:
    public class StaticClass
        static Map properties;
        static
            properties = new HashMap();
            properties.put("MyVariable", "Some Value");
            properties.put("OtherVariable", new Integer(3));
        public static Object get(String property)
            return properties.get(property);
        public static void set(String property, Object value)
            //Maybe some code checking to make sure object is right type
            //or don't use a set method at all to make the properties immutable
            properties.put(property, value);
    }

  • Take and delete a String from another String

    I have original input string= 111100001111
    I need to Take for example the least 4 bits .... Output= 1111
    and to be removed from the original input string so the original input string= 11110000 
    I am trying to make a generic one but the point is that I can not delete subset that I take from the original input String.  
    How can I take and delete from a string in the same time? 
    Solved!
    Go to Solution.

    Something like this?
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Split String.png ‏13 KB

  • Possible to create an object from a String?

    Hi,
    is is somehow at all possible to create an object from a String ?
    If we have etc.
    String txt = "Carrot()";
    Is it then possible to somehow cast that String and interpret it as a class type that it should make an object of ?
    Like
    new txt; - would then give me the same as new Carrot(); ?
    Hope you understand what i mean.
    Martin From... :-)

    Class.forName("some.package.Carrot");

  • How do yah make something like this?

    I'm trying to make simething like this. However I'm stuck on what sort of algorithm would be used. Any idea? Thanks a bunch in advance for any help!
    http://i91.photobucket.com/albums/k293/rawlehypermode/Untitled.jpg

    You meant something like this ?
    import java.awt.Dimension;
    import java.awt.Graphics;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class LineDemo extends JPanel {
        final static int SIZE = 640;
        final static int STEP = 20;
        protected void paintComponent(Graphics g) {
            for (int i = 0; i < SIZE; i += STEP) {
                g.drawLine(i,0,SIZE,i);
                g.drawLine(SIZE,i,SIZE-i,SIZE);
                g.drawLine(SIZE-i,SIZE, 0, SIZE - i);
                g.drawLine(0, SIZE - i,i,0);
        public static void main(String[] args) {
            JFrame frame = new JFrame("Line demo");
            frame.add(new LineDemo());
            frame.setPreferredSize(new Dimension(SIZE+STEP,SIZE+2*STEP));
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
    }

  • How to make something like this in Edge Animate?

    Hi,
    I'm hoping to make something like this – https://www.youtube.com/watch?v=OJeDppEHI1g – in Edge Animate but I'm not sure where to start.
    I'm new to Edge but am keen to explore.
    Anyone have any feedback on whether:
    1. It's possible, and
    2. What techniques/effects have been used.
    Thanks!

    Hi there and welcome,
      Could you be a little more specific on what it is exactly that you would want to create? Most of what I can see from that website is doable in Edge Animate, but if you specify what it is you'd like to accomplish I could walk you through how to do it.
    Thanks!

Maybe you are looking for

  • Java.io.IOException: Not enough space  - Weblogic 8.1 on Solaris 8

    Hi, We get "java.io.Exception: Not enough space" sometimes when trying to access JSPs hosted on Weblogic 8.1 on Solaris 8. It looks like a problem because of increased swap space usage. What should we do to get rid of this issue Compilation of '.....

  • Excel 2008 Number Problems OS 10.7.5

    I have suddenly developed a problem in my Excel worksheets. I cannot get a plain number to show. If I format the cell for either number or general, I get the currency format. Every number has a .00 in it or is rounded off to the numbers before the do

  • "iTunes Library" can't be read, it was created by a newer version of iTunes

    I just installed iTunes 9.1. I'm running OS X 10.5.8. When I try to open iTunes, I get the above message that it can't read the file "iTunes Library." The result is iTunes can't be opened at all. When I connect my iPhone to the system, iTunes opens n

  • Statistical Setup (OLI3BW tcode)

    Hi all,     Can anyone please explain me what the below fields mean and what should I select to do a Statistical setup ie to do a full update. Control of Recompilation run 1.  Name of Run(New Run) 2.  Termination date, Termination time 3.  block all

  • MONITORING EXTERNAL MIDI?

    Goal: To be able to monitor the audio of my external synth module through my Presonus/FIREBOX. Current Status: External MIDI is communicating with Logic, but no external MIDI heard through FIREBOX interface. Equipment: Yamaha S90 controller keyboard,