tailieunhanh - Bài giảng Lập trình Java: Buổi 4 - Industrial university of Ho Chi Minh City
Bài giảng "Lập trình Java - Graphic user interface in Java" trình bày các nội dung: Text component, choice component, menu, mnemonic, toolbar, tooltip, tabbed pane, scroll pane, dialog box. nội dung chi tiết. | 1/3/2016 04. Graphic User Interface in Java Faculty of Information Technologies Industrial University of Ho Chi Minh City 1 GUI components (p3) Text component Choice component Menu Mnemonic Toolbar Tooltip Tabbed pane Scroll pane Dialog box 2 Text component 3 1 1/3/2016 Text component 4 Text component Group Description Text Also known simply as text fields, Controls text controls can display only one line of editable text. Like buttons, they generate action events. Swing Classes JTextField and its subclasses JPasswordField and JFormattedTextField Plain Text Areas JTextArea can display multiple lines JTextArea of editable text. Although a text area can display text in any font, all of the text is in the same font. Styled Text Areas A styled text component can display JEditorPane editable text using more than one and its subclass font. Some styled text components JTextPane allow embedded images and even embedded components. 5 JTextField • If the cursor is in the text field, the user presses the Enter key, JTextField generates an Action event o Listener? o Method in the listener? o Register listener to the text field? • implements ActionListener • public void actionPerformed(ActionEvent e) • void addActionListener(ActionListener listener) 6 2 1/3/2016 JTextField Demo public class JTextFieldDemo extends JFrame implements ActionListener { JTextField mmText; JLabel resultLabel; public JTextFieldDemo() { super("Chuyen doi don vi"); setLayout(new GridLayout(2,2)); public void actionPerformed(ActionEvent e) { double cm, mm; mm = (()); cm = mm/10; ((cm)); } add (new JLabel (“Nhap vao so millimet:")); add (mmText = new JTextField (10)); add (new JLabel (“So centimet tuong ung:")); add (resultLabel = new JLabel ("---")); (this); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(300,90); } } public static void main(String[] args) { new .
đang nạp các trang xem trước