Skip to content

Commit 5961769

Browse files
authored
Create PhoneBook.java
1 parent 21aecdb commit 5961769

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

Mini Projects/PhoneBook.java

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package mp;
2+
import javax.swing.*;
3+
import java.awt.event.*;
4+
import mp.Connect1;
5+
import mp.ViewFrame;
6+
@SuppressWarnings("serial")
7+
public class PhoneBook extends JFrame {
8+
JLabel l1,l2,l3,l4,l5;
9+
JTextField t1,t2;
10+
JButton b1,b2,b3;
11+
Connect1 c ;
12+
ViewFrame vf;
13+
PhoneBook()
14+
{
15+
super("Phone Book");
16+
ImageIcon image = new ImageIcon("E:/just.png");
17+
l1 = new JLabel(image);
18+
add(l1);
19+
l1.setBounds(0, 0, 80, 60);
20+
l2 = new JLabel("Phone Book");
21+
add(l2);
22+
l2.setBounds(90, 0, 390, 60);
23+
l3 = new JLabel("Contact Name");
24+
add(l3);
25+
l3.setBounds(20, 80, 100, 50);
26+
l4 = new JLabel("Contact Number");
27+
add(l4);
28+
l4.setBounds(20, 140, 100, 50);
29+
t1 = new JTextField();
30+
add(t1);
31+
t1.setBounds(130, 80, 210, 40);
32+
t2 = new JTextField();
33+
add(t2);
34+
t2.setBounds(130, 150, 210, 40);
35+
ImageIcon image1 = new ImageIcon("E:/ct.png");
36+
l5 = new JLabel(image1);
37+
add(l5);
38+
l5.setBounds(370, 80, 100, 100);
39+
b1 = new JButton("CANCEL");
40+
add(b1);
41+
b1.setBounds(240, 230, 110, 40);
42+
b1.addActionListener(new java.awt.event.ActionListener() {
43+
public void actionPerformed(java.awt.event.ActionEvent evt) {
44+
t1.setText(" ");
45+
t2.setText(" ");
46+
}});
47+
c = new Connect1();
48+
b2 = new JButton("ADD TO CONTACTS");
49+
add(b2);
50+
b2.setBounds(80, 230, 145, 40);
51+
b2.addActionListener(new ActionListener() {
52+
public void actionPerformed(ActionEvent evt) {
53+
String s1 = t1.getText();
54+
String s2 = t2.getText();
55+
if(s1.equals("") & s2.equals("") )
56+
{
57+
JOptionPane.showMessageDialog(null,"Please Enter the Name and Number!");
58+
}
59+
else
60+
{
61+
try { c.connect(s1,s2); }catch(Exception e) {};
62+
JOptionPane.showMessageDialog(null,"Contact added Successfully!");
63+
t1.setText("");
64+
t2.setText("");
65+
}
66+
67+
}});
68+
69+
b3 = new JButton("View Contacts");
70+
b3.addActionListener(new ActionListener() {
71+
public void actionPerformed(ActionEvent evt) {
72+
vf = new ViewFrame();
73+
try {
74+
vf.Vcon();
75+
} catch (Exception e) {
76+
77+
e.printStackTrace();
78+
}
79+
}
80+
});
81+
add(b3);
82+
b3.setBounds(160, 300, 120, 40);
83+
84+
t1.addKeyListener(new KeyAdapter() {
85+
public void keyReleased(KeyEvent e)
86+
{
87+
int key = e.getKeyCode();
88+
if(e.getSource()==t1)
89+
{
90+
if (key == KeyEvent.VK_ENTER)
91+
{
92+
t2.requestFocus();
93+
}
94+
}
95+
}
96+
});
97+
98+
99+
100+
setLayout(null);
101+
setSize(481,380);
102+
setVisible(true);
103+
setResizable(false);
104+
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
105+
}
106+
public static void main(String[] args) {
107+
new PhoneBook();
108+
}
109+
}

0 commit comments

Comments
 (0)