
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();
}
}

Please go through the following link:
http://www.roseindia.net/java/example/java/swing/addeditanddeleteemployee_inf.shtml

but sir,my program is not using database...i dont know where to put the coding....
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.