SlideShare a Scribd company logo
1 of 40
Download to read offline
JAVA
JAVA HOW TO PROGRAM
12
Prepared by: Mir Omranudin Abhar
Email : MirOmran@Gmail.com
1
JAVA
2
Graphic User Interface Component
(GUI) Component
JAVA
3
JAVA
4
• GUI Component
1. JOptionPane
◦ showInputDialog
◦ showMessageDialog
◦ JOptionPane.PLAN_MESSAGE
◦ Integer.parseInt
JAVA
5
• GUI Component
1. JOptionPane
◦ showInputDialog
◦ showMessageDialog
◦ JOptionPane.PLAN_MESSAGE
◦ Integer.parseInt
JAVA
6
• GUI Component
1. JOptionPane
◦ showMessageDialog
JAVA
7
• GUI Component
1. JOptionPane
JAVA
8
• GUI Component
1. JOptionPane
JAVA
9
• GUI Component
Swing AWT
Java GUI
JAVA
10
• GUI Component
• Super Classes of Swings
JAVA
11
• GUI Component
1. Class
2. Inheritance Jframe Class
3. Super()
4. setSize
5. setVisible
6. setDefaultCloseOperation
JAVA
12
• GUI Component
1. Class
2. extends JFrame Class
3. Super()
4. setSize
5. setVisible
6. setDefaultCloseOperation
JAVA
13
• GUI Component
1. Swing Components
JAVA
14
• GUI Component
1. Swing Components
JLable
JTextField
JButton
JCheckBox
JComboBox
JList
JAVA
15
• GUI Component
JLable
JAVA
16
• GUI Component
1. Displaying Text in a Window
◦ JLable
JAVA
17
• GUI Component
1. Displaying Text in a Window
◦ JLable
JAVA
18
• GUI Component
1. Displaying Image in a Window
◦ Jlable
◦ Icon, ImageIcon
JAVA
19
• GUI Component
1. Displaying text and Image in a Window
◦ Jlable
◦ Icon
JAVA
20
• GUI Component
1. Displaying text and Image in a Window
◦ Jlable
◦ Icon
◦ setToolTipText
◦ setVerticalTextPosition
◦ setHorizontalTextPosition
JAVA
21
• GUI Component
1. Displaying text and Image in a Window
◦ Jlable
◦ Icon
◦ setToolTipText
◦ setVerticalTextPosition
◦ setHorizontalTextPosition
◦ setIcon
JAVA
22
• GUI Component
JTextField
JAVA
23
• GUI Component
1. Displaying TextField in a Window
◦ JTextField
JAVA
24
• GUI Component
1. Displaying TextField in a Window
◦ JTextField
JAVA
25
• GUI Component-Example-1
1. Jlabel
2. JTextField
3. Array
4. for
JAVA
26
• GUI Component-Example-1
1. Jlabel
2. JTextField
3. Array
4. for
JAVA
27
• GUI Component
JPasswordField
JAVA
28
• GUI Component
1. Displaying PasswordField in a Window
◦ JPasswordField
JAVA
29
• GUI Component
1. Displaying PasswordField in a Window
◦ JPasswordField
JAVA
30
• GUI Component-Example-2
1. Jlabel
2. JTextField
3. JPasswordField
JAVA
31
• GUI Component-Example-2
1. Jlabel
2. JTextField
3. JPasswordField
JAVA
32
• GUI Component
JButton
JAVA
33
• GUI Component
1. Displaying Button in a Window
◦ JButton
JAVA
34
• GUI Component
1. Displaying Button in a Window
◦ JButton
JAVA
35
• GUI Component-Example-3
1. Jlabel
2. JTextField
3. JPasswordField
4. JButton
JAVA
36
• GUI Component-Example-3
1. Jlabel
2. JTextField
3. JPasswordField
4. JButton
Question
.1
‫در‬
‫باره‬
Method
‫ها‬
‫ذیل‬
‫که‬
‫از‬
‫جمله‬
‫میتود‬
‫های‬
‫کالس‬
JOptionPane
‫میباشد‬
‫تحقیق‬
‫نماید‬
‫و‬
‫برنامه‬
‫جالب‬
‫با‬
‫استفاده‬
‫ازین‬
‫میتود‬
‫ها‬
‫بنویسید؟‬
 JOptionPane.showConfirmDialog
 JOptionPane.showInternalConfirmDialog
 JOptionPane.showOptionDialog
