Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 56 time
* Project Name:
Address Book in Java * Programmer:Rahul Chouhan * Type:Java Swing * Technology:Java * IDE:Any * Description:asy to keep records first create a directory named data which should be in Bin folder of jdk and in that create a file name data.dat
menu = new JMenu("Options"); menuItem = new JMenuItem("Add New Contact"); menu.add(menuItem); menuItem.addActionListener(this);
menuItem = new JMenuItem("Delete Contact"); menu.add(menuItem); menuItem.addActionListener(this);
menuItem = new JMenuItem("Search Contacts"); menu.add(menuItem); menuItem.addActionListener(this);
menuItem = new JMenuItem("Sort Contacts"); menu.add(menuItem); menuItem.addActionListener(this);
menuItem = new JMenuItem("View All Contacts"); menu.add(menuItem); menuItem.addActionListener(this);
menuItem = new JMenuItem("Backup Contacts"); menu.add(menuItem); menuItem.addActionListener(this);
menubar.add(menu);
menu = new JMenu("Help");
menuItem = new JMenuItem("Help Contents"); menu.add(menuItem); menuItem.addActionListener(this);
menuItem = new JMenuItem("About"); menu.add(menuItem); menuItem.addActionListener(this);
menubar.add(menu);
frame.setJMenuBar(menubar);
JPanel topPanel = new JPanel(); JPanel bottomPanel = new JPanel();
//Add Buttons To Bottom Panel JButton AddNew = new JButton("Add New Contact"); JButton DeleteContact = new JButton("Delete Contact"); JButton SearchContacts = new JButton("Search Contacts"); JButton SortContacts = new JButton("Sort Contacts"); JButton ViewContactList = new JButton("View All Contacts");
JLabel label = new JLabel("<HTML><FONT FACE = ARIAL SIZE = 2><B>Use The options below and In The Menu To Manage Contacts");
try { fis = new FileInputStream("data/data.dat"); ois = new ObjectInputStream(fis); v = (Vector) ois.readObject(); ois.close(); }
catch(Exception e) {
}
}
public void run() {
try { FileOutputStream fos = new FileOutputStream("data/data.dat"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(v); oos.flush(); oos.close();
} catch(Exception e) { JOptionPane.showMessageDialog(newFrame, "Error Opening Data File: Could Not Save Contents.", "Error Opening Data File", JOptionPane.INFORMATION_MESSAGE); }
}
public void AddNew() { newFrame = new JFrame("Add New"); newFrame.setSize(220,250); newFrame.setResizable(false); newFrame.setIconImage(img);
JLabel lblFirstName = new JLabel("First Name: "); JLabel lblLastName = new JLabel("Last Name: "); JLabel lblNickname = new JLabel("Nickname: "); JLabel lblEMail = new JLabel("EMail: "); JLabel lblAddress = new JLabel("Address: "); JLabel lblPhoneNo = new JLabel("Phone No: "); JLabel lblWebpage = new JLabel("Webpage: "); JLabel lblBDay = new JLabel("BDay: "); JLabel lblEmpty1 = new JLabel(""); JLabel lblEmpty2 = new JLabel("");
txtFirstName = new JTextField(10); txtLastName = new JTextField(10); txtNickname = new JTextField(10); txtEMail = new JTextField(10); txtAddress = new JTextField(10); txtPhoneNo = new JTextField(10); txtWebpage = new JTextField(10); txtBDay = new JTextField(10);
JButton BttnAdd = new JButton("Add New!"); BttnSaveAdded = new JButton("Save Added!");
public void SearchContacts() { newFrame = new JFrame("Search Contacts"); newFrame.setSize(700,220); newFrame.setLocation(screenWidth/4, screenHeight/4); newFrame.setIconImage(img); newFrame.setResizable(false);
JPanel topPane = new JPanel(); JLabel label1 = new JLabel("Search Contacts by First Name or Last Name or Both Spaced Via a Single Space:"); topPane.add(label1);
JPanel centerPane = new JPanel(); JLabel label2 = new JLabel("Search String:"); txtSearch = new JTextField(20); JButton bttnSearch = new JButton("Search!"); bttnSearch.addActionListener(this); JButton bttnCancel = new JButton("Cancel"); bttnCancel.addActionListener(this); centerPane.add(label2); centerPane.add(txtSearch); centerPane.add(bttnSearch); centerPane.add(bttnCancel);
searchTable = new JTable(data,columnNames); JScrollPane scrollPane = new JScrollPane(searchTable); searchTable.setPreferredScrollableViewportSize(new Dimension(500, 90));
JOptionPane.showMessageDialog(newFrame, "Entries Empty! Fill in the required entries to save Contact.", "Entries Empty", JOptionPane.INFORMATION_MESSAGE);