Sponsored Links


Results 1 to 2 of 2

Thread: CS506 Web Design and Development second assignment fall 2010

  1. #1
    Administrator Xpert's Avatar
    Join Date
    May 2010
    Location
    Jhelum
    Posts
    6,251

    Icon14 CS506 Web Design and Development second assignment fall 2010

    Sponsored Links


    Problem Statement:

    You are required to develop a simple GUI (Graphical user interface) application for the registration of voters.
    Your code should take data form user and save it into a text file.
    You will make voter class and a GUI.

    The Voter Class must have following attributes:

    • National ID Card Number (This should be primary key)
    • Name
    • Father/Husband’s name
    • Age
    • Address
    • Province

    GUI should look like this (You are not required to make GUI exactly like this, You can use any layout you like, just all the elements that is text boxes, labels and buttons should be there) .


    In the above GUI application, when the user clicks ‘Save’ button then it will take the data from the form and store into text file name “voter.txt”. The application must quit by clicking ‘Exit’ button.

    Sponsored Links



    Solution will be updated soon.

  2. #2
    Administrator Xpert's Avatar
    Join Date
    May 2010
    Location
    Jhelum
    Posts
    6,251

    Icon29 cs506 web development idea solution

    Get this solution and make changes your self.
    Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    
    public class GUI implements ActionListener
    {
    ArrayList personsList;
    PersonDAO pDAO;
    
    JFrame myFrame;
    
    // labels
    JLabel lNIC Card, lFather/Husband'sName, lAge, lAddress, lProvance;
    
    // text fields
    JTextField tfNIC Card, tfFather/Husband'sName, tfAge, tfAddress, tfProvance;
    
    // buttons
    JButton bSave, bExit;
    
    String Father/Husband'sname, address, Provance;
    int NIC Card, Age;
    
    
    //*************************************************************************************
    /*GUI Constructor*/
    public GUI()
    {
    NIc Card = "";
    FAther/HUsband's Name = "";
    Age = "";
    Address = "";
    provance = "";
    
    recordNumber = -1;
    
    initGUI();
    
    personsList = new ArrayList();
    
    // creating PersonDAO object
    pDAO = new PersonDAO();
    }
    
    //*****************************************************************************************
    /*initGui function will initialize our GUI*/
    public void initGUI()
    {
    
    /*Create a frame, get its contentpane and set layout*/
    myFrame = new JFrame("Voter Registration Form");
    
    Container c = myFrame.getContentPane();
    c.setLayout(new FlowLayout());
    
    /*initializing labels*/
    lNIC Card = new JLabel("NIC Card");
    lFather/HUsband's Name = new JLabel("Father/HUsband's Name");
    lAge = new JLabel("Age");
    lAddress = new JLabel("Address");
    lProvance = new JLabel("provance");
    
    /*initializing text fields*/
    tfNIC Card = new JTextField(20);
    tfFather'Husband's Name = new JTextField(20);
    tfAge = new JTextField(20);
    tfAddress = new JTextField(20);
    tfProvance = new JTextField(20);
    
    
    /* intializing buttons */
    bSave = new JButton("Save");
    bExit = new JButton("Exit");
    
    /*add all initialized components to the container*/
    c.add(lNIC Card);
    c.add(tfNIC Card);
    
    c.add(lFather/Husband's Name);
    c.add(tfFather/Husband's Name);
    
    c.add(lAge);
    c.add(tfAge);
    
    c.add(lAddress);
    c.add(tfAddress);
    
    c.add(lProvance);
    c.add(tfProvance);
    
    c.add(bSave);
    c.add(bExit);
    
    /*registering buttons with actionListner*/
    bSave.addActionListener(this);
    bExit.addActionListener(this);
    
    myFrame.setSize(240,315);
    myFrame.setResizable(false);
    myFrame.setVisible(true);
    
    } // end initGUI() method
    
    //*****************************************************************************************
    // implementing ActionListener's method i.e. actionPerformed()
    public void actionPerformed (ActionEvent event )
    {
    
    /*if button bSave generates the event */
    if (event.getSource () == bSave)
    {
    savePerson();
    
    // clear fields
    clear();
    }
    
    
    
    /*if button bExit generates the event */
    else if (event.getSource() == bExit)
    {
    System.exit(0);
    }
    
    }// end actionPerformed
    
    //********************************************************************************************************
    // used to save person information into DB, using PersonDAO
    public void savePerson()
    {
    /*get values from text fields*/
    NIc Card = Integer.parseInt(tfNIC Card.getText());
    Father/Husband's Name = tfFather/Husband's Name.getText();
    Age = Integer.parseInt(tfAge.getText());
    Address = tfAddress.getText();
    Provance = tfProvance.getText();
    
    if(NIC Card.equals(""))
    {
    JOptionPane.showMessageDialog(null, "Please enter NIC Card Number.");
    }else
    {
    
    /*create a new PersonInfo object and pass it to PersonDAO to save it*/
    PersonInfo person = new PersonInfo(NIC Card , father/Husband's Name, Age, address, Provance);
    pDAO.savePerson(person);
    
    JOptionPane.showMessageDialog(null, "Record added");
    }
    }// end GUI

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. CS506 Web Design and Development Assignment No.2 Semester Fall 2012
    By Vuhelper in forum Assignments & Solutions
    Replies: 3
    Last Post: 11-28-2012, 12:44 AM
  2. CS506 Web Design and Development Assignment 1 Fall semester 3rd November 2012
    By vuassignments in forum Assignments & Solutions
    Replies: 0
    Last Post: 11-03-2012, 03:28 PM
  3. Replies: 14
    Last Post: 11-02-2011, 02:06 AM
  4. Replies: 0
    Last Post: 12-05-2010, 07:38 PM
  5. Replies: 14
    Last Post: 11-01-2010, 04:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft