#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    5
    Rep Power
    0

    Talking newbie java questions


    Hi,

    I have 2 java questions, and because i'm a bit of a newbie programmer i'd like it if gave examples with any explanations!

    1) In an applet, how do i set it so that after an event (like a button click) the GUI gets replaced by a different GUI? so all the previous buttons/textfields/prompts etc are replaced by different buttons and textfields

    2) I have an array of objects. This object has 19 arguments (!). Do you think this is too disorganized? and if so, how could i organize it? It's part of a university assignment so readability of code is certainly important.
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    1) You might try having a function that does getContentPane().removeAll(), the adding your new components. Either one function for each layout or one function that lets you choose layouts.

    You could also a Container object for each layout you want then use setContentPane() to switch between them.

    2) Yes, that sounds rather disorganized. Any way you can break that down into multiple classes? If not, well, make sure you document it well
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    5
    Rep Power
    0
    1) You might try having a function that does getContentPane().removeAll(), the adding your new components. Either one function for each layout or one function that lets you choose layouts.
    hmm...care to give an example?
  6. #4
  7. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Code:
    public layout2() {
      JLabel label = new JLabel("Dude!");
      label.setHorizontalAlignment(JLabel.CENTER);
      label.setBorder(BorderFactory.createMatteBorder(1,1,2,2,Color.black));
    
      getContentPane().removeAll();
    
      getContentPane().add(label, BorderLayout.CENTER);
    }
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    5
    Rep Power
    0
    sank yuu


IMN logo majestic logo threadwatch logo seochat tools logo