java - Border and Flow Layouts -


okay, i'm having trouble programming exercise today.

the exercise text goes this:

(use flowlayout manager) write program meets following requirements:

  • create frame , set layout flowlayout
  • create 2 panels , add them frame
  • each panel contains 3 buttons. panel uses flowlayout

the buttons should named "button 1", "button 2" , on. (i completed original code)

now needed change code borderlayout while moving 1 panel south, , other center, tried doesn't seem come out correctly. buttons on top , bottom.

original code (flowlayout):

import javax.swing.*; import java.awt.*;  public class lab5_1 extends jframe {      public lab5_1() {         setlayout(new flowlayout());          // create 2 panels         jpanel panel1 = new jpanel();         jpanel panel2 = new jpanel();           // add 3 buttons each panel         panel1.add(new jbutton(" button 1 "));         panel1.add(new jbutton(" button 2 "));         panel1.add(new jbutton(" button 3 "));         panel2.add(new jbutton(" button 4 "));         panel2.add(new jbutton(" button 5 "));         panel2.add(new jbutton(" button 6 "));           // add panels frame         add(panel1);         add(panel2);      }      public static void main(string[] args) {         lab5_1 frame = new lab5_1();         frame.settitle(" exercise 12_1 ");         frame.setsize(600,75);         frame.setlocationrelativeto(null); // center frame         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.setvisible(true);     } } 

my attempt @ borderlayout:

public class lab5_2 extends jframe {      public lab5_2() {     setlayout(new borderlayout());       // create 2 panels         jpanel panel1 = new jpanel();         jpanel panel2 = new jpanel();           // add 3 buttons each panel         panel1.add(new jbutton(" button 1 "));         panel1.add(new jbutton(" button 2 "));         panel1.add(new jbutton(" button 3 "));         panel2.add(new jbutton(" button 4 "));         panel2.add(new jbutton(" button 5 "));         panel2.add(new jbutton(" button 6 "));          //add panel frame         add(panel1, borderlayout.center);         add(panel2, borderlayout.south);     }       public static void main(string[] args) {         lab5_2 frame = new lab5_2();         frame.settitle(" exercise 12_2 ");         frame.setsize(200, 200);         frame.setlocationrelativeto(null); // center frame         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.setvisible(true);     } } 

the center area gets of available space possible. other areas expand as necessary fill available space.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -