Results 1 to 11 of 11
  1. #1
    ashton is offline Member
    Join Date
    Jan 2009
    Posts
    31
    Rep Power
    0

    Default need help in uploading images in swing program!!!

    Hi guys!

    i am quite a noob in java... don't worry, i got the basics already...
    uhm... I just want to ask this question:
    'How do you make a program not terminate imediately once you clicked a button?...

    Grrr.. let me try to explain it this way....

    uhmm... I'm working on a simple project that says, "My Profile Manager"..
    This program has fields for the user's name, age, etc, something like that...

    I'm just a noob so, the project only works one-way... meaning, the profile of certain people are built-in within the program...

    This is what happens, when a person enters his name, age, etc,... His picture will show up beside the textfields... (I got that already)...

    This is simple but my problem is, once I clicked the button, for the first time, it works.... but when i try to type another name, the picture doesn't change... I know I'm missing something here... please help????:confused:
    Last edited by ashton; 01-26-2009 at 06:49 AM.

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    its difficult to help w/o seeing the codes.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    ashton is offline Member
    Join Date
    Jan 2009
    Posts
    31
    Rep Power
    0

    Default ok.. just focus on the colored lines...

    Java Code:
     
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){                                         
     
           String name = nameField.getText();
           String age = ageField.getText();
    
    
            if(name == "John"){
                jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/swingPack/joham.jpg")));
            }else if(name == "Smiley"){
                jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/swingPack/smiley.jpg")));
            }
          }
          //[COLOR="DarkGreen"]-> the problem here is, when i type a name for the first time, a new photo will show up... but when I type a new name which supposedly corresponds to a different photo, the previous photo that showed up doesn't change...[/COLOR]


    this is my code under my Button's action...

  4. #4
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    If you want to upload the image,do you want to insert into the database?There are many ways.Search for the com.oreilly package for uploading data, it uses MultipartRequest .

  5. #5
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    try this
    1) use name.equal("...") NOT name == ...

    2) why don't you just use this:
    jLabel2.setIcon(new ImageIcon("swingPack/smiley.jpg"));
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  6. #6
    ashton is offline Member
    Join Date
    Jan 2009
    Posts
    31
    Rep Power
    0

    Default the button is my problem...

    sorry guys... I can't explain it clearly... but what i am trying to say is that, the button works only once... how can i make it work again and again and again??

  7. #7
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Actually button works each time you click it, but label is not changed. You should repaint your label, each time you click the button.

  8. #8
    ashton is offline Member
    Join Date
    Jan 2009
    Posts
    31
    Rep Power
    0

    Default ohhhhhhh.....

    :eek: gak! gak! gak! gak! I forgot that! tnx pal! I really really thank you for this! :D I almost forgot that... yup... repaint.... tnx a lot!!!!

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  10. #10
    ashton is offline Member
    Join Date
    Jan 2009
    Posts
    31
    Rep Power
    0

    Default whoopss...

    Sorry ERANGA... won't do this again... i was just afraid that the first one i posted is kinda hard to understand... just tried to explain it in a simpler way...

    Next time, i promise..won't make two threads with one topic...

    :)

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Hwlp with "Open", "Save", "Save as..."
    By trill in forum New To Java
    Replies: 3
    Last Post: 11-02-2010, 09:26 AM
  2. How can i save the data Internally(auto save)
    By Rama Koti Reddy in forum AWT / Swing
    Replies: 2
    Last Post: 11-01-2010, 08:31 PM
  3. How to save name in Array and Print saved Name
    By ppkkyaw in forum New To Java
    Replies: 4
    Last Post: 06-15-2008, 06:44 AM
  4. How can I save my XML
    By FrankyDee in forum XML
    Replies: 1
    Last Post: 03-27-2008, 03:59 PM
  5. How do I create an Array of Images
    By wco5002 in forum New To Java
    Replies: 3
    Last Post: 03-21-2008, 03:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •