Results 1 to 16 of 16

Thread: multiple gui

  1. #1
    samanyu is offline Member
    Join Date
    Jun 2011
    Location
    Tsukuba, Japan
    Posts
    63
    Rep Power
    0

    Default multiple gui

    Hi all,
    I know this may have been asked a zillion times, but I couldn't find any direct replies in my search.
    My question is, suppose i use a main GUI(GUI1) button to open another GUI, say GUI2, how do I close GUI2 without closing GUI1?

    Restated, I only want one GUI window to close, the remaining to stay open. That includes if i want to close GUI3 and not GUI2, even if i used GUI2 to call GUI3.
    Closing GUI1 should be definitive, ofcourse.

    Please help.
    Thanks.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default

    Have you tried using the setVisible method?

  3. #3
    samanyu is offline Member
    Join Date
    Jun 2011
    Location
    Tsukuba, Japan
    Posts
    63
    Rep Power
    0

    Default

    i think i found a cross post. i'll close this thread and come back later if necessary.
    i haven't. i will though, thanks.

  4. #4
    samanyu is offline Member
    Join Date
    Jun 2011
    Location
    Tsukuba, Japan
    Posts
    63
    Rep Power
    0

    Default

    actually, help me out, if i use the close button, how do i call setVisible? what is the mouse event code?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default

    how do i call setVisible?
    Have you looked up that method in the API documentation? That should explain how to use it.

    what is the mouse event code?
    How is this related to closing a window?

  6. #6
    samanyu is offline Member
    Join Date
    Jun 2011
    Location
    Tsukuba, Japan
    Posts
    63
    Rep Power
    0

    Default

    what is the mouse event code?
    i don't know. the code in the constructor for the main class is exit_on_close. its generated by a click on the x box on the JFrame. so i figured i might need an event trigger for the set Visible.
    i have a lot to learn!! :)

  7. #7
    samanyu is offline Member
    Join Date
    Jun 2011
    Location
    Tsukuba, Japan
    Posts
    63
    Rep Power
    0

    Default

    this is the code i use now. "setDefaultCloseOperation(EXIT_ON_CLOSE);"
    what do i change it with?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default

    Time to read the API doc for the method you are using to see what options it has.

  9. #9
    samanyu is offline Member
    Join Date
    Jun 2011
    Location
    Tsukuba, Japan
    Posts
    63
    Rep Power
    0

    Default

    got it. thanks for not giving me the easy way out. :D

    also could you suggest a method for converting a regular rectangular grid of (i,j) to a hex grid of (i,j)?

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default

    method for converting a regular rectangular grid of (i,j) to a hex grid of (i,j)
    Please define in java code a regular grid and a hex grid. I have no idea what you mean by those terms.

  11. #11
    samanyu is offline Member
    Join Date
    Jun 2011
    Location
    Tsukuba, Japan
    Posts
    63
    Rep Power
    0

    Default

    this is the code i have use.
    public void paintComponent( Graphics g ){ // main rendering recipe
    Graphics2D g3 = (Graphics2D)g;
    g3.setColor( Color.black );
    g3.fillRect( 0, 0, getWidth()-1, getHeight()-1 );
    int w = 810 / (810/30);
    int h = 630 / (630/30);
    for(int col=0;col<(810/30);col++){
    for(int row=0;row<(630/30);row++){
    for(int k=0; k<works1.l; k++){
    if( jiffy.rulbas[col][row] == k){
    g3.setColor(jiffy.colors[k]);
    repaint();

    } g3.fillRect( col * w +1, row * h +1, w-2, h-2 );

    } }}
    it creates a rectangular grid on a display window.
    i need to create a hexgrid. and i am having difficulty visualising the pixels, and also drawing the hexagon itself.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default

    What is a hex grid? Do you have an algorithm or design for drawing one? Not really part of java coding.

    To compile and execute this code, you need a definition for jiffy

  13. #13
    samanyu is offline Member
    Join Date
    Jun 2011
    Location
    Tsukuba, Japan
    Posts
    63
    Rep Power
    0

    Default

    the code is executing. a hex grid, is one like in this picture: Google Image Result for http://www.thealmightyguru.com/Humor/Inventions/Images/Grid-Hex.gif

    i do have an algorithm, but it might take time to dig it up. i will post it tomorrow, its past 12 here in japan.
    thanks for your help.

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    gamedev.net used to have some articles on drawing hex maps, and using masks to figure out which hex a user has clicked on.
    I would suggest using an image file for the hexes. It's a lot easier.

  15. #15
    zzuum is offline Member
    Join Date
    May 2011
    Posts
    8
    Rep Power
    0

    Default

    I just had a post like this; I wanted to have a JFrame (in swing) and multiple JPanels. Just remove the current JPanel when a button is clicked and add another one.

  16. #16
    loopsnhoops is offline Member
    Join Date
    Feb 2011
    Posts
    83
    Rep Power
    0

    Default

    to get rid of the GUIs JFrame just use the method: frame.dispose();

Similar Threads

  1. Multiple iframes
    By Pablo3728 in forum Java Servlet
    Replies: 5
    Last Post: 09-21-2010, 02:30 AM
  2. Running multiple threads on multiple CPU cores?
    By Dosta in forum Threads and Synchronization
    Replies: 2
    Last Post: 09-19-2010, 03:48 PM
  3. Multiple SwingWorkers
    By Arne in forum Threads and Synchronization
    Replies: 12
    Last Post: 08-26-2010, 02:54 AM
  4. Multiple Users
    By peiceonly in forum Threads and Synchronization
    Replies: 5
    Last Post: 06-09-2008, 09:17 AM
  5. Multiple Inheritance
    By mew in forum New To Java
    Replies: 1
    Last Post: 12-01-2007, 10:04 PM

Tags for this Thread

Posting Permissions

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