getting started with gui programming in java_2
TRANSCRIPT
![Page 1: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/1.jpg)
By .Muhammad Shebl
GETTING STARTED WITH GUI PROGRAMMING 2
![Page 2: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/2.jpg)
OBJECTIVES
1. Labels & Images 2. Buttons 3. Text Fields & Text Area 4. Combo Boxes 5. Check box 6. Set bounds layout 7. Pack() & setResizable() 8. Menus
![Page 3: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/3.jpg)
Labels :
JLabel lab=new JLabel(“MUFIX”);
ImageIcon icon = new ImageIcon("sigin.png");
JLabel lab=new JLabel(icon );
![Page 4: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/4.jpg)
BUTTONS :
Adding Event :
JButton jbt = new JButton("OK");
jbt.addActionListener(this );
Add icon image :
ImageIcon icon = new
ImageIcon("sigin.png");
JButton jbt = new JButton(icon);
![Page 5: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/5.jpg)
BUTTONS :
Roll over icon :
ImageIcon icon = new
ImageIcon("sigin.png");
JButton jbt = new JButton(icon);
Jbt.setRolloverIcon(icon);
![Page 6: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/6.jpg)
BUTTONS:
Roll Pressedicon : ImageIcon icon = new
ImageIcon("sigin.png");
JButton jbt = new JButton(icon);
jbt.setPressedIcon(icon);
![Page 7: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/7.jpg)
TEXT AREA
If you want to let the user enter multiple lines of text, you have to create several instances of JTextField. A better alternative is to use JTextArea, which enables the user to enter multiple lines of text.
JTextArea jtaNote = new JTextArea(5, 20);
![Page 8: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/8.jpg)
TEXT FIELDS KEY LISTNERS :
// Create a text field with text "Type Name Here" JTextField jtfName = new JTextField("Type Name Here");
jtfName .addKeyListener(this);
![Page 9: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/9.jpg)
Array of Text Fields
You can create Array of Text fields by:
JTextField[][] txt = new JTextField[x][y];
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
txt[i][j] = new JTextField(10);
panel.add(txt[i][j]);
txt[i][j].setHorizontalAlignment(JTextField.CENTER);
if (i == j) {
txt[i][j].setText("1");
txt[i][j].setEditable(false);
} txt[i][j].addKeyListener(this);
}}
![Page 10: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/10.jpg)
Combo box
To Create Combo box :
JComboBox operations_txt= new JComboBox(new String[]{"<=", "=", ">="});
Operation_txt. getSelectedItem();
![Page 11: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/11.jpg)
Check box :
// Create a check box with text bold JCheckBox jchkBold = new JCheckBox("Bold");
jchkBold.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { if (jchkBold.isSelected()) { // your Action
}
} });
![Page 12: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/12.jpg)
QUESTIONS ?!!
![Page 13: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/13.jpg)
TASK : FULL CALCULATOR
![Page 14: Getting started with GUI programming in Java_2](https://reader034.vdocuments.mx/reader034/viewer/2022052619/556626d2d8b42ac0498b48a6/html5/thumbnails/14.jpg)
Thank You