1 / 52

JAVA GUI PROGRAMMING

JAVA GUI PROGRAMMING. 12. JAVA GUI. 12.1 GUI 의 기본 요소 추상 윈도우 툴 킷 (AWT, Abstract Window Toolkit) 을 사용 . AWT 를 사용하기 위해서 다음 두 문장을 포함해야 함 . import java.awt.*; import java.awt.event.*;. 12. JAVA GUI. 12.2 자바의  GUI  컴포넌트. 12. JAVA GUI. 12.2 자바의  GUI  컴포넌트 12.2.1  버튼

Download Presentation

JAVA GUI PROGRAMMING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JAVA GUI PROGRAMMING

  2. 12. JAVA GUI 12.1 GUI의 기본 요소 • 추상윈도우툴킷(AWT,AbstractWindowToolkit)을 사용. • AWT를사용하기위해서다음두문장을포함해야함. importjava.awt.*; importjava.awt.event.*;

  3. 12. JAVA GUI 12.2 자바의 GUI 컴포넌트

  4. 12. JAVA GUI 12.2 자바의 GUI 컴포넌트 • 12.2.1 버튼 -사용자가클릭할수있는기본컴포넌트 -버튼클릭시에ActionEvent발생 • 생성자 ①publicButton() 레이블이없는버튼을생성한다. ②publicButton(Stringlabel) label을레이블로 갖는버튼을생성한다. • 지원되는메소드 ①publicStringgetLabel() 버튼의이름인레이블을 반환한다. ②publicvoidsetLabel(Stringlabel) 버튼의이름인 레이블을설정한다.

  5. 12. JAVA GUI [예제코드] importjava.awt.*; importjava.awt.event.*;//ActionListener를구현하기위해필요. importjava.applet.Applet; publicclassButtonAppletextendsAppletimplementsActionListener { Buttonbutton1,button2; Stringmsg=""; publicvoidinit(){ button1=newButton("First"); button1.addActionListener(this);//버튼1을리스너에등록. button1.setActionCommand("One");//액션명령어 “One” 설정 button2=newButton("Second"); button2.addActionListener(this);//버튼2를리스너에등록. button2.setActionCommand("Two"); add(button1);add(button2); } //버튼1과2를애플릿에포함.

  6. 12. JAVA GUI [예제코드] publicvoidactionPerformed(ActionEvente){ Stringcmd=e.getActionCommand(); //버튼에연결된액션명령문자열을변수cmd에저장한다. if(cmd.equals("One")){msg="One"; } elseif(cmd.equals("Two")){msg="Two";} repaint();//applet을다시디스플레이한다. } publicvoidpaint(Graphicsg){ g.drawString(msg,10,70); }

  7. 12. JAVA GUI • 12.2.2 텍스트 필드(TextField) -문자열을입력받거나,실행결과를출력할때사용 -텍스트필드에서엔터키를키면ActionEvent가발생 • 생성자 ①publicTextField() 새로운텍스트필드를생성한다. ②publicTextField(intcols) 주어진컬럼수를가진텍스트필드를생성한다. ③publicTextField(StringText) 주어진텍스트로초기화된텍스트필드를생성한다. ④publicTextField(intcols,StringText) 기술된Text와크기cols로초기화된텍스트필드를 생성한다.

  8. 12. JAVA GUI • 12.2.2 텍스트 필드(TextField) • 지원되는메소드 ①publicbooleanechoCharsSet() 에코문자셋을가진경우true를,그렇지않은경우 false를반환한다. ②publicintgetColums() 해당텍스트필드의객체가가진컬럼수를반환한다. ③publicchargetEchoChar() 에코로사용되는문자를반환한다. ④protectedStringparamString() 해당텍스트필드의문자열을반환한다. ⑤publicvoidsetEchoCharacter(Charc); 해당텍스트필드의에코문자를설정한다.

  9. 12. JAVA GUI [예제코드] importjava.awt.*; importjava.awt.event.*; importjava.applet.Applet; publicclassTextFieldAppletextendsApplet implementsActionListener{ TextFieldtf1,tf2; publicvoidinit(){ tf1=newTextField("Keyinyourmessage",16); tf1.addActionListener(this);//텍스트필드tf1의이벤트를등록 tf2=newTextField("Hello!!",16); tf2.addActionListener(this);//텍스트필드tf2의이벤트를등록 add(tf1);//applet에텍스트필드tf1,tf2를포함시킴. add(tf2); }

  10. 12. JAVA GUI [예제코드] publicvoidactionPerformed(ActionEvente){ if(e.getSource()instanceofTextField){ TextFieldt=(TextField)e.getSource(); if(t==tf1){//이벤트가발생한텍스트필드를확인함 tf2.setText(t.getText()); tf1.setText("");//tf1에있었던모든문자를삭제함 }elseif(t==tf2){ tf1.setText(t.getText()); tf2.setText(""); }}}}

  11. 12. JAVA GUI • 12.2.3 체크박스와 라디오 버튼 • 생성자 ①publicCheckbox() 레이블이없고,초기값이false인체크박스를생성한다. ②publicCheckbox(Stringlabel) 레이블이문자열label인체크박스를생성한다. ③publicCheckbox(Stringlabel,CheckboxGroupgroup, booleanstate) 레이블이label이고초기상태가state이며그룹이group인 라디오버튼을생성한다.

  12. 12. JAVA GUI • 12.2.3 체크박스와 라디오 버튼 • 메소드 ①publicvoidaddNotify() 체크박스의모양을 변경할수있도록피어(peer)를설정한다. ②publicStringgetLabel() 체크박스의레이블문자열을반환한다. ③publicbooleangetState() 체크박스의상태를반환한다. ④publicvoidsetLabel() 체크박스의레이블을설정한다. ⑤publicvoidsetState() 체크박스의상태를설정한다. ⑥publicCheckboxgetCurrent() 현재선택한체크박스를반환한다. ⑦publicStringtoString() 체크박스그룹을나타내는문자열을반환한다.

  13. 12. JAVA GUI [체크박스예제코드] importjava.awt.*; importjava.awt.event.*; importjava.applet.Applet; publicclassCheckboxAppletextendsApplet implementsItemListener{ Checkboxch1,ch2,ch3; TextFieldtf; Stringmsg="Checkbox"; publicvoidinit() { ch1=newCheckbox("one");//체크박스3개생성 ch2=newCheckbox("two"); ch3=newCheckbox("three"); ch1.addItemListener(this);//체크박스의이벤트를등록한다. ch2.addItemListener(this); ch3.addItemListener(this); tf=newTextField(20);

  14. 12. JAVA GUI [체크박스예제코드] add(ch1); add(ch2); add(ch3); add(tf); } publicvoiditemStateChanged(ItemEvente){ if(e.getItem().equals("one")) {msg=msg+"1";} elseif(e.getItem().equals("two")) {msg=msg+"2";} else{msg=msg+"3";} if(e.getStateChange()==ItemEvent.SELECTED){ msg=msg+"isselected"; }else{msg=msg+"isde-selected";} tf.setText(msg); msg="Checkbox"; } }

  15. 12. JAVA GUI [라디오버튼예제코드] importjava.awt.*; importjava.awt.event.*; importjava.applet.Applet; publicclassRadioButtonextendsAppletimplementsItemListener{ CheckboxGroupradio1; Checkboxch1,ch2,ch3; TextFieldtf; Stringmsg="Checkbox"; publicvoidinit(){ radio1=newCheckboxGroup(); //ch1,ch2,ch3는동일한그룹으로하나만이선택가능하다. ch1=newCheckbox("one",radio1,true); ch2=newCheckbox("two",radio1,false); ch3=newCheckbox("three",radio1,false); //ch1,ch2,ch3의이벤트를등록한다. ch1.addItemListener(this);

  16. 12. JAVA GUI [라디오버튼예제코드] ch2.addItemListener(this); ch3.addItemListener(this); tf=newTextField(20); add(ch1);add(ch2); add(ch3);add(tf); } publicvoiditemStateChanged(ItemEvente){ if(e.getItem().equals("one")){msg=msg+"1";} elseif(e.getItem().equals("two")){msg=msg+"2";} else{msg=msg+"3";} if(e.getStateChange()==ItemEvent.SELECTED){ msg=msg+"isselected"; } tf.setText(msg); msg="Checkbox"; }

  17. 12. JAVA GUI • 12.2.4 레이블 • 생성자 ①Label() 출력할문자열이없는레이블을생성한다. ②Label(Stringtext) 문자열text를출력하는레이블을생성한다. ③Label(Stringtext,intalignment). 문자열을정렬할위치를결정할수있는생성자이다. alignment:Label.RIGHT,Label.CENTER,Label.LEFT

  18. 12. JAVA GUI [레이블예제코드] importjava.awt.*; importjava.applet.Applet; publicclassLabelDemoextendsApplet{ Labell1,l2,l3; publicvoidinit(){ l1=newLabel("Label_Left",Label.LEFT); l2=newLabel("Label_Center",Label.CENTER); l3=newLabel("Label_Right",Label.RIGHT); add(l1); add(l2); add(l3); } }

  19. 12. JAVA GUI • 12.2.5 스크롤 바(scroll bar) • 생성자 ①publicScrollbar() 스크롤바를만든다. ②publicScrollbar(intorientation) 지정된방향의스크롤바를만든다. orientation의값은HORIZONTAL또는VERTICAL이다. ③publicScrollbar(intorientation,intvalue,intvisible, intminimum,intmaximum) -intvalue:스크롤바의초기값을나타낸다. -intvisible:화면에표시되는스크롤바의크기를 나타낸다. -intminimum:스크롤바의최소값을나타낸다. -intmaximum:스크롤바의최대값을나타낸다.

  20. 12. JAVA GUI • 12.2.5 스크롤 바(scroll bar) • 메소드 ①publicintgetLineIncrement() 현재화면에나타나지않은한라인이위로스크롤된다. ②publicintgetValue() 스크롤바의현재값을반환한다. ③publicvoidsetValue(intvalue) 스크롤바의값을지정된값으로설정한다. ④publicintgetOrientation() 스크롤바의방향을반환한다. ⑤publicvoidsetValues(intvalue,intvisible,intminimum, intmaximum) 스크롤바에대한여러가지값을설정한다.

  21. 12. JAVA GUI [스크롤바예제코드] importjava.awt.*; importjava.awt.event.*; importjava.applet.Applet; PublicclassScrollBarDemoextendsAppletimplements AdjustmentListener{ TextFieldtf1,tf2; Scrollbarhs,vs; publicvoidinit(){ tf1=newTextField(30); tf2=newTextField(30); add(tf1);add(tf2); vs=newScrollbar(Scrollbar.HORIZONTAL,100,100,0,200); vs.addAdjustmentListener(this);

  22. 12. JAVA GUI [스크롤바예제코드] hs=newScrollbar(Scrollbar.VERTICAL,100,100,0,200); hs.addAdjustmentListener(this); add(vs);add(hs); } publicvoidadjustmentValueChanged(AdjustmentEvente) {//스크롤바에서이벤트가발생하면이메소드가호출된다. Scrollbars=(Scrollbar)e.getSource(); if(s.getOrientation()==Scrollbar.HORIZONTAL) {tf1.setText(String.valueOf(s.getValue()));} else {tf2.setText(String.valueOf(s.getValue()));} }}

  23. 12. JAVA GUI • 12.2.6 텍스트 영역 • 생성자 ①publicTextArea() 기본크기를가지는TextArea를생성한다. ②publicTextArea(introws,intcolumns) 원하는줄과열을가진TextArea를생성한다. ③publicTextArea(Strings) 원하는문자열을포함하는TextArea를생성한다. ④publicTextArea(Strings,introws,intcolumns) 원하는문자열과크기를가진TextArea를생성한다. ⑤publicTextArea(Strings,introw,intcolum,intscrollbar) 변수scrollbar는SCROLLBARS_BOTH,SCROLLBARS_HORIZONT AL_ONLY,SCROLLBARS_NON,SCROLLBARS_VERTICAL_ ONLY중의하나

  24. 12. JAVA GUI • 12.2.6 텍스트 영역 • 메소드 ①publicvoidinsertText(Stringstr,intpos) 원하는위치pos에문자열을삽입하는메소드이다. ②publicvoidappendText(Stringstr) 텍스트영역의끝에문자열을추가하는메소드이다. ③publicvoidreplaceText(Stringstr,intstart,intend) 원하는위치의문자열을문자열str로변경하는메소드이다. ④publicintgetRows() 텍스트영역의row(행)의수를반환한다. ⑤publicintgetColumns() 텍스트영역의column(열)의수를반환한다.

  25. 12. JAVA GUI [예제코드] importjava.applet.Applet; importjava.awt.*; importjava.awt.event.*; classTextAreaDemoextendsApplet implementsTextListener{ TextAreats,td; publicvoidinit(){ ts=newTextArea("keyinsentence",5,20); ts.addTextListener(this); add(ts); td=newTextArea(5,20); td.setEditable(false); add(td); }

  26. 12. JAVA GUI [예제코드] publicvoidtextValueChanged(TextEvente){ TextComponentsource=(TextComponent)e.getSource(); td.setText(source.getText()); } }

  27. 12. JAVA GUI • 12.2.7 Choice(선택) 버튼 • 생성자 ①publicChoice() • 메소드 ①publicintcountItems() Choice객체에서선택가능한항목의수를반환한다. ②publicStringgetItem(intindex) index가가리키는항목을반환한다(맨앞의항목의index는0이다). ③publicsynchronizedvoidaddItem(Stringitem) Choice객체에선택가능한항목(item)을추가한다. ④publicStringgetSelectedItem()현재선택된항목을반환한다. ⑤publicintgetSelectedIndex()현재선택된항목의index를반환한다. ⑥publicsynchronizedvoidselect(intpos) 인자pos가가리키는항목을선택하는메소드이다. ⑦publicsynchronizedvoidselect(Stringstr) 문자열str과동일한항목을선택하는메소드이다.

  28. 12. JAVA GUI [예제코드] importjava.applet.Applet; importjava.awt.*; importjava.awt.event.*; publicclassChoiceDemoextendsApplet implementsItemListener{ Choicec1; publicvoidinit(){ c1=newChoice(); c1.addItem("ComputerEngineering"); c1.addItem("Multimedia"); c1.addItem("ComputerCommunication"); c1.addItem("DataBaseDesign"); c1.select(2);//초기값을ComputCommunication으로선택 c1.addItemListener(this);//Choice객체의이벤트등록 add("Major",c1); }

  29. 12. JAVA GUI [예제코드] publicvoiditemStateChanged(ItemEvente){ Choicetmp=(Choice)e.getItemSelectable(); showStatus(tmp.getSelectedItem()+"selected"); //상태바의메시지출력 } }

  30. 12. JAVA GUI • 12.2.8 List • 생성자 ①publicList() 기본값을가진List를생성 ②publicList(introws,booleanmultipleSelections) 생성될List객체의라인수 및여러항목을선택가능하게할것인지를설정 • 메소드 ①publicintcountItems() 리스트안에있는항목의수를반환한다. ②publicStringgetItem(intindex) index가가리키는항목을반환한다. ③publicsynchronizedvoidaddItem(Stringitem) 리스트객체의맨끝에항목을추가한다. ④publicsynchronizedvoidreplaceItem(StringnewValue,intindex) index가가리키는항목을newValue로교체한다.index는정수로서,변경을원하는항목의첨자이다.index의값이-1의값을가지거나리스트안의 항목의번호보다큰경우리스트의맨끝에항목이추가된다. ⑤publicsynchronizedvoidclear() 리스트객체의모든항목을삭제한다. ⑥publicsynchronizedvoiddelItem(intposition) 리스트객체에서position이가리키는항목을삭제한다.

  31. 12. JAVA GUI [예제코드] importjava.applet.Applet; importjava.awt.*; importjava.awt.event.*; publicclassListDemoextendsAppletimplementsActionListener{ privateListfromList,toList; privateButtoncopyButton; privateStringmajorNames[]= {"game","multimedia","SE","Com.Arch.", "internet","websearch","graphics","AI", "neuralnet","database","edutainment","OS"}; publicvoidinit() {//createalistwith5itemsvisible,allowmultipleselections fromList=newList(5,true); //additemstothelist for(inti=0;i<majorNames.length;i++) fromList.add(majorNames[i]);

  32. 12. JAVA GUI [예제코드] add(fromList);//createcopybutton copyButton=newButton("Copy->"); copyButton.addActionListener(this); add(copyButton); //createalistwith5itemsvisible //donotallowmultipleselections toList=newList(5,false); add(toList); } publicvoidactionPerformed(ActionEvente) {Stringcolors[];//gettheselectedstates colors=fromList.getSelectedItems(); //clearallitemsintherightlist toList.clear();//copythemtocopyList for(inti=0;i<colors.length;i++) toList.add(colors[i]); }}

  33. 12. JAVA GUI • 12.3 레이아웃 관리하기 ①pubicvoidsetLayout(LayoutManagermgr) 레이아웃을설정하는메소드이다. ②publicsynchronizedvoidvalidate() 컨테이너와포함된모든요소들을다시디스플레이한다. ③publicLayoutManagergetLayout() 컨테이너에설정된레이아웃을반환한다.

  34. 12. JAVA GUI • 12.3.1 FlowLayout • 생성자 ①publicFlowLayout() 기본적으로요소들이중앙에정렬하도록한다. ②publicFlowLayout(intalignment) alignment의값에따라요소를배치시킨다. alignment는 FlowLayout.Left,FlowLayout.Right,FlowLayout.Center ③publicFlowLayout(intalignment,inthorizon_gap,intvert_gap) 요소의배치기준및요소간의수평거리및수직거리를명시

  35. 12. JAVA GUI [예제코드] publicclassFlowDemoextendsAppletimplementsActionListener{ privateButtonl,c,r; publicvoidinit() {l=newButton("Left"); l.addActionListener(this); add(l); c=newButton("Center"); c.addActionListener(this); add(c); r=newButton("Right"); r.addActionListener(this); add(r); }

  36. 12. JAVA GUI [예제코드] publicvoidactionPerformed(ActionEvente) {intalign; if(e.getSource()==l)align=FlowLayout.LEFT; elseif(e.getSource()==c)align=FlowLayout.CENTER; elsealign=FlowLayout.RIGHT; setLayout(newFlowLayout(align)); validate();//refreshcomponents } }

  37. North West Center East South 12. JAVA GUI • 12.3.2 BorderLayout • 생성자 ①publicBorderLayout() BorderLayout클래스를생성한다. ②publicBorderLayout(inthorizontal_gap,intvertical_gap) 수평간격과수직간격을설정한BorderLayout클래스를생성한다. - BorderLayout의위치

  38. 12. JAVA GUI [예제코드] importjava.applet.*; importjava.awt.*; publicclassBorderLayoutDemoextendsApplet{ publicvoidinit(){ setLayout(newBorderLayout(8,2)); add(newButton("North"),BorderLayout.NORTH); add(newButton("South"),BorderLayout.SOUTH); add(newButton("Center"),BorderLayout.CENTER); add(newButton("West"),BorderLayout.WEST); add(newButton("East"),BorderLayout.EAST); } }

  39. 12. JAVA GUI • 12.3.3 GridLayout • 생성자 ①publicGridLayout(introws,intcols) 줄수와칸수를지정한GridLayout클래스를생성한다. ②publicGridLayout(introws,intcols,inthorizon_gap,intvert_gap) 줄수,칸수,수평및수직간격을지정한GridLayout클래스를생성한다.

  40. 12. JAVA GUI [예제코드] importjava.applet.*; importjava.awt.*; publicclassGridLayoutDemoextendsApplet{ publicvoidinit(){ //3줄4칸,가로간격4,세로간격1 setLayout(newGridLayout(3,4,4,1)); add(newButton("1")); add(newButton("2")); add(newButton("3")); add(newButton("4")); add(newButton("5")); add(newButton("6")); add(newButton("7")); add(newButton("8")); add(newButton("9")); add(newButton("0")); add(newButton("+")); add(newButton("=")); } }

  41. 12. JAVA GUI • 12.3.4 CardLayout • 생성자 ①publicCardLayout() 기본값을가진CardLayout을생성한다. ②publicCardLaout(inthgap,intvgap) 지정된수직간격과수평간격을가진CardLayout을생성한다. 사용예) L1=newLabel("Memory:"); L2=newLabel("Printer:"); Panelp1=newPanel(); p1.setLayout(newCardLayout());//p1을card-layout으로설정 p1.add(L1,L1.getText()); p1.add(L1,L1.getText());

  42. 12. JAVA GUI [예제코드] importjava.awt.*; importjava.awt.event.*; publicclassCardLayoutDemoextendsjava.applet.Applet implementsActionListener,MouseListener{ Labelsunos,Win98,linux; PanelosCards; CardLayoutcardLO; ButtonWin,Sun; publicvoidinit(){ Win=newButton("MS-Windows"); Sun=newButton("SunOS"); add(Win); add(Sun);//두개의버튼Win과Sun을만들어붙임 cardLO=newCardLayout(); osCards=newPanel();//osCards라는panel을생성 osCards.setLayout(cardLO);//osCards를cardlayout으로설정

  43. 12. JAVA GUI [예제코드] Win98=newLabel("Windows98&NT"); sunos=newLabel("SunOS&Solaris"); linux=newLabel("Linux6.0"); osCards.add(Win98,"Windows"); osCards.add(sunos,"Sun"); osCards.add(linux,"linux");//세개의레이블을osCard에부착함 add(osCards);//panelosCard를애플릿에부착함 Win.addActionListener(this);//버튼의리스너등록 Sun.addActionListener(this); addMouseListener(this); } publicvoidmousePressed(MouseEventme){ cardLO.next(osCards);//마우스를클릭하면다른카드를보여줌 }

  44. 12. JAVA GUI [예제코드] publicvoidmouseClicked(MouseEventme){} publicvoidmouseEntered(MouseEventme){} publicvoidmouseExited(MouseEventme){} publicvoidmouseReleased(MouseEventme){} publicvoidactionPerformed(ActionEventae){ if(ae.getSource()==Win){cardLO.show(osCards,"Windows");} else{cardLO.show(osCards,"Sun");} } }

  45. 12. JAVA GUI • 12.3.5 GridBagLayout • 특징 ①컴포넌트는그리드에서하나이상의방(cell)을차지할수있다. ②서로다른행,열들의크기를서로다르게지정할수있다. ③그리드셀내의컴포넌트들이서로다른방식으로정렬될수있다. - GridBagLayout설정절차 ①GridBagLayout객체를생성하고생성된객체를레이아웃관리자로등록 (코드예)GridBagLayoutg1=newGridBagLayout(); setLayout(g1); ②GridBagCaonstraints의객체및컴포넌트객체들을생성한다. (코드예)GridBagConstraintsc1=newGridBagConstraints(); Buttonb1=newButton("Compute"); Buttonb2=newButton("Cancel");

  46. 12. JAVA GUI • 12.3.5 GridBagLayout - GridBagLayout설정절차 ③컴포넌트에대한위치,크기에대한값을조정한다. GridBagConstraints객체의내부변수 gridx,gridy,gridwidth,gridheight,weightx,weighty사용 (코드예)c1.gridx=0; c1.gridy=0; c1.gridwidth=1; c1.gridwidth=1; c1.weightx=20; c1.weighty=10; ④컴포넌트와constraint값을설정한후,컨테이너에컴포넌트 를추가 (코드예)g1.setConstraints(b1,c1); add(b1);

  47. 12. JAVA GUI • 12.3.5 GridBagLayout • GridBagConstraints ①publicintgridx,gridy ②gridwidth,gridheight -컴포넌트가가로와세로로각각몇개의셀을차지할것인가지정. ex) -가로와세로로각각한셀을차지하는컴포넌트는(1,1) -가로만2개의셀을.세로는한셀을차지하는컴포넌트는(2,1)

  48. A (10, 10) A (10, 10) A (10, 20) B (10, 10) B (20, 10) B (20, 0) C (10, 10) C (0, 10) C (0, 10) D (10, 10) D (0, 10) D (0, 0) 12. JAVA GUI • 12.3.5 GridBagLayout • GridBagConstraints ③weightx,weighty -이두변수는다른행,열들과비교하여행과열의비를결정 ex)모든컴포넌트의weightx와weighty의값이10으로동일함 모두동일한비율의크기 ex)컴포넌트A의폭을B보다1:2의비율로설정. ex) -weightx의값을0으로지정한이유는 “ditto(상동)”이라는의미 -위에서정의한x방향의폭과동일함을의미

  49. 12. JAVA GUI • 12.3.5 GridBagLayout • GridBagConstraints ④fill -fill변수는컴포넌트가셀안에서늘어나는방향을결정 -GridBagConstraints.BOTH:컴포넌트가상하좌우모두늘어남 -GridBagConstraints.HORIZONTAL:컴포넌트가좌우로늘어남 -GridBagConstraints.VERTICAL:컴포넌트가상하로늘어남 -GridBagConstraints.NONE:컴포넌트가최소의크기로. ⑤insets -컴포넌트와컴포넌트를둘러싸고있는영역간의간격설정. ⑥anchor -anchor변수는셀의크기보다작은컴포넌트위치결정. -anchor의값 CENTER(기본값),NORTH,NORTHEAST,EAST, SOUTHEAST,SOUTH,SOUTHWEST,WEST,NORTHWEST ⑦ipadx,ipady -컴포넌트주변의빈공간을설정 -ipadx는컴포넌트좌우의여분공간설정 -ipady는컴포넌트상하의여분공간을설정

  50. 12. JAVA GUI [예제프로그램] importjava.awt.*; publicclassGridBagDemoextendsjava.applet.Applet{ voidbuildConstraints(GridBagConstraintsgbc,intgx,intgy, intgw,intgh,intwx,intwy){ gbc.gridx=gx; gbc.gridy=gy; gbc.gridwidth=gw; gbc.gridheight=gh; gbc.weightx=wx; gbc.weighty=wy; } publicvoidinit(){ GridBagLayoutgb=newGridBagLayout(); GridBagConstraintsc1=newGridBagConstraints(); setLayout(gb); //TextFieldArea buildConstraints(c1,0,0,3,1,0,20); c1.fill=GridBagConstraints.BOTH;

More Related