Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Please help me to do the search edit and delete. PLEASE :(

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Please help me to do the search edit and delete. PLEASE :(

    package project;


    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileReader;
    import java.io.FileWriter;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;


    public class DirectoryBook{
    private finalFantasyVII list[] = new finalFantasyVII[20];
    private int top = 0;

    public static void main(String[] args) {
    DirectoryBook book = new DirectoryBook();
    book.showMenu();
    }

    public void readFromFile(){
    BufferedReader br;
    FileReader fr;
    JFileChooser file = new JFileChooser();
    String name, sex, skill, weapon;
    int index=0;

    finalFantasyVII list[] = new finalFantasyVII[20];
    try{
    file.showOpenDialog(null);
    fr = new FileReader(file.getSelectedFile().getPath());
    br = new BufferedReader(fr);

    name = br.readLine();

    while(name!=null){
    sex = br.readLine();
    skill = br.readLine();
    weapon = br.readLine();
    finalFantasyVII f = new finalFantasyVII(name,sex,skill,weapon);
    list[index]= f;
    index++;
    name = br.readLine();

    }
    top=index;
    br.close();
    this.list=list;
    }catch(Exception e){
    System.err.println(e.getMessage());

    }
    }

    public void writeToFile(){
    BufferedWriter bw;
    FileWriter fw;
    JFileChooser file = new JFileChooser();
    try{
    file.showSaveDialog(null);
    fw = new FileWriter(file.getSelectedFile().getPath());
    bw = new BufferedWriter(fw);
    for (finalFantasyVII f : list) {
    if (f !=null){
    bw.write(f.getName());
    bw.newLine();
    bw.write(f.getSex());
    bw.newLine();
    bw.write(f.getSkill());
    bw.newLine();
    bw.write(f.getWeapon());
    bw.newLine();
    }
    }
    bw.close();
    }catch (Exception e){
    System.err.println(e.getMessage());
    }
    }


    public void showMenu() {
    String menu = "";
    menu += " Record Information Systrem";
    menu += "\n [A] - Add a record";
    menu += "\n [E] - Edit a record";
    menu += "\n [D] - Delete a record";
    menu += "\n [V] - View all record";
    menu += "\n [S] - Search a record";
    menu += "\n [O] - Open records from file";
    menu += "\n [W] - Write records to file";
    menu += "\n [Q] - Quit";
    menu += "\n Please Enter your choice";
    String name;
    String sex;
    String skill;
    String weapon;
    boolean isQuit = false;
    char choice = 'u';
    do {
    choice = JOptionPane.showInputDialog(menu).charAt(0);

    switch (choice) {
    case 'a':
    case 'A':

    name = JOptionPane.showInputDialog("Enter name:");
    sex = JOptionPane.showInputDialog("Enter sex:");
    skill = JOptionPane.showInputDialog("Enter skill:");
    weapon = JOptionPane.showInputDialog("Enter weapon:");
    if( addAfinalFantasyVII(name,sex,skill,weapon)){
    JOptionPane.showMessageDialog(null,"Added a finalFantasyVII");
    } else {
    JOptionPane.showMessageDialog(null, "Cannot add another finalFantasyVII");

    }
    break;
    case 'v':
    case 'V':
    viewAll();
    break;
    case 'o':
    case 'O':
    readFromFile();
    break;
    case 'w':
    case 'W':
    writeToFile();
    break;
    case 'q':
    case 'Q':
    isQuit = true;
    break;
    }
    }while (isQuit == false);
    }

    public boolean addAfinalFantasyVII(String name, String sex, String skill, String weapon) {
    if (top == list.length){
    return false;
    }

    finalFantasyVII aNewfinalFantasyVII = new finalFantasyVII(name,sex,skill,weapon);
    list[top] = aNewfinalFantasyVII;
    top++;
    return true;

    }



    public void viewAll(){

    int recordNumber = 0;
    for(finalFantasyVII f: list){
    if(f !=null){
    System.out.println("Record Number:" + (recordNumber + 1));
    f.displayInformation();
    recordNumber++;
    }else {
    System.out.println("No more record to be viewed.");
    break;
    }
    }
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    51
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Please help me to do the search edit and delete. PLEASE :(

    Do you have any specific questions or problems?

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help me to do the search edit and delete. PLEASE :(

    package project;
     
     
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileReader;
    import java.io.FileWriter;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;
     
     
    public class DirectoryBook{
    private finalFantasyVII list[] = new finalFantasyVII[20];
    private int top = 0;
     
    public static void main(String[] args) {
    DirectoryBook book = new DirectoryBook();
    book.showMenu();
    }
     
    public void readFromFile(){
    BufferedReader br;
    FileReader fr;
    JFileChooser file = new JFileChooser();
    String name, sex, skill, weapon;
    int index=0;
     
    finalFantasyVII list[] = new finalFantasyVII[20];
    try{
    file.showOpenDialog(null);
    fr = new FileReader(file.getSelectedFile().getPath());
    br = new BufferedReader(fr);
     
    name = br.readLine();
     
    while(name!=null){
    sex = br.readLine();
    skill = br.readLine();
    weapon = br.readLine();
    finalFantasyVII f = new finalFantasyVII(name,sex,skill,weapon);
    list[index]= f;
    index++;
    name = br.readLine();
     
    }
    top=index;
    br.close();
    this.list=list;
    }catch(Exception e){
    System.err.println(e.getMessage());
     
    }
    }
     
    public void writeToFile(){
    BufferedWriter bw;
    FileWriter fw;
    JFileChooser file = new JFileChooser();
    try{
    file.showSaveDialog(null);
    fw = new FileWriter(file.getSelectedFile().getPath());
    bw = new BufferedWriter(fw);
    for (finalFantasyVII f : list) {
    if (f !=null){
    bw.write(f.getName());
    bw.newLine();
    bw.write(f.getSex());
    bw.newLine();
    bw.write(f.getSkill());
    bw.newLine();
    bw.write(f.getWeapon());
    bw.newLine();
    }
    }
    bw.close();
    }catch (Exception e){
    System.err.println(e.getMessage());
    }
    }
     
     
    public void showMenu() {
    String menu = "";
    menu += " Record Information Systrem";
    menu += "\n [A] - Add a record";
    menu += "\n [E] - Edit a record";
    menu += "\n [D] - Delete a record";
    menu += "\n [V] - View all record";
    menu += "\n [S] - Search a record";
    menu += "\n [O] - Open records from file";
    menu += "\n [W] - Write records to file";
    menu += "\n [Q] - Quit";
    menu += "\n Please Enter your choice";
    String name;
    String sex;
    String skill;
    String weapon;
    boolean isQuit = false;
    char choice = 'u';
    do {
    choice = JOptionPane.showInputDialog(menu).charAt(0);
     
    switch (choice) {
    case 'a':
    case 'A':
     
    name = JOptionPane.showInputDialog("Enter name:");
    sex = JOptionPane.showInputDialog("Enter sex:");
    skill = JOptionPane.showInputDialog("Enter skill:");
    weapon = JOptionPane.showInputDialog("Enter weapon:");
    if( addAfinalFantasyVII(name,sex,skill,weapon)){
    JOptionPane.showMessageDialog(null,"Added a finalFantasyVII");
    } else {
    JOptionPane.showMessageDialog(null, "Cannot add another finalFantasyVII");
     
    }
    break;
    case 'v':
    case 'V':
    viewAll();
    break;
    case 'o':
    case 'O':
    readFromFile();
    break;
    case 'w':
    case 'W':
    writeToFile();
    break;
    case 'q':
    case 'Q':
    isQuit = true;
    break;
    }
    }while (isQuit == false);
    }
     
    public boolean addAfinalFantasyVII(String name, String sex, String skill, String weapon) {
    if (top == list.length){
    return false;
    }
     
    finalFantasyVII aNewfinalFantasyVII = new finalFantasyVII(name,sex,skill,weapon);
    list[top] = aNewfinalFantasyVII;
    top++;
    return true;
     
    }
     
     
     
    public void viewAll(){
     
    int recordNumber = 0;
    for(finalFantasyVII f: list){
    if(f !=null){
    System.out.println("Record Number:" + (recordNumber + 1));
    f.displayInformation();
    recordNumber++;
    }else {
    System.out.println("No more record to be viewed.");
    break;
    }
    }
    }
    }



    ahm this is NetBeans IDE..

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,442
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: Please help me to do the search edit and delete. PLEASE :(

    Do you really not use indentation?

    And you still haven't actually specified what your question is or where you're stuck.

    If you want help, I suggest you provide an SSCCE along with a specific technical question.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Graph Search Theory with extend of BFS, UFS and A* Search in grid
    By keat84 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 7th, 2012, 08:46 AM
  2. How do you edit an array?
    By alkamenes in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 13th, 2011, 11:35 AM
  3. how to delete a JTextField?
    By A4Andy in forum AWT / Java Swing
    Replies: 10
    Last Post: August 31st, 2011, 11:33 AM
  4. Can I delete one of these two?
    By ice in forum Java IDEs
    Replies: 2
    Last Post: November 14th, 2010, 03:02 AM
  5. JFrame Edit
    By n00b123 in forum AWT / Java Swing
    Replies: 1
    Last Post: May 19th, 2010, 08:23 PM