Home Answers Viewqa Java-Beginners Code to register a new patient in a clinic

 
 


Sam
Code to register a new patient in a clinic
2 Answer(s)      a year and 2 months ago
Posted in : Java Beginners

Hi,

How do i write a code that allows a user to enter someone's name and then search for that name from a text file. If the name is not available it opens up a form to register the patient, but if the name is available in the text file, it just updates the profile if necessary

View Answers

March 27, 2012 at 1:28 PM


import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;

class  SearchFromFile{
    public static void main(String[] args)  {

        JFrame f=new JFrame();
        f.setLayout(null);
        final JLabel label=new JLabel("Enter Name to search: ");
        final JTextField text=new JTextField(20);
        final JButton b=new JButton("Search");
        final JLabel lab1=new JLabel("Name: ");
        final JTextField text1=new JTextField(20);
        final JLabel lab2=new JLabel("Address: ");
        final JTextField text2=new JTextField(20);
        final JLabel lab3=new JLabel("Contact No: ");
        final JTextField text3=new JTextField(20);
        final JLabel lab4=new JLabel("Email: ");
        final JTextField text4=new JTextField(20);
        final JButton button=new JButton("Edit");
        final JButton addbutton=new JButton("Add");
        final ArrayList list=new ArrayList();

        label.setBounds(20,20,150,20);
        text.setBounds(170,20,100,20);

        lab1.setBounds(20,70,100,20);
        text1.setBounds(120,70,100,20);

        lab2.setBounds(20,100,100,20);
        text2.setBounds(120,100,100,20);

        lab3.setBounds(20,130,100,20);
        text3.setBounds(120,130,100,20);

        lab4.setBounds(20,160,100,20);
        text4.setBounds(120,160,100,20);

        b.setBounds(170,50,80,20);
        addbutton.setBounds(20,190,100,20);
        button.setBounds(120, 190,80,20);


        lab1.setVisible(false);
        text1.setVisible(false);

        lab2.setVisible(false);
        text2.setVisible(false);

        lab3.setVisible(false);
        text3.setVisible(false);

        lab4.setVisible(false);
        text4.setVisible(false);

        button.setVisible(false);
        addbutton.setVisible(false);

        b.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
          String value = text.getText();
          File f = new File("c:/data.txt");
          try {
             BufferedReader freader = new BufferedReader(new FileReader( f));
             String s;
             while ((s = freader.readLine()) != null) {
                String[] st = s.split(" ");
                String name = st[0];
                String address = st[1];
                String contact = st[2];
                String email = st[3];
                list.add(name);
                if(name.equals(value)) {
                        int answer = JOptionPane.showConfirmDialog(null, "Do you want to update the record?");
                        if(answer == JOptionPane.YES_OPTION) {
                        lab1.setVisible(true);
                        text1.setVisible(true);
                        lab2.setVisible(true);
                        text2.setVisible(true);
                        lab3.setVisible(true);
                        text3.setVisible(true);
                        lab4.setVisible(true);
                        text4.setVisible(true);
                        button.setVisible(true);
                        label.setVisible(false);
                        text.setVisible(false);
                        b.setVisible(false);
                        addbutton.setVisible(false);
                        text1.setText(name);
                        text2.setText(address);
                        text3.setText(contact);
                        text4.setText(email);
                        }
                    }                                
                }

March 27, 2012 at 1:29 PM


continue....

if(!list.contains(value)) {
                        int answer = JOptionPane.showConfirmDialog(null, "Record Not Found! Do you want to add the record?");
                        if(answer == JOptionPane.YES_OPTION) {
                        lab1.setVisible(true);
                        text1.setVisible(true);
                        lab2.setVisible(true);
                        text2.setVisible(true);
                        lab3.setVisible(true);
                        text3.setVisible(true);
                        lab4.setVisible(true);
                        text4.setVisible(true);
                        addbutton.setVisible(true);
                        label.setVisible(false);
                        text.setVisible(false);
                        b.setVisible(false);
                        button.setVisible(false);
                        addbutton.addActionListener(new ActionListener() {
                              public void actionPerformed(ActionEvent ae) {
                               String t1 = text1.getText();
                               String t2 = text2.getText();
                               String t3 = text3.getText();
                               String t4 = text4.getText();
                               File f3 = new File("c:/data.txt");
                               try {
                                    BufferedWriter output = new BufferedWriter(new FileWriter(f3,true));
                                    output.newLine();
                                    output.write(t1 + " " + t2 + " " + t3 + " " + t4);
                                    output.close();
                                    JOptionPane.showMessageDialog(null,"Record is added successfully!");
                                }
                                catch(Exception e){}
                              }
                        });
                    }
                }
                  freader.close();
                }
                catch (Exception e) { }
                        }
                });
                button.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                  String value = text.getText();
                  String t1 = text1.getText();
                  String t2 = text2.getText();
                  String t3 = text3.getText();
                  String t4 = text4.getText();
                  File f3 = new File("c:/new.txt");
                  File f4 = new File("c:/data.txt");
                  try {
                       BufferedWriter output = new BufferedWriter(new FileWriter(f3));
                       BufferedReader freader = new BufferedReader(new FileReader(f4));
                       String s;
                       while ((s = freader.readLine()) != null) {
                          String[] f = s.split(" ");
                          String n = f[0];
                          String add = f[1];
                          String con= f[2];
                          String emailid = f[3];
                        if (!n.equals(value)) {
                           output.write(s);
                           output.newLine();
                        }
                        }
                       freader.close();
                        output.write(t1 + " " + t2 + " " + t3 + " " + t4);
                        output.close();
                        JOptionPane.showMessageDialog(null,"Record is updated successfully!");
                         }
                         catch (Exception e) {}
                         f4.delete();
                         f3.renameTo(f4);
                        }
                });

                f.add(label);
                f.add(text);
                f.add(lab1);
                f.add(text1);
                f.add(lab2);
                f.add(text2);
                f.add(lab3);
                f.add(text3);
                f.add(lab4);
                f.add(text4);
                f.add(b);
                f.add(button);
                f.add(addbutton);
                f.setSize(400,300);
                f.setVisible(true);
    }
}









