Home Answers Viewqa Java-Beginners adding the delete code

 
 


ida zuriati
adding the delete code
2 Answer(s)      a year ago
Posted in : Java Beginners

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 Pages:
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 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
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: 1)user.jsp: <%@ page... type="button" name="edit" value="Delete" style="background-color:red;font-weight
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
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 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
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 checkbox to List as item
Adding checkbox to List as item   can we add checkox to List   Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class CheckBoxInList{ public static void
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
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 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
Dyanmically Adding Rows with Date Picker
Dyanmically Adding Rows with Date Picker  Hi Sir, I am doing a project in that i need to add rows dynamically with date picker inside row, send me code as soon as possible. Regards, Santhosh
i written the program in the files but in adding whole file is writing once again - Java Beginners
Home Page   Delete record code... i written the program in the files but in adding whole file is writing once... and it should not be re-written for every add/delete operation.  Hi
problem in adding a fullscreen frame nd adding a glass pane to it
problem in adding a fullscreen frame nd adding a glass pane to it  hi , here is my code import java.awt.*; import javax.swing.*; import java.awt.ToolKit; class MyFrame extends Jframe{ Container c; JPanel glass; MyFrame
Insert and Delete an element in between an array
Insert and Delete an element in between an array In this section, you will learn how to insert and delete an element in between an array. For this purpose, we... a new array. Following code insert an element in an array: public int
Adding a Reports tap in table pool
Adding a Reports tap in table pool  strong textHow to write a code to create a report in java using eclipse and link that report in jsp file that is written in jsf. I have to edit a jsp file that is written jsf there is a table
Adding A Primary Key to an Existing Table
Adding A Primary Key to an Existing Table   Been trying to add a primary key to a MySQL table using Java for two days with no success. I'm new... unable to find a good example. My code sample: try
adding some value to new column
adding some value to new column   how to update a column having some...   Hi Friend, Try the following code: import java.sql.*; public...+""); } } } For the above code, we have created a table 'leaveData' CREATE TABLE
adding two numbers - Java Beginners
adding two numbers  hii friends....... this is my program:- import java.io.*; import java.util.*; import java.math.*; public class... at Add2Numbers.main(Add2Numbers.java:17)  Hi friend, Correct code you changes x[1
adding of two numbers in designing of frame
adding of two numbers in designing of frame  hello sir, now i'm create two textfield for mark1&mark2 from db.how to add these two numbers... tell me........   Hi Friend, Try the following code: import
adding mouse listeners to drop target
adding mouse listeners to drop target  import java.awt.*; import... with adding mouse listeners to "table" which is drop target, to accept drop component wherever it drops from the mouse. in this code when component drops
adding background image - Java Beginners
adding background image  how do i add background image to this code: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class sampleProg extends JFrame { JButton button = new JButton ("Result
adding a method to calculate a students grade
adding a method to calculate a students grade  The Following program which displays a students name, id and mark works fine. But when i tried to add... someone help please the program code is as follows: class Student { private
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
adding two numbers using bitwise operators
adding two numbers using bitwise operators  adding two integer numbers with using bitwise opeators   Hi Friend, Try the following code...[] args) { System.out.println("Adding 5 and 6......"); int x=5,y=6; int xor
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 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
hibernate delete query :
hibernate delete query :   Hi, I m using Hibernate 3 + javadb my... NOT NULL , ITEM_ID INTEGER NOT NULL ) I want to delete a row from table . My code is : try{ SessionFactory sessionFactory = new Configuration
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... have a developed a code for item deletion and updation, it is not showing any errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... have a developed a code for item deletion and updation, it is not showing any errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... have a developed a code for item deletion and updation, it is not showing any errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... have a developed a code for item deletion and updation, it is not showing any errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... have a developed a code for item deletion and updation, it is not showing any errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... have a developed a code for item deletion and updation, it is not showing any errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... have a developed a code for item deletion and updation, it is not showing any errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... have a developed a code for item deletion and updation, it is not showing any errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... have a developed a code for item deletion and updation, it is not showing any errors but the edit and delete operations were not working, so please modify my
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... have a developed a code for item deletion and updation, it is not showing any errors but the edit and delete operations were not working, so please modify my
having difficulties in dynamically adding textbox with datepicker
having difficulties in dynamically adding textbox with datepicker  hi all, I need help! Right now the problem is, when a button is click... tried to solve but I still can't find any solution. Pls Help! below is my code
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
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
Java Applet - Adding a Button to Decrease a Total
Java Applet - Adding a Button to Decrease a Total  Hello everyone! Here is my current code: import java.awt.*; import java.awt.event.*; import... increasetestone() { testone++; } } When you run this current code
How to refresh a jTable On adding or deleting record ....
How to refresh a jTable On adding or deleting record ....   Hii Sir, I am developing a project in which a jtable is getting populated... me the code ........ Thank you Sir....   Here is a java swing code
delete and edit options in struts
where code=(?)"; //String query2="delete from pitems where code...delete and edit options in struts   Hi, I am doing an web application... have a developed a code for item deletion and updation, it is not showing any
adding DSN in Data Sources - JSP-Servlet
adding DSN in Data Sources  I have added DSN the way you have told and it has been added in the data sources as online_exam is shown in the ODBC Database Administrator dialog box. But still code gives the following exception
How to delete and update from Jtable cell in swing app
How to delete and update from Jtable cell in swing app  Hii Sir, I am developing a swing app for adding,updating and deleting from jtable... on delete button on selecting particular row which has to be deleted then last row

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.