Upload
muhammad-shebl-farag
View
179
Download
0
Tags:
Embed Size (px)
Citation preview
By .Muhammad Shebl
GETTING STARTED WITH GUI PROGRAMMING 2
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
Labels :
JLabel lab=new JLabel(“MUFIX”);
ImageIcon icon = new ImageIcon("sigin.png");
JLabel lab=new JLabel(icon );
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);
BUTTONS :
Roll over icon :
ImageIcon icon = new
ImageIcon("sigin.png");
JButton jbt = new JButton(icon);
Jbt.setRolloverIcon(icon);
BUTTONS:
Roll Pressedicon : ImageIcon icon = new
ImageIcon("sigin.png");
JButton jbt = new JButton(icon);
jbt.setPressedIcon(icon);
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);
TEXT FIELDS KEY LISTNERS :
// Create a text field with text "Type Name Here" JTextField jtfName = new JTextField("Type Name Here");
jtfName .addKeyListener(this);
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);
}}
Combo box
To Create Combo box :
JComboBox operations_txt= new JComboBox(new String[]{"<=", "=", ">="});
Operation_txt. getSelectedItem();
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
}
} });
QUESTIONS ?!!
TASK : FULL CALCULATOR
Thank You