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



Home Answers Viewqa Java-Beginners adding the delete code
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ida zuriati
adding the delete code
2 Answer(s)      2 years and 6 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
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 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
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
Delete Account
Delete Account  How to delete account
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
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
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
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
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
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 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
Advertisements
 

 

 

DMCA.com