tailieunhanh - lt_java_csdl_bai_3_components_part_1_2236

| LẬP TRÌNH JAVA CSDL BÀI 3 COMPONENTS Nguyễn Hữu Thể 1 Nội dung JLabel JTable JButton JMenu JTextField JToolBar JCheckBox JOptionPane JRadioButton JFileChooser JPanel JComboBox JList 2 GUI Components JButton JLabel JTextField JCheckBox JRadioButton and JComboBox. Each GUI component class provides several constructors that you can use to create GUI component objects. 3 GUI Components Create a button with text OK JButton btOK new JButton quot OK quot Create a label with text quot Enter your name quot JLabel lbName new JLabel quot Enter your name quot Create a text field with text quot Type Name Here quot JTextField txtName new JTextField quot Type Name Here quot Create a check box with text bold JCheckBox chkBold new JCheckBox quot Bold quot Create a radio button with text red JRadioButton rbRed new JRadioButton quot Red quot Create a combo box with choices red green blue JComboBox cboColor new JComboBox new String quot Red quot quot Green quot quot Blue quot 4 Working with Components Several methods setEnabled boolean receive user input an argument of true or is inactive and cannot receive input false . Components are enabled by default. isEnabled returns a boolean value. setVisible boolean for all components. Use true to display a component and false to hide it. isVisible setSize int int width and height specified as arguments setSize Dimension uses a Dimension getSize returns a Dimension object with height and width 5 Working with Components setText getText setValue and getValue for components that store a numeric value. 6 JLabel Display Text not editable Constructor Label An empty label JLabel String A label with the specified text JLabel String int A label with the specified text and alignment LEFT CENTER and RIGHT. JLabel String Icon int A label with the specified text icon and Alignment 7 JLabel Common Methods void setFont Font f void setText String S String getText void setIcon Icon 8 JLabel Example JLabel lbl new JLabel quot Họ và tên

TỪ KHÓA LIÊN QUAN