CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2011
    Posts
    26

    [RESOLVED] swing case-JFrame

    can anyone tell me how to attach one JFrame to another one??....


    I mean if i have a frame including a button and when i press that button it should take me to the next frame....

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: swing case-JFrame

    can anyone tell me how to attach one JFrame to another one
    JFrames are top level windows and so you can't attach them to other frames. You can however create a new JFrame from the button's action and display it in the same way you created your initial JFrame. If you want to display a new window that is a child of your existing JFrame then use a JDialog.

    when i press that button it should take me to the next frame
    What do you mean by "take me to the next frame"?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Dec 2011
    Posts
    26

    Smile Re: swing case-JFrame

    What do you mean by "take me to the next frame"?

    i meant that it should take me to the next window(frame)....

    thanks for the advice keang....
    Can you tell me some sources for learning the "java GUI"....

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: swing case-JFrame

    i meant that it should take me to the next window(frame)
    Saying the same thing again doesn't make it any more understandable.

    Can you tell me some sources for learning the "java GUI"....
    Google
    The java tutorial
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  5. #5
    Join Date
    Dec 2011
    Posts
    26

    Question Re: swing case-JFrame

    As you said keang i'm going through the java tutorials....
    but i'm stopped for a while because i'm not able to load an image into my program from my computer....
    so can you tell me how to load the image....

  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: swing case-JFrame

    Unless you give more information on what you are trying to do it's hard to give specific advice.

    Recently I posted code on loading an image into a JPanel. Look back through my recent posts or click on the link in my signature below - where it says "Click here for examples of Java Code"
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  7. #7
    Join Date
    Dec 2011
    Posts
    26

    Question Re: swing case-JFrame

    i just went through your code "Background image panel"....
    in the "usage" section,there's a following code....

    Code:
    ImagePanel ip = new ImagePanel("myImage.jpg", false);
        f.add(ip);
    so my question is where did you get the myImage.jpg from?? i mean where it is stored in your computer and how to get it in the program....or do i have to move/copy it to some particular location??....

  8. #8
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: swing case-JFrame

    You just have to supply the path to the file. This can be either a relative path or an absolute path ie:

    Code:
    ImagePanel ip = new ImagePanel("images/myImage.jpg", false);
    Or
    Code:
    ImagePanel ip = new ImagePanel("c:/myProject/images/myImage.jpg", false);
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  9. #9
    Join Date
    Dec 2011
    Posts
    26

    Smile Re: swing case-JFrame

    i used your code and i got the image....
    then i tried another code....it was given in the java tutorial....

    Code:
           BufferedImage img = null;
    try {
        img = ImageIO.read(new File("Sample Pictures/Desert.jpg"));
    } catch (IOException e) {
    }
    can you explain me this code and particularly the following code....

    Code:
    catch (IOException e) {
    }

  10. #10
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: swing case-JFrame

    Code:
    img = ImageIO.read(new File("Sample Pictures/Desert.jpg"));
    is slightly easier to understand if rewritten like this
    Code:
    File imgFile = new File("Sample Pictures/Desert.jpg");
    img = ImageIO.read(imgFile);
    The code creates a File object for the file specified by the relative path "Sample Pictures/Desert.jpg". It then passes this File object to the ImageIO classes read() method to obtain a BufferedImage object for this file.

    Everything else is exception handling - google for Java exception handling.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured