adding the delete code

adding the delete code

hello sir... i need to add a delete button to my code but i didn't know where can i put it.. i've tried but still not working.. please help me...this is the code..

package newproject1;

import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; import javax.swing.*;

public class DisplayInfo extends JFrame implements ActionListener {

private String fileName;
private Scanner input = null;
private Container container;
private JPanel panel1, panel2, panel3;
private JButton sortBut,delBut;
private FlowLayout panel1L, panel2L, panel3L;
private BorderLayout containerL;
private JTextArea ta1, taUN, taPWD, taAPP;
private JScrollPane pane;
private JMenuBar menuBar;
private JMenu menu;
private JMenuItem menuSort, menuBack;
private Font displayFont;

//constructor
public DisplayInfo ()
{       
    //set frame title
    setTitle("EASY ACCESS");

    //set size
    setSize(510,620);

    //set frame close operation
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //set frame to be visible
    setVisible(true);

    //Create Font
    displayFont = new Font("Serif", Font.BOLD, 14);

    //Create text field
    taUN = new JTextArea(1,13);     
    taPWD = new JTextArea (1,13);       
    taAPP = new JTextArea(1,13);    
    taUN.append("USERNAME");
    taPWD.append("PASSWORD");
    taAPP.append("APPICATION");


    //Create Button
    sortBut = new JButton ("Sort by UserName");
            delBut = new JButton ("Delete");

    //create text area
    ta1 = new JTextArea(30, 43);        

    //Create Panel
    panel1 = new JPanel();      
    panel2 = new JPanel();      
    panel3 = new JPanel();      

    //Create Layout
    panel1L = new FlowLayout();
    panel2L = new FlowLayout();
    panel3L = new FlowLayout ();
    containerL = new BorderLayout();

    //create JScrollPane
    pane = new JScrollPane(panel2);

    //Create menu bar
    menuBar = new JMenuBar();
    menuBar.setBackground(Color.cyan);

    //Create menu
    menu = new JMenu("File");

    //Create menu item
    menuSort = new JMenuItem("Sort By UserName");
    menuSort.setBackground(Color.CYAN);
    menuBack = new JMenuItem("Back to InsertData");
    menuBack.setBackground(Color.CYAN);

    //set editable false to all text areas
    ta1.setEditable(false);
    taUN.setEditable(false);
    taPWD.setEditable(false);
    taAPP.setEditable(false);


    //set background to text areas
    taUN.setBackground(Color.yellow);
    taPWD.setBackground(Color.BLUE);
    taAPP.setBackground(Color.green);


    //set Font for taUN, taPWD and taAPP

    taUN.setFont(displayFont);
    taPWD.setFont(displayFont);
    taAPP.setFont(displayFont);

    //set background to all panels
    panel1.setBackground(Color.cyan);
    panel2.setBackground(Color.cyan);
    panel3.setBackground(Color.cyan);

    //set Mnemonic for menu item
    menuSort.setMnemonic('S');
    menuBack.setMnemonic('B');

    //set Mnemonic for button
    sortBut.setMnemonic('S');
            delBut.setMnemonic('D');

    //set Accelerator for menu item
    menuSort.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.Event.CTRL_MASK));
    menuBack.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.Event.CTRL_MASK));

    //set top and bottom layout
    panel1.setLayout(panel1L);
    panel2.setLayout(panel2L);
    panel3.setLayout(panel3L);

    //get all component
    container = getContentPane();

    //set container layout
    container.setLayout(containerL);    

    //Add label and text field onto panel 2
    panel1.add(taUN);
    panel1.add(taPWD);
    panel1.add(taAPP);


    //Add text field onto panel 2
    panel2.add(ta1);        

    //Add text field onto panel 3
    panel3.add(sortBut);
            panel3.add(delBut);

    //Add menu items to menu
    menu.add(menuSort);
    menu.add(menuBack);

    //Add menu to menu bar
    menuBar.add(menu);

    //Add menu bar to JFrame
    setJMenuBar(menuBar);

    //Add listener to all menu items
    menuSort.addActionListener(this);
    menuBack.addActionListener(this);

    //add listener button
    sortBut.addActionListener(this);

    //add panel onto container
    container.add(pane,BorderLayout.CENTER);
    container.add(panel3,BorderLayout.SOUTH);
    container.add(panel1,BorderLayout.NORTH);

    try
    {
        fileName = "User.dat";
        input = new Scanner(new FileInputStream(fileName));

        while(input.hasNext())
        {
            ta1.append(input.nextLine() + "\n");
        }
        input.close();
    }
    catch(FileNotFoundException fnfe)
    {
        System.err.println("Couldn't Find " + fileName + " !!");

    }

    {
        System.err.println("An Error has been occured!! ");
    }
}


@Override
public void actionPerformed(ActionEvent ae)
{
    if(ae.getSource() == sortBut)
    {
        try
        {               
            ArrayList<String> rows = new ArrayList<>();
            FileWriter writer;
            try (BufferedReader reader = new BufferedReader(new FileReader("User.dat"))) {
                String s;
                while((s = reader.readLine())!=null)
                    rows.add(s);
                Collections.sort(rows);
                writer = new FileWriter("User.dat");
                for(String cur: rows)
                    writer.write(cur+"\n");
            }
            writer.close();

            fileName = "User.dat";
            input = new Scanner(new FileInputStream(fileName));

            ta1.setText(null);
            while(input.hasNext())
            {                   
                ta1.append(input.nextLine() + "\n");
            }
            input.close();
        }
        catch(Exception e)
        {
        }
    }

    String menuCommand = ae.getActionCommand();

    //Event handler for menu item
    if(ae.getSource() instanceof JMenuItem){
        switch (menuCommand) {
            case "Sort By UserName":
                try
                {               
                        ArrayList<String> rows = new ArrayList<>();
            FileWriter writer;
            try (BufferedReader reader = new BufferedReader(new FileReader("User.dat"))) {
                String s;
                while((s = reader.readLine())!=null)
                    rows.add(s);
                Collections.sort(rows);
                writer = new FileWriter("Usert.dat");
                for(String cur: rows)
                    writer.write(cur+"\n");
            }
                    writer.close();

                    fileName = "User.dat";
                input = new Scanner(new FileInputStream(fileName));

                ta1.setText(null);
                while(input.hasNext())
                {                   
                        ta1.append(input.nextLine() + "\n");
                }
                input.close();
                }
                catch(Exception e)
                {
                }

                break;



            case "Back to InsertData":
                //calling the method openInsertData
                openInsertData();
                //set the DisplayInfo to not appear when InsertData is opened
                setVisible(false);
                break;
        }
    }
}   

public void openInsertData()
{
    //open InsertData
    new InsertData();

}

}

View Answers

May 17, 2012 at 4:18 PM


May 17, 2012 at 7:26 PM

but sir,my program is not using database...i dont know where to put the coding....