37
Question
.1
‫برنامه‬
‫بنویسید‬
‫که‬
‫توسط‬
‫ان‬
‫بتوانیم‬
‫تاریخ‬
‫و‬
‫ساعت‬
‫کمپیوتر‬
‫را‬
‫بدست‬
‫ب‬
‫یاورویم‬
‫و‬
‫انرا‬
‫در‬
JTextField
‫نشان‬
‫بدهیم؟‬
38
public class frame extends JFrame {
frame(){
super("Title");
setLayout(newFlowLayout());
JLabel label1 = new JLabel("Date & Time : ");
Date di = new Date();
String[]arra = di.toLocaleString().split("");
JTextFieldname = new JTextField("Date: " + arra[0]);
JTextFieldname1 = new JTextField("Time:" + arra[1]);
add(label1);
add(name);
add(name1);
}
}
Question
.1
‫برنامه‬
‫بنویسید‬
‫که‬
‫توسط‬
‫ان‬
‫بتوانیم‬
logo
‫سافت‬
‫ویر‬
‫خویش‬
‫را‬
‫در‬
‫قسمت‬
Title-Bar
‫برنامه‬
‫اضافه‬
‫کنیم؟‬
39
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package jframe2;
import java.awt.FlowLayout;
import java.util.Date;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
/**
*
* @author DELL
*/
public class frame extends JFrame {
frame() {
super("JAVA");
setLayout(new FlowLayout());
JLabel label1 = new JLabel("Date & Time : ");
Date di = new Date();
String[] arra = di.toLocaleString().split(" ");
JTextField name = new JTextField("Date : " + arra[0]);
JTextField name1 = new JTextField("Time :" + arra[1]);
ImageIcon img = new ImageIcon(getClass().getResource("123.jpg"));
this.setIconImage(img.getImage());
// add(label1);
// add(name);
// add(name1);
}
}
Question
.1
‫برنامه‬
‫بنویسید‬
‫که‬
‫توسط‬
‫ان‬
‫بتوانیم‬
‫رنگ‬
background frame
‫را‬
‫تغیر‬
‫بدهیم‬
‫و‬
‫همچنان‬
‫رنگ‬
‫نوشته‬
‫و‬
background
,
JTextField
‫را‬
‫تغیر‬
‫بدهیم؟‬
40
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package jframe2;
import java.awt.Color;
import java.awt.FlowLayout;
import java.util.Date;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
/**
*
* @author DELL
*/
public class frame extends JFrame {
frame() {
super("JAVA");
setLayout(new FlowLayout());
JLabel label1 = new JLabel("Date & Time : ");
Date di = new Date();
String[] arra = di.toLocaleString().split(" ");
JTextField name = new JTextField("Date : " + arra[0]);
ImageIcon img = new ImageIcon(getClass().getResource("123.jpg"));
JTextField name1 = new JTextField("Time :" + arra[1]);
JButton bu=new JButton("Button",img);
bu.setBackground(Color.BLUE);
name.setBackground(Color.red);
getContentPane().setBackground(java.awt.Color.g etHSBColor(120, 202,122));
// this.setIconImage(img.getImage());
// add(label1);
add(name);
// add(bu);
// add(name1);
}
}

More Related Content

More from MirOmranudinAbhar (20)

java-9
java-9java-9
java-9
 
java-8
java-8java-8
java-8
 
java-7
java-7java-7
java-7
 
java-5
java-5java-5
java-5
 
java-4
java-4java-4
java-4
 
java-3
java-3java-3
java-3
 
java-2
java-2java-2
java-2
 
java-1
java-1java-1
java-1
 
Software-0
Software-0Software-0
Software-0
 
Net 1
Net 1Net 1
Net 1
 
Net 2
Net 2Net 2
Net 2
 
Net 3
Net 3Net 3
Net 3
 
Net 4
Net 4Net 4
Net 4
 
Net 5
Net 5Net 5
Net 5
 
Net 6
Net 6Net 6
Net 6
 
Net 7
Net 7Net 7
Net 7
 
(Ds+alg) 6
(Ds+alg)   6(Ds+alg)   6
(Ds+alg) 6
 
(Ds+alg) 5
(Ds+alg)   5(Ds+alg)   5
(Ds+alg) 5
 
(Ds+alg) 4
(Ds+alg)   4(Ds+alg)   4
(Ds+alg) 4
 
(Ds+alg) 3
(Ds+alg)   3(Ds+alg)   3
(Ds+alg) 3
 

java-12