Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners adding the delete code

Have Programming Question? Ask it here!
 
 
 


ida zuriati
adding the delete code
2 Answer(s)      2 years and 2 months 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();

}

}


Advertisement
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
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 an employee
Adding an employee  coding for adding an employee
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
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
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... will delete the row having minimum value of ID then delete the column named
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
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
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
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
Delete Account
Delete Account  How to delete account
adding groups in contacts
adding groups in contacts  how to add groups in contacts using servlet and jsp????pls help.thanku in advance
adding view to viewcontroller
adding view to viewcontroller  How to add a frame window that opens on button click .. in iPhone application
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 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
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
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
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 s
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
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
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
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
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
To delete post
To delete post  How can I delete my old post answer. I've posted 2 same answers by mistake
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
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
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>
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
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"/> <
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
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
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 button to each row for the table and adding row to another table
Adding button to each row for the table and adding row to another table  Hi I need to add button to each line in the table(Table data is retrived form database) and need to add that column data which we click in the specified
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
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
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
Adding a text file - Java Beginners
Adding a text file  Hello, I need a program that will search a text file of strings representing numbers of type int and will write the largest and the smallest numbers to the screen. The file contains nothing but strings
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
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
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
 

 

 

DMCA.com