Related Tutorials/Questions & Answers:
adding the delete code
adding the delete code  hello sir... i need to add a delete button to my code but i didn't know where can i put it.. i've tried but still not working.. please help me...this is the code.. package newproject1; import java.awt.
Adding checkbox in table using that delete table rows
Adding checkbox in table using that delete table rows  I need coding for how to add checkbox in table,the table data from database.Using that checkbox select more than than one rows,and using delete button i want to delete
Advertisements
Example code of adding placeholder in UItextFeild
Example code of adding placeholder in UItextFeild  Ho to add add the placeholder text in UITextField in IOS program programmatically? Thanks  ... is the code example: mytext.placeholder = @"Enter User Name"; Thanks
How to delete file in Java code?
How to delete file in Java code?  Hi, From my Java program I have to delete a file. How to delete file in Java code? Thanks   Hi, Java... complete example code at How to delete file in Java?. Thanks   Hi, Also
DELETE
DELETE   I AM DOING IT IN MYSQL. DELETE FROM EMP WHERE SAL>(SELECT SAL FROM EMP WHERE ENAME='MILLAR') AND ENAME='ALLEN'; THIS IS GIVING THE FOLLOWING ERROR Error Code : 1093 You can't specify target table 'EMP
delete
delete  how delete only one row in the database using jsp.database is mysql   Hi Friend, Try the following code:ADS_TO_REPLACE_1 1...;td><input type="button" name="edit" value="Delete" style="background-color
Delete row and column from table through java code
Delete row and column from table through java code... will see how to delete row and column from given table through java code. Java code... | +----+----------+------------+---------+ In this table we will delete the row having minimum value of ID then delete
in order to create jsp and servlet code to add,delete,edit,list of persons in eclipsejavaee
in order to create jsp and servlet code to add,delete,edit,list of persons in eclipsejavaee  in order to create jsp and servlet code what all files we need to create in eclipse --dynamic web project
How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?
How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?  import java.awt.*; import javax.swing.*; import java.awt.event.*; public class MarkStudent { double
Delete Account
Delete Account  How to delete account
adding a dialogue
adding a dialogue  Blockquote Hi can you help with the program below,the program is a loop that prints out a code and a quantity when prompt for the user input.what I need is to modify the code to incorporate a dialogue asking
Adding an employee
Adding an employee  coding for adding an employee
adding loop
adding loop  Hi I have a program that is not compiling when I add...; class HardwareItems { String code; String description; double price; HardwareItems(String code,String description,double price
Array Delete
Array Delete       In this Tutorial we want to describe you a code that make you to understand Array Delete Example. For this we are using JavaScript
To delete post
To delete post  How can I delete my old post answer. I've posted 2 same answers by mistake
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color..."); JButton delete=new JButton("DELETE"); JButton save=new JButton("SAVE"); JButton
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color..."); JButton delete=new JButton("DELETE"); JButton save=new JButton("SAVE"); JButton
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color..."); JButton delete=new JButton("DELETE"); JButton save=new JButton("SAVE"); JButton
delete row
delete row  how to delete row using checkbox and button in php? localhost=wampserver database name=sourabh table name=sonu and my code...="delete" > <table width="100%" border="1"> <tr><td>
delete jsp
delete jsp  <%@ page language="java" contentType="text/html...; charset=ISO-8859-1"> <title>Delete Student</title> </head>...;/Controller"> <input type="hidden" name="page" value="delete"/> <
Hibernate delete example program
() method of the Session object. Here is the sample code: //Delete the object...Hibernate delete example program  How to delete an object in Hibernate? In my program I have to write program to delete the data using Hibernate
delete record
delete record  how to delete record using checkbox and button in php   We are providing you the jsp code that displays the database table...=conn.createStatement(); for(int a=0;a<10;a++){ st.executeUpdate("delete from book where
Java delete file if exists
Java delete file if exists  Hi, Hi how to delete file if exists? I need example code of java delete file if exists. Thanks   Hi, following code can be used: String tempFile = "C:/mydir/myfile.txt"; //Delete
Delete points from database
Delete points from database  I have a polygon on a web page and a delete button. The polygon is saved in the database in one table and in another... the delete button, the polygon in the webpage gets deleted as well as the polygon
JPA delete query - EJB
JPA delete query  Hi, I have an entity InvoiceItems.java. I want to delete all the records from the table. What will be the JPA query to delete.... Deleting all the records (enteties) is very easy. You can use the following code
delete an entry using JavaScript
delete an entry using JavaScript  How to delete an entry using JavaScript
delete() method of hibernate
delete() method of hibernate  Define the use of delete() method of hibernate? Example
delete javascript object
delete javascript object  How to create and delete an object in JavaScript
Java file delete
Java file delete In this section, you will learn how to delete a file. Description of code Java makes file manipulation easier by providing many useful... we are going to delete a file. For this, we have created an object of File
delete row using id
delete row using id  package pkg2; import org.hibernate.Query; import... = "delete from Insurance insurance where id = 2"; Query query = sess.createQuery...()); } } } this is the code m using . Error is -query must begin with SELECT or FROM
how to delete a letter in a word?
how to delete a letter in a word?  how to delete a letter in a word? for example if i enter= roseindia, i want to delete 's', then output= roeindia
Adding images in itext pdf
Adding images in itext pdf  Hi, How to add image in pdf file using itext? Thanks   Hi, You can use following code: PdfWriter.getInstance(document,new FileOutputStream("imagesPDF.pdf")); Read more at Inserting
Adding two numbers
Adding two numbers  Accepting value ffrom the keyboard and adding two numbers
What is the Delete Statements in SQL?
What is the Delete Statements in SQL?  What is the Delete Statements in SQL?   Hi, Here is the answer,ADS_TO_REPLACE_1 Delete statement in SQL is used to delete partial/all data. Especially delete statement is useful
javascript adding a value to an array
javascript adding a value to an array  How to add a value to a function argument or an array in JavaScript
adding view to viewcontroller
adding view to viewcontroller  How to add a frame window that opens on button click .. in iPhone application
adding groups in contacts
adding groups in contacts  how to add groups in contacts using servlet and jsp????pls help.thanku in advance
Adding photo to iPhone simulator
Adding photo to iPhone simulator  Hi, there is no photo in my iPhone simulator.. how can i add one? Please suggest. Thanks
adding buttons - Swing AWT
adding buttons  can u plzz explain how to add button to a dialog box and make them perform some event on the image loaded on the panel
adding buttons - Swing AWT
adding buttons  can u plzz explain how to add button to a dialog box and make them perform some event on the image loaded on the panel
Adding checkbox to List as item
Adding checkbox to List as item   can we add checkox to List   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.awt.*; import javax.swing.*; import java.awt.event.*; public class CheckBoxInList
Dyanmically Adding Rows
Dyanmically Adding Rows  Hi sir Am doing project in that i need to add date picker in dynamically adding rows but the dates are storing in first test box only ill paste my code debug that code as soon as possible. Regards
testcase for adding - JUNIT
testcase for adding  hi deepak...I am new to junit.can u send me a JUnit test case for adding or multiplying of two numbers.please i need it urgently
Adding Jar into Eclipse
Adding Jar into Eclipse  Hi, Please provide Step by step procedure to add jar, tld files and configurations in Eclipse Helios version and i am using Jboss5. Thanks&Regards, Shiva sADS_TO_REPLACE_1
Dynamically adding textbox and labels
Dynamically adding textbox and labels  Sir, In my application I want to insert texbox and labels dynamically and want to insert database field value in that generated label. Plz help me, Thanks in advance
Delete Internet Explorer History in java program
Delete Internet Explorer History in java program  code for Delete Internet Explorer History in java program
Adding customitem in canvas in J2ME?
Adding customitem in canvas in J2ME?  In J2ME how should we add a customitem inside the canvas.Because i need to perform key event handling for customitem.The key event handling is allowed in canvas not in form.So i try to use
webservices adding in eclipse
webservices adding in eclipse  hi team, i am working on webservices, please guide me how to add webservices in eclispe with step by step and give some examples also.   Please visit the following link: http
Java: Adding Row in JTable
Java: Adding Row in JTable   how about if we already have the JTAble created earlier. And i just found nothing to get its DefaultTableModel, thus, I can't call insertRow() method. Is there any work around for this? I found
jtable-adding a row dynamically
jtable-adding a row dynamically  hi..i am doing a project for pharmacy .. *pblm:* when i want to enter the details in jtable while running the application there are 3 rows and 4 columns which is default bt when we we have

Ads