1 / 20

JTextArea Constructors

JTextArea Constructors. JTextArea(int rows, int columns) Creates a text area with the specified number of rows and columns. JTextArea(String s, int rows, int columns) Creates a text area with the initial text and the number of rows and columns specified. 1. JTextArea Properties. text

conor
Download Presentation

JTextArea Constructors

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. JTextArea Constructors JTextArea(int rows, int columns) Creates a text area with the specified number of rows and columns. JTextArea(String s, int rows, int columns) Creates a text area with the initial text andthe number of rows and columns specified. 1

  2. JTextArea Properties text editable columns lineWrap wrapStyleWord rows lineCount tabSize 2

  3. CheckBox ทำหน้าที่คล้ายกับสวิทซ์ on-offปกติจะมีสถานะเป็น off การสร้าง check boxสามารถสร้างได้ดังนี้ JCheckBox ch = new JCheckBox(); มี constructorดังนี้ JCheckBox(String text) JCheckBox(String text, boolean b) มี methodสำหรับกำหนดค่า checkBox เป็น true/false Obj.setSelected(boolean b) Obj.isSelected() //return true/false on Obj. CheckBok 3

  4. JCheckBox JCheckBox inherits all the properties such as text, icon, mnemonic, verticalAlignment, horizontalAlignment, horizontalTextPosition, verticalTextPosition, and selected from AbstractButton, and provides several constructors to create check boxes. 4

  5. RadioButton ใช้กรณีให้ผู้ใช้เลือกตัวเลือกได้เพียงตัวเลือกเดียวภายในกลุ่มเดียวกัน ใช้คลาส JRadioButtonเพื่อสร้าง ใช้คลาส ButtonGroupเพื่อจัดกลุ่ม RadioButton Constructor JRadioButton() JRadioButton(Icon icon) JRadioButton(String text) ButtonGroup() ตัวอย่างการเขียนโปรแกรม CreateRadio1.java 5

  6. Event Hangling • getItemSelectable() iตรวจสอบ Checkbox นั้นๆถูกคลิกหรือไม่ 6

  7. JRadioButton Radio buttons are variations of check boxes. They are often used in the group, where only one button is checked at a time. 7

  8. Grouping Radio Buttons ButtonGroup btg = new ButtonGroup(); btg.add(jrb1); btg.add(jrb2); 8

  9. List ใช้สร้างรายการซึ่งสามารถเลื่อนรายการเพื่อเลือกรายการใดรายการหนึ่ง การสร้างสามารถสร้างได้ JList list = new JList(); มี constructor JList() JList(Object item[]) มี method setFixedCellWidth(int i) //Set ขนาดความกว้างของ List setVisbleRowCount(int i) // setให้มองเห็นกี่ตัวเลือก getSelectedIndex()//returnค่าของตำแหน่งข้อมูลใน List setSelectedIndex(int i) //Set ค่าเริ่มต้นของข้อมูลในList getSelectedValue()//returnค่าของข้อมูลที่อยู่ใน List 9

  10. Event Hangling • getSource() iใช้ในการคืนค่าว่าปุ่มใดถูกกด • getText() iสำหรับดึงข้อความจาก Text นั้นๆ • setText() iสำหรับกำหนดข้อความ • getSelectedIndex() iจะคืนค่าตำแหน่งรายการใน list ที่ถูกเลือก • getSelectedValue() iจะคืนข้อความที่อยู่ใน list 10

  11. JList A list is a component that performs basically the same function as a combo box, but it enables the user to choose a single value or multiple values. 11

  12. JList Constructors JList() Creates an empty list. JList(Object[] stringItems) Creates a new list initialized with items. 12

  13. JList Properties selectedIndexd selectedIndices selectedValue selectedValues selectionMode visibleRowCount 13

  14. Combo Box สามารถเลือกข้อมูลใน Listได้เพียง 1ตัวเลือกเท่านั้น สามารถสร้าง JComboBox com = new JComboBox(); Constructor JComboBox() JComboBox(Object item[]) เมธอดที่สำคัญ setMaximumRowCount(int i)//กำหนดรายให้มองเห็นใน combo ตัวอย่างการเขียนโปรแกรม UseComBox.java 14

  15. Event Hangling • getSource() iใช้ในการคืนค่าว่าปุ่มใดถูกกด • getText() iสำหรับดึงข้อความจาก Textนั้นๆ • setText() iสำหรับกำหนดข้อความ • getSelectedIndex() iจะคืนค่าตำแหน่งรายการใน ComboBoxที่ถูกเลือก • getSelectedItem() iจะคืนข้อความที่อยู่ใน ComboBox 15

  16. JComboBox A combo box is a simple list of items from which the user can choose. It performs basically the same function as a list, but can get only one value. 16

  17. JComboBox Methods To add an item to a JComboBox jcbo, use jcbo.addItem(Object item) To get an item from JComboBox jcbo, use jcbo.getItem() 17

  18. Menu เป็นเครื่องมือสำหรับให้ผู้ใช้เลือกคำสั่งต่างๆจากรายการที่สร้างขึ้น ขั้นตอนการสร้าง สร้าง Menu barsจาก Class “JMenuBar” สร้าง Menuจาก Class “JMenu” เพิ่ม Menu Itemให้กับ Menuโดย Class “JMenuItem”หรือ Subclassของ Class JMenuItem เพิ่ม Menuให้กับ Menu bars กำหนด Menu barให้กับ Frameโดย “setJMenuBar()” 18

  19. Menu Constructor JMenuBar() JMenu(String text) JMenuItem(String text) Method addSeparator() 19

  20. Event Hangling • getSource() iใช้ในการคืนค่าว่าปุ่มใดถูกเลือก 20

More Related