Download presentation
Presentation is loading. Please wait.
Published byDorothy Fleming Modified over 8 years ago
1
CC1007NI: Further Programming Week 6-7 Dhruba Sen Module Leader (Islington College)
2
2.0
3
Overview Buttons Text fields Layout
4
Adding a button private JButton button; button = new JButton(“Press me!”); contentPane.add(button); button.addActionListener(this); String command = event.getActionCommand(); if (command.equals(“Press me!”)) {... }
5
Adding a text field private JTextField textField; textField = new JTextField(10); contentPane.add(textField); String inputText = textfield.getText(); textfield.setText(outputText);
6
Inputting numbers using a text field String inputText = textfield.getText(); int wholeNumber = Integer.parseInt(inputText); double decimal = Double.parseDouble(inputText);
7
Flow Layout Frame.setLayout(new FlowLayout()); Is a basic layout in which GUI components are placed in a left to right flow. For more precise arrangement: Frame.setLayout(null);.setBounds(x,y,width,height); E.g. btnsubmit.setBounds(5,5,100,25);
8
More Components JCheckBox JCheckBox(“ ”) Used for multiple selection at once.
9
More Components JRadioButton JRadioButton(“ ”) Used for single selection out of multiple options. For the same, button group must be created; ButtonGroup() Add radio buttons to the group. buttonGroup.add(RadioButton);
10
More Components JComboBox (Drop down menu) JComboBox() Array can also be added as menu items: JComboBox( ); To add (append) Items: comboBox.addItem(“ ”);
11
More Components JTextArea: Input box for more than one line of input. JTextArea(); Jtextarea.setLineWrap(true);
12
More Controls for frame FrameObject.setResizable(false); //true default FrameObject.setSize(,<height in pixels); FrameObject.setDefaultCloseOperation(JFrame.EXIT_ON_ CLOSE);
13
THANK YOU.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.