Related Pages:
Code to register a new patient in a clinic
Code to register a new patient in a clinic  Hi, How do i write a code that allows a user to enter someone's name and then search for that name from a text file. If the name is not available it opens up a form to register
Hospital Patient
=new HashMap<Integer,Patient>(); PatientFunction pf=new PatientFunction(); Patient p1=new Patient(); Calendar c=Calendar.getInstance(); Date d... Patient addPatient() { Patient p=new Patient(); try
hospital patient
PatientFunction { Scanner s=new Scanner(System.in); public Patient updatePatient(Patient p) { int ctr=0; try { do...() { Patient p=new Patient(); try { System.out.println("Enter Name
JSP Servlet update patient data - JSP-Servlet
JSP Servlet update patient data  Hi Friend, I'm attaching my inserting patient data servlet as requested. I tried your posted code, its... 2. My index page has a patient register form and also the search facility
register servlet vibhu
register servlet vibhu  how to make register servlet?   ... register extends HttpServlet { public static Map<String, User> userPerson = new HashMap<String, User>(); /** * Processes requests for both HTTP
Cash Register System - Java Beginners
Cash Register System  Consider the problem below. A Cash Register... code, price, and quantity purchased for each product. All the products sold in the store is categorized by code ?1? (food), ?2? (water), ?3? (magazine), ?4
login and register - Java Beginners
login and register  pls send me the code for login and register immediately  Hi friend, Please specify the technology you want code for login and register. For example : JSP,Servlet,Struts,JSF etc
new
new   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <%@page contentType="text... use following sample code. */ out.println("<html>.... Click on the + sign on the left to edit the code."> /** * Handles the HTTP
Session Register
Session Register For session register, you will have to first create an action form in HTML that calls the php session_register code.   In PHP form... code, we have used server[PHP_SELF] call.  <?php session_start
new 2
new 2  <%@page import="java.util.ArrayList"%> <%@page...=stmt.executeQuery("Select * from register"); System.out.println("Select * from register "); RequestDispatcher rsd=request.getRequestDispatcher
java.lang.RuntimeException: Failed to register user. - MobileApplications
java.lang.RuntimeException: Failed to register user.  Hi Mr.Deepak i... this java.lang.RuntimeException: Failed to register user... Register User threw exception java.lang.RuntimeException: Failed to register user
Register page using servlets,jsp and java beans
Register page using servlets,jsp and java beans  i want code for register page using jsp,serlets and java beans.iam getting error for my code in java beans pls help me   Hi Friend, Please visit the following links
pls send me the code for login and register - Java Beginners
pls send me the code for login and register  pls immediately send me the jsp code for login and registration with validation with java bean in mysql database...  Hi friend, This login action code
Product Register System using Java
Product Register System In this section, you will learn how to create product register system. For this, we have categorized the products by code 1 (food), 2... given discount of  0% to product code 1 , 5% product code 2, 15% product
Java code problem
(); Patient p1=new Patient(); Calendar c=Calendar.getInstance(); Date d=new Date...Java code problem  Please check the errors,if any,in this code...i am...) { // TODO Auto-generated method stub Map<Integer,Patient> patients=new
jsp code for allocating a room for a new guest
jsp code for allocating a room for a new guest  i am implementing a project on online hotel reservation system.please give code in jsp to allocate a room for a guest
New to Java - New to java tutorial
. Properties props = new Properties(); // code to fill props with any... a unique session by getInstance() method… Properties props = new Properties(); // code to fill props with any information Session session
How to register domain name
to register. Follow the rules regarding name length and format. Search for the name. If the name is already taken, enter a new name... as a suffix, try .org or .net instead. Register the domain name
java code
[]) { m=new menu(); } void addMenu() { MenuBar mb=new MenuBar(); Menu register=new Menu("REGISTER"); Menu inquery=new Menu("INQUERY"); register.add...("NAMEWISE"); mb.add(register); mb.add(inquery); setMenuBar(mb
opening new browser with new JSESSIONID using java
. I have to open a new browser window with new JSESSIONID. Here is my code...opening new browser with new JSESSIONID using java  I am facing following problem, I am trying to open a new browser using java. First i have opened
GPS Patient Tracking System
GPS Patient Tracking System The patients with Alzheimer?s disease or dementia... be filed against them in case of any misfortune with the patient. For solving... the GPS Patient Tracking System at very affordable prices. The GPS Patient
code
code  < comp xlink:type="new" xlink:actuate="onload"/> how to write this in java
code
"   Hi Friend, Try the following code: import java.security....[]) { StringBuffer buffer = new StringBuffer(buf.length * 2); int i; for (i... = skey.getEncoded(); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES
code
; } } var Obj1 = new MyClass(); var Obj2 = new MyClass(); Obj1.SetData( 30
The registerShutdownHook in spring
the relevant destroy methods. In order to register a shutdown hook, you have... context = new ClassPathXmlApplicationContext( new String[] { "context.xml...]; root of context hierarchy Download this example code
New features in PHP5?
New features in PHP5?   hello,, What are new features added in PHP5?   hii, Following are new features added in PHP5 Access Modifiers are added in PHP5 PHP 5 introduces a number of new "magic" methods. Magic
new
new    hi i am jane pls explain the difference between string greeting = good morning string greeting = new string ("good morning
Simple but confusing code... Parent obj1 = new Parent(); Parent obj2 = new Child();
Simple but confusing code... Parent obj1 = new Parent(); Parent obj2 = new Child();  Hi friends I got confused in the below code snippet: Parent.... Then we create Parent obj2 = new Child(); <--------------- here in this code
NEW IN JAVA - Java Beginners
NEW IN JAVA  Suppose you are asked to design a software tool... the following code: import java.util.*; public class Operations { public static void main(String[] args) throws Exception { Scanner scan = new Scanner
new
new    hi i am jane pls explain the difference between heap memory and stack memory
new
new  hi the difference between string sname = good morning string sname =new("good morning
new to EJBs exceptions while excuting Client code - EJB
new to EJBs exceptions while excuting Client code  Hi i am new... then it is compiling fine can any one help me please.. i am posting the client code and the EXCEPTIONS here... thanks
How to Register Custom MBeans in Tomcat5.5
How to Register Custom MBeans in Tomcat5.5  How to register custom MBeans in Tomcat5.5 , please provide me an end-to-end example
JAVA SCRIPT CODE FOR OPENING A WEBSITE IN A NEW WINDOW - Java Beginners
JAVA SCRIPT CODE FOR OPENING A WEBSITE IN A NEW WINDOW   PLS... DATA, IT MUST OPEN A WEB SITE IN A NEW WINDOW. SPECIFICATION:MAKING ONLY "1" FUNCTION TO PERFORM ALL FUNCTIONS ON CLICK.  Hi friend, Code to help
JSF validator Tag
;    This tag is used to add and register the validator... (in faces-config file and validator tag in jsp file ) should match.  Code... Bean (Validation.java) : The code below is for backing bean used in this example
How to register for SCJP 6 certification ?
How to register for SCJP 6 certification ?  Hi, I want to take up SCJP 6 certification. Can somebody pl tell me how to register and go ahead
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I...;ZHTYPE (Just Logical) Please tell me how can i see this output? Code... This output with this code is true but I want add ZHTYPE at the end of each line
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I...;ZHTYPE (Just Logical) Please tell me how can i see this output? Code... with this code is true but I want add ZHTYPE at the end of each line + XTSM/XTS please
New Page 1
JavaScript loop through In this Tutorial we want to describe you a code that help you in understanding JavaScript loop through. We are using Java Script... of the program Download source code
New to Java?
New to Java?       If you are new to Java technology and you want to learn Java and make career... Machine (JVM) that acts as a translators of  byte code into machine language
New Page 1
. The onBlur event handler can execute the specific JavaScript code... event. Explanation with code : In this example we have created three... can see from the above code that we have invoked the addFName() method
display he new customer no in textbox
display he new customer no in textbox   i want to add the new customer for that when i click on add butto the new customernumber should be display in textfield . plz ell me the suggestions & code
Java file new directory
Java file new directory In this section, you will learn how to create a new directory. Description of code: This is a common task. The java.io.package... the given code, you will get the newly generated directory in the given path
Registering DataSource with JNDI
{ Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT... initialContextcontext = new InitialContext(properties); return initialContextcontext...(); ConnectionPoolDataSource dataSource = new MysqlConnectionPoolDataSource
JSP 2.0 - New Features
;    JSP 2.0  is released with new promises. JSP 2.0 is an upgrade to JSP 1.2 with several new and interesting features... with version 1.2. JSP 2.0 allows the developer to write script-free code without
opening new window - Java Beginners
opening new window  Hi All, I have two classes with me , lets say A and B.when I press a button in class A , the class B should open in a new window.i.e., I want to know, how a new window(B) can be opened by clicking a button
NOT ABLE TO MAKE A NEW FILE IN SERVLET
NOT ABLE TO MAKE A NEW FILE IN SERVLET  What is the error in my code? It is not making a new file which contains the string values coming from a HTML page. Any help appreciated. Code is-: package myprogram; import
java code - Java Beginners
through a frame?  Hi Friend, We are providing you a code... { static JTextField text1=new JTextField(20); static JTextField text2=new JTextField(20); static JTextField text3=new JTextField(20); static JButton

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.