More than one URL object

OK - I've managed to get this far without posting to the forum with this project, which shows that I'm actually beginning to grasp java.
I'm trying to get graphics to show up on JButton in jar files - I know that you're thinking that I should search the forums and I've already done that and found part of the solution - which is so create a URL object which uses the getResource method.
This works when I have one button - and works fine - when I have more than one for some reason the whole application crashes. If I have two buttons implemented through this way the first works fine, but the second causes the application to crash and I get:
Uncaught error fetching image:
java.lang.NullPointerException
        at sun.awt.image.URLImageSource.getConnection(Unknown Source)
        at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
        at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
        at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
        at sun.awt.image.ImageFetcher.run(Unknown Source)My code is
if (letter=="a"){
     URL urlA = JIEventFrame.class.getResource("alphabet_media/Angelfish.png");     
     ImageIcon picA = new ImageIcon(Toolkit.getDefaultToolkit().getImage(urlA));
          jiEventOK = new JButton(picA);  jiEventText = new JLabel ("a, Angelfish", JLabel.CENTER);}
if (letter=="b"){
          URL urlB = JIEventFrame.class.getResource("alphabet_media/Baloons.png");     
          ImageIcon picB = new ImageIcon(Toolkit.getDefaultToolkit().getImage(urlB));
          jiEventOK = new JButton (picB); jiEventText = new JLabel ("b, Balloons", JLabel.CENTER);}letter is a String which is passed from a preceding class which creates an instance of this one.
Any ideas why one would work and not two, even though they've got different identifiers ?
Thanks in advance.
adam

Map pngs = new HashMap();
pngs.put("a", "Angelfish");
pngs.put("b", "Balloons");
// and so on
Your code which you were having a
problem then doesn't need to have 26 if-statements, it
should look more like this:
String pngName = (String)pngs.get(letter);
URL url = JIEventFrame.class.getResource("alphabet_media/" + pngName + ".png");
ImageIcon pic = new ImageIcon(Toolkit.getDefaultToolkit().getImage(url));
jiEventOK = new JButton(pic);
jiEventText = new JLabel (letter + ", " + pngName,
JLabel.CENTER);Okay - this is a neat looking piece of code and I'm really learning. Many thanks for this. However, I'm not sure what pngName will be in this instance - will it be "a" + "Angelfish" or will it be "a", or "Angelfish"? How are the two parts separated, if at all? I've read the API for HashMap, but it isn't all that clear. I'll scour the tutorials next. How does the String know that letter is the first element "a" and that pngName is "Angelfish"?
I want to have an ImageIcon called Angelfish.png and then another JLabel where I will show the text "a, Angelfish".
Also there is a smallish problem in that not all the graphics are png; I also have jpg, but I could fix that by reformatting them. However, it's not an ideal fix.

Similar Messages

  • Can i open more than one Resultset object

    hi in my program i have to retrive data from three table and the data from three
    table i have to use in another one
    i wanna know that can we open more than one ResultSet object within one
    try{
    }catch{] block ( i means ResultSet rs = st.excuteQuery(query) more than one time for different -different tables)
    or there is any other way to do this

    You can only have one active result set per statement at a time.
    Depending on the driver you are using you might be able to have more than one active statement (and result set) on one connection. Or not.
    Try catch has nothing to do with that.
    If you are nesting result sets then it is likely you should be using a join (SQL) which would then only require one result set.

  • Can i Bind more than one Model object to the Custom controller or not

    Hi All, I trying to bind more than one model object to the custom controller, Both the model objects contains same attribute name called ( output). Both model objects created on to top of the BAPI. So when i bind first model object to the custom controller will work fine. When i am trying to bind the second model object to the same controller. This second model object also having the same attribute name called "output" . So it is giving an error of "Duplicate context element "Detail". Rename or uncheck duplicate elements.
    can i assign more than one model object to the single controller or not?
    But in the reference document, it has given that , we can create model object with more than one bapi.So in this case if both the bapis contains any element with the same name will also be problem. Any body give me the solution.
    Initially we have created one custom controller for each model object. But later i realized that, why con't we use same controller for all the model object. Because, the custom controller context is the public context. this context shared across all the view controllers.
    The concept which I am trying to do is right or wrong?

    Hi Vishal,
    of course, you can bind one controler to many models. When the same name occours you can simply RENAME binded node in controler.
    Regards
    Bogdan

  • Charts - more than one dimension object on the x axis of the chart

    Is it possible to add more than one dimension object on X axis of the chart ? I have two reports - one for bookings revenue for rolling 12 months period and other for forecast revenue for forward going 12 months. I have been asked by my manager to produce one chart showing 12 months rolling bookings plus revenue forcast going forward 12 months in one chart. Is it possible? and if so then how to go about to accomplish it.
    Thanks for the help in advance.
    - Fizza

    hi
    i think it is posible. for exaple  on x axis can include year, months.  on y axis may include sales revenue.
    or
    what dimensions are you going to put on the x axis and y axis?

  • Dragging more than one display object in flex3

    As per my knowledge, we can drag and drop only one display object at a time.... What should i do if i want to drag more than one display object together as a group.
    I am having a canvas and inside it i am having a box..... In that box I am having many Panels.... Now i can create a group of adjascent panels.... And i can drag that panel group to some other place in that box only....
    So how to drag a group of display objects together.

    You can use custom code for that.  Flex doesn't use the Flash Player's dragging API.  It monitors mouse activity instead.  There is an example in Panel.as.  You can extend it to move more than one panel.
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • External e-mail to more than one organizational object

    Is there any way to send an external e-mail in a mail step on the WF, to more than one organizational object, without getting their mails?.
    I mean, I have a table with OTYPE and OBJID
    (example:
    line 1: 'US' 'USERNAME'
    line 2: 'O' '123456'
    line3:  'S' '56789'
    I can send them a work-item or a notification, but can I send them an external e-mail in a mail step?
    If not, how can I get their mails with an FM?
    Thanks!!!!

    Hi,
    send an external e-mail in a mail step on the WF, to more than one organizational object
    1) Get the Email ids of the Org. Objects and stored it in a Multiline Container element and assign it in the 'Send Mail' step
    2) Other wise, you have to create a Method in the BO, in the Method get all the email ids of the Org. Object. Then using the Function Module  [SO_NEW_DOCUMENT_ATT_SEND_API1|https://wiki.sdn.sap.com/wiki/x/nYKdAw]  to send the email.
    Regards,
    Surjith
    Edited by: surjith kumar on Jun 9, 2009 6:53 PM

  • Are there any way to copy or delete more than one url at a time

    i have a lot of url and i want to copy them to another folder, for now i do it one at a time, so i am wondering can i highlight and cope more than one at a time, and i also want to do this in delete.

    If i ever win a grammy. ill thank u...ok one last thing...is there a way to sort of consolidate tracks? sometimes there are a few...quite a few and some stuff could be on one but i need it to not cut out any of the other parts

  • Added more than one service objects

    Is it possible to add more than one attachment to the service for object section? It is possible to delete more than one attachments..
    Edited by: Lien Thach on Jan 14, 2010 3:20 PM

    The user wants to add more then one attachment documents in SAP..It will allow for them to delete more than one documents. can this be done through configuration? If so, can you please show me how?

  • Creating Interactive Files with more than one URL

    Hello, here's my problem: I want to create more than one button instance that go to different URL address's. From the Adobe Video Workshop, I got the code:
    interactive_test.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    function buttonClickHandler(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    This works fine with one button instance. When I copy and paste the code for another button instance, i.e:
    butn1.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    function buttonClickHandler(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    butn2.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    function buttonClickHandler(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    I get 1021 duplicate function error. I think I understand in priciple what's wrong but don't know how to fix it. MyI knowledge of Action Script 3 is zero. What I need is sample code that works that I could copy and paste, with appropriate changes.
    Thanks in advance for your help, Richard

    use different function names or flash won't know which function to use:
    butn1.addEventListener(MouseEvent.CLICK, buttonClickHandler1);
    function buttonClickHandler1(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    butn2.addEventListener(MouseEvent.CLICK, buttonClickHandler2);
    function buttonClickHandler2(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));

  • Can I create more than one URL link in a single Flash (SWF) file?

    I created a simple SWF slideshow in Flash with 5 slides. I was able to link one URL to the whole file by adding an alpha button.
    What I can't figure out is how to add a URL link to each slide. The SWF file i sused on a website and I would like to be able to click on a particular slide as it is playing to go the a site or page that applies to that slide.
    Is there a way or code I can use to do this??
    This is the code I am currently using for the button now.
    ja_btn.addEventListener(MouseEvent.CLICK,mouseClick);
    function mouseClick(event:MouseEvent):void
                   var request = new URLRequest("http://www.jakeandamos.com/");
                    navigateToURL (request,"_blank");
    I am just learning this stuff so I can use your help, Thanks!

    You cannot duplicate instance names or function names, so you'll need to create unique names for each one that behaves differently.  So you can only have one function named "mouseClick"... if you want to have another function to link somewhere else you need to create a new name for that function ("mouseClick2" would work)
    There are alternate approaches, but for now this will be the easiest for you to deal with.

  • Problem is having more than one FrameAccess object running in multithreads

    Hi all,
    I have a problem with my system which uses JMF for frame capture for frame processing. The system flow is like this -
    I use a FrameAccess.java (modified from the one provided by Sun) to grab frames. I use 5 different threads to create an associated FrameAccess object (i.e. one thread owns its own FrameAccess object ). And then they will do their own processing (all of them are implementing motion estimation thing using buffered image from the frame).
    The problem is , when I examine the frames captured from the 5 threads, something irregular happened.
    For example, the thread A (capturing video A) may return frames captured from video C. such scenairo happened without signs and patterns. Sometimes a thread even return something like half frame from video C and half from video B.
    I would like to know if there is any way to check if it is the problem of JMF (can't synchronize frame capturing), or it's the problem of FrameAccess object (but they are in five independent threads ><")
    Thank you very much...

    It is a problem with how you are handling threads.
    Thread one calls frame access, then thread 2 calls frame access, and it is possible that thread one will only get half a frame.
    You will probably have success by syncronizing your calls to frameaccess(lock), and then unlock when that thread has a complete frame.
    This way only one thread will access frame access, at any one time.
    I have had this exact problem, when trying to capture every single frame, save it to jpeg.
    Half the problem was writing to disk before the frame was complete, thus showing have a picture.

  • CNAME function available for more than one URL?

    Hello!
    I have successfully installed the CNAME funktion for ond URL to be used with an iWebsite.
    Now I would like to create another iWebsite using a different URL via CNAME function.
    Is this possible and if so how can I do it?
    Thorge

    No it is not possible because CNAME forwarding can only be used ONCE for every MobileMe account. 
    If you want to link another domain name to another website, then you will have to use either masked or unmasked web forwarding.
    This is all you can do, remembering that MobileMe will not be here after June this year, so you'll have to find alternative web hosting anyway - why not start looking now rather than using MobileMe?

  • Returning more than one value/object from an EJB method

    Hi,
    I have the follong method in the remote interface of my EJB:
    void createSomeObject( MyObject obj1, List returnList1, Map returnMap1);
    Since i want to return a List (returnList1) and a Map(returnMap1) from my EJB method "createSomeObjects", i am passing these as parameters thinking they will be passed by reference and the client(servlet) gets the changes the EJB made to these objects.
    But it doesn't seem to be working, the EJB is filling the List and Map objects and the servlet doesn't get it (pass by value problem).
    My understading is that, all parameters to an EJBs are passed by value(because they are remote calls, the RMI thing), let me know if this right.
    Is there any workaround apart from the following alternative?
    Alternatives:
    1. Wrap "List list1" and "Map map1" in another model and return this instead of passing them as parameters.
    Thanks
    Vasu

    My understading is that, all parameters to an EJBs
    are passed by value(because they are remote calls,
    the RMI thing), let me know if this right.Yes, that is correct - which you should know from your introduction to J2EE reading.
    Is there any workaround apart from the following
    alternative?
    Alternatives:
    1. Wrap "List list1" and "Map map1" in another model
    and return this instead of passing them as
    parameters.No.

  • Is it possible to download/Upload more that one AOL objects using FNDLOAD.

    Hi,
    I need to download responsibilities and then its will need to migrate in PRD using fndload.
    in my case, i have more 50 responsibilities. i want to download all responsibilities in one shot using FNDLOAD commnad. same way to upload in other instance in one shot.
    Is it possible to download/upload more than one AOL object like Repsonsibilities,menu, function, lookup, flexfield etc using FNDLOAD in Oracle Apps R12.
    configuration :
    EBS : r12.1.2
    DB : 11gR3.
    Thank you,
    Nitin

    Try this
    $ FNDLOAD apps/apps 0 Y DOWNLOAD $FND_TOP/patch/115/import/afscursp.lct file_name.ldt FND_RESPONSIBILITY RESP_KEY="%SYS%"
    Log filename : L2117062.log
    Report filename : O2117062.out
    $ more L2117062.log
    L2117062.log
    +---------------------------------------------------------------------------+
    Application Object Library: Version : 12.0.0
    Copyright (c) 1979, 1999, Oracle Corporation. All rights reserved.
    module:
    +---------------------------------------------------------------------------+
    Current system time is 25-MAR-2013 11:48:55
    +---------------------------------------------------------------------------+
    Downloading FND_RESPONSIBILITY to the data file file_name.ldt
    Downloaded FND_APPLICATION WMS
    Downloaded FND_RESPONSIBILITY WMS DW_SYSADMIN
    Downloaded FND_RESPONSIBILITY WMS LSP_SYSADMIN_KEY
    Downloaded FND_APPLICATION CS
    Downloaded FND_RESPONSIBILITY CS CS_KB_SYSTEM_ADMIN
    Downloaded FND_RESPONSIBILITY CS CS_KB_SYS_ADMIN
    Downloaded FND_APPLICATION ICX
    Downloaded FND_APPLICATION FND
    Downloaded FND_RESPONSIBILITY ICX SYSTEM_ADMINISTRATION
    Downloaded FND_APPLICATION PA
    Downloaded FND_RESPONSIBILITY PA PROJECTS SYSTEM ADMINISTRATOR
    Downloaded FND_APPLICATION SYSADMIN
    Downloaded FND_RESPONSIBILITY SYSADMIN XX_SYSADMIN_CUSTOM
    Downloaded FND_RESPONSIBILITY SYSADMIN SYSTEM_ADMINISTRATOR
    Downloaded FND_APPLICATION PV
    Downloaded FND_RESPONSIBILITY PV SYS ADMIN
    Downloaded FND_APPLICATION CSS
    Downloaded FND_RESPONSIBILITY CSS CSS_DEF_SYS_ADMIN_RESP
    Downloaded FND_RESPONSIBILITY CSS CSS_DEF_SYS_ADM
    Downloaded FND_APPLICATION FLM
    Downloaded FND_RESPONSIBILITY FLM SYSTEM_ADMINISTRATOR-71451394
    Downloaded FND_APPLICATION GMA
    Downloaded FND_RESPONSIBILITY GMA OPM_SYSTEMS
    Downloaded FND_APPLICATION IBU
    Downloaded FND_RESPONSIBILITY IBU IBU_SYS_ADMIN
    Downloaded FND_APPLICATION IBY
    Downloaded FND_RESPONSIBILITY IBY IBY_OAUI_ADMIN_SYS_RESP
    Downloaded FND_APPLICATION JA
    Downloaded FND_RESPONSIBILITY JA JAI_SYSADMIN
    Downloaded FND_APPLICATION JTF
    Downloaded FND_RESPONSIBILITY JTF JTF_FM_SYSTEM_MANAGER
    Downloaded FND_APPLICATION MSD
    Downloaded FND_RESPONSIBILITY MSD MSD_EOL_SYSADMIN
    Downloaded FND_RESPONSIBILITY MSD MSD_SOP_SYSADMIN
    Downloaded FND_RESPONSIBILITY MSD MSD_SYSADMIN
    Downloaded FND_APPLICATION XDP
    Downloaded FND_RESPONSIBILITY XDP OP_SYSADMIN
    Downloaded FND_RESPONSIBILITY XDP OP_SYS_ADMIN
    Downloaded FND_APPLICATION XNP
    Downloaded FND_RESPONSIBILITY XNP NP_SYS_ADMIN
    Downloaded FND_RESPONSIBILITY XNP NP_SYSADMIN
    Downloaded FND_APPLICATION AHM
    Downloaded FND_RESPONSIBILITY AHM OHM_SYSTEM_ADMINISTRATOR
    Downloaded FND_APPLICATION CN
    Downloaded FND_RESPONSIBILITY CN CN_INC_SYS_ADMIN
    Downloaded FND_APPLICATION IMT
    Downloaded FND_RESPONSIBILITY IMT IMT_SYSADMIN
    Downloaded FND_RESPONSIBILITY IMT IMT_SYS_MONITOR
    +---------------------------------------------------------------------------+
    Concurrent request completed successfully
    Current system time is 25-MAR-2013 11:48:55
    +---------------------------------------------------------------------------+HTH
    Srini

  • OracleConnection opening more than one session.

    Hi,
    I am using ODP.NET 10.2 client, when i try to connect to Oracle database using OracleConnection object it is creating more than one session object.
    I created one windows application, then i added the below code in form load event of the application
    Please find the below code
    string strConnection1 = "Persist Security Info=False;User ID=service1;Data Source=SD.World;Connection Lifetime=60;Max Pool Size=30;Min Pool Size=0;Pooling=true;PASSWORD=ases;";
    string strConnection2 = "Persist Security Info=False;User ID=service1;Data Source=SD.World;Connection Lifetime=60;Max Pool Size=30;Min Pool Size=0;Pooling=true;PASSWORD=ASES;";
    string strConnection3 = "Persist Security Info=False;User ID=service1_customer;Data Source=SD.World;Connection Lifetime=60;Max Pool Size=30;Min Pool Size=0;Pooling=true;PASSWORD=ases;";
    OracleConnection con = new OracleConnection(strConnection1);
    con.Open();
    OracleConnection con1 = new OracleConnection(strConnection2);
    con1.Open();
    OracleConnection con2 = new OracleConnection(strConnection3);
    con2.Open();
    When i run the below Query
    select * from V$session where PROGRAM='WindowsApplication7.vshost.exe'
    I am getting 6 session. Please help me out in this regard.

    The Error message was “Unable to open connection” once it reach the maximum session.
    I agree for that, Previously I was not disposing that connection object. Presently I am using keyword to dispose the connection object.
    Here I have doubt
    In connection string the pooling attribute is true by default.
    Scenario 1:
    If I specify externally(through connection string it behaves very badly) like pooling=true in the connection string. It will create more than one session.
    Scenario 2 :
    If I donot specify pooling attribute in connection string it will create only one session and it will consume the same session for all the instance.
    Below is the code snippet
    Here is the example for scenario 2
    private void button3_Click(object sender, EventArgs e)
    //Connection string which donot have a pooling value.
    string strConnection1 = "Persist Security Info=False;User ID= is_customer;Data Source=ISD.World;Connection Lifetime=60;Max Pool Size=30;Min Pool Size=0;PASSWORD=is;";
    using(OracleConnection con = new OracleConnection(strConnection1))
    con.Open();
    MessageBox.Show(GetSID(con));
    //con.Dispose();
    using (OracleConnection con2 = new OracleConnection(strConnection1))
    con2.Open();
    MessageBox.Show(GetSID(con2));
    //con2.Dispose();
    Scenario 1 Example:
    private void button7_Click(object sender, EventArgs e)
    string strConnection1 = "Persist Security Info=False;User ID= is_customer;Data Source=ISD.World;Connection Lifetime=60;Max Pool Size=30;Min Pool Size=0;Pooling=true;PASSWORD=is;";
    using (OracleConnection con = new OracleConnection(strConnection1))
    con.Open();
    MessageBox.Show(GetSID(con));
    //con.Dispose();
    using (OracleConnection con2 = new OracleConnection(strConnection1))
    con2.Open();
    MessageBox.Show(GetSID(con2));
    //con2.Dispose();
    GetSID is the function which is used to fetch the session of the connection string.
    private string GetSID(OracleConnection con)
         OracleCommand cmd = new OracleCommand();
         cmd.Connection = con;
         cmd.CommandText = "select SYS_CONTEXT('USERENV','SID') from dual";
    object sid = cmd.ExecuteScalar();
    return Convert.ToString(sid);
    In Scenario 2 example I will get only one session ID.
    But in Scenarion 1 example I will get different session ID’s.
    Please suggest what is the problem.
    Message was edited by:
    user476285

Maybe you are looking for