plz help me for this difficult project

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tamara omar
    New Member
    • Sep 2006
    • 23

    plz help me for this difficult project

    i want to build a java program that can search for words in a text and can replace word by another one and the interface will be diveded as
    1-a large space for a text that is chosen by user
    2-a blank for written word
    3-find command button
    4-finf all command button
    5-replace button
    6-replace all
    i think these packages will help
    import java.util.regex .matcher;
    import java.util.regex .pattern;
    import java.util.strin gtokenizer;
    import java.util.vecto r;
    import java.io.*;


    plzzz help me
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by tamara omar
    i want to build a java program that can search for words in a text and can replace word by another one and the interface will be diveded as
    1-a large space for a text that is chosen by user
    2-a blank for written word
    3-find command button
    4-finf all command button
    5-replace button
    6-replace all
    i think these packages will help
    import java.util.regex .matcher;
    import java.util.regex .pattern;
    import java.util.strin gtokenizer;
    import java.util.vecto r;
    import java.io.*;


    plzzz help me
    If you are using regex, might as well do way with the StringTokenizer . Also replace that vector with an ArrayList.
    I suppose the text comes from a file so a JFileChooser will do.
    The best place to start for this is the interface. Play around with your swing and get the interface right. Help is easily available for more specific questions.

    Comment

    • tamara omar
      New Member
      • Sep 2006
      • 23

      #3
      i dont konw how to write a code in java and i must do this project ,can anyone do it for me,plzzzzz i need this so badly

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by tamara omar
        i dont konw how to write a code in java and i must do this project ,can anyone do it for me,plzzzzz i need this so badly
        When is the project due?

        Comment

        • tamara omar
          New Member
          • Sep 2006
          • 23

          #5
          after 2 weeks,on 29 october

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by tamara omar
            after 2 weeks,on 29 october
            You've got plenty of time to do it right.
            Let's start with the interface:
            Code:
            import javax.swing.*;
            import java.awt.event.*;
            import java.awt.Container;
            public class Tamara extends JFrame implements ActionListener { //is allowed to listen for actions
            	private Container pane;
            	public Tamara() {
            		pane = getContentPane(); //pane will now replace getContentPane() from now onwards
            		setTitle("Tamara Omar");
            		setSize(400, 400);
            		JPanel panel = new JPanel();
            
            
            
            		JButton edit = makeButton("Find");
            		JButton replace = makeButton("Replace");
            		//add the buttons to the panel
            		panel.add(edit);
            		panel.add(replace);
            		//add the panel to the frame at the bottom
            		pane.add(panel, "South");
            		setVisible(true);
            	}
            	public JButton makeButton(String label) { //creates a button
            		JButton jb = new JButton(label);
            		jb.setActionCommand(label); //This message will be set in the action for the button
            		jb.addActionListener(this); //this (JFrame) will respond to this button's press
            		return jb;
            	}
            
            	public void actionPerformed(ActionEvent action) {
            		String command = action.getActionCommand();
            		if(command.equals("Find")) {
            			JOptionPane.showMessageDialog(this, "Find");
            		}
            		else if(command.equals("Replace")) {
            			JOptionPane.showMessageDialog(this, "Replace");
            		}
            	}
            	public static void main(String[] args) {
            		new Tamara();
            	}
            }
            Look up anything you don't understand here. Post if you really won't find it in a textbook. If you feel that you get the hang of it, try to add all the buttons you need for the program and make sure they are responding to mouse click. Post when you are done. this should not take you more than 12 hours!

            Comment

            • tamara omar
              New Member
              • Sep 2006
              • 23

              #7
              i couldnt see the interface because i have this error
              Tamara is not abstract and does not override abstract method actionPerformed (java.awt.event .ActionEvent) in java.awt.event. ActionListener
              public class Tamara extends JFrame implements ActionListener { //is allowed to listen for actions

              Comment

              • tamara omar
                New Member
                • Sep 2006
                • 23

                #8
                i think that there are two missing buttons (find all, replace all) and the bordered space for the text that the user will enter to search for the missing word in it
                sorry for annoying u, and im so gratefull for helping me:)

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by tamara omar
                  i think that there are two missing buttons (find all, replace all) and the bordered space for the text that the user will enter to search for the missing word in it
                  sorry for annoying u, and im so gratefull for helping me:)
                  Ok one thing at a time. Can you compile and run the code above yet? Do a copy paste to take the code. It does not give an error on my compiler.


                  The two missing buttons will hopefully be added by you. We are going to look at the bordered space for the text next, after we've run and understood what we have so far.

                  Comment

                  • tamara omar
                    New Member
                    • Sep 2006
                    • 23

                    #10
                    i added (replace all) and( find all) and there is no error :)
                    import javax.swing.*;
                    import java.awt.event. *;
                    import java.awt.Contai ner;
                    public class Tamara1 extends JFrame implements ActionListener { //is allowed to listen for actions
                    private Container pane;
                    public Tamara1() {
                    pane = getContentPane( ); //pane will now replace getContentPane( ) from now onwards
                    setTitle("Tamar a Omar");
                    setSize(400, 400);
                    JPanel panel = new JPanel();



                    JButton edit = makeButton("Fin d");
                    JButton edit1= makeButton("fin d all");
                    JButton replace1=makeBu tton("replace all");
                    JButton replace = makeButton("Rep lace");
                    //add the buttons to the panel
                    panel.add(edit1 );
                    panel.add(repla ce1);
                    panel.add(edit) ;
                    panel.add(repla ce);
                    //add the panel to the frame at the bottom
                    pane.add(panel, "South");
                    setVisible(true );
                    }
                    public JButton makeButton(Stri ng label) { //creates a button
                    JButton jb = new JButton(label);
                    jb.setActionCom mand(label); //This message will be set in the action for the button
                    jb.addActionLis tener(this); //this (JFrame) will respond to this button's press
                    return jb;
                    }

                    public void actionPerformed (ActionEvent action)
                    {
                    String command = action.getActio nCommand();
                    if(command.equa ls("Find"))
                    {
                    JOptionPane.sho wMessageDialog( this, "Find");
                    }
                    else if(command.equa ls("Replace"))
                    {
                    JOptionPane.sho wMessageDialog( this, "Replace");
                    }
                    else if(command.equa ls("replace all"))
                    {
                    JOptionPane.sho wMessageDialog( this,"replace all");
                    }
                    else if(command.equa ls("find all"))
                    {
                    JOptionPane.sho wMessageDialog( this,"replace all");
                    }
                    }


                    public static void main(String[] args) {
                    new Tamara1();
                    }
                    }


                    what next?

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Code:
                      import javax.swing.*;
                      import java.awt.event.*;
                      import java.awt.Container;
                      import java.io.*;
                      import java.awt.*;
                      import java.util.Scanner;
                      public class Tamara2 extends JFrame implements ActionListener { //is allowed to listen for actions
                      	private Container pane;
                      	JTextArea area;
                      	JFileChooser fc;
                      	JPanel southPanel;
                      	JPanel northPanel;
                      	JScrollPane scrollPane;
                      	static private final String newline = "\n";
                      	public Tamara2() {
                      		pane = getContentPane(); //pane will now replace getContentPane() from now onwards
                      
                      
                      		setTitle("Tamara Omar");
                      		setSize(400, 400);
                      
                      
                      
                      		//
                      		fc = new JFileChooser();
                      		area = new JTextArea(10,20);
                      		scrollPane = new JScrollPane(area);
                      
                      		area.setMargin(new Insets(5,5,5,5));
                      		area.setEditable(true);
                      
                      
                      
                      		//make buttons
                      		JButton open = makeButton("Open");
                      		JButton save = makeButton("Save");
                      		JButton edit = makeButton("Find");
                      		JButton edit1= makeButton("find all");
                      		JButton replace1=makeButton("replace all");
                      		JButton replace = makeButton("Replace");
                      
                      		southPanel = new JPanel();
                      		northPanel = new JPanel();
                      		//add the buttons to the panel
                      		southPanel.add(edit1);
                      		southPanel.add(replace1);
                      		southPanel.add(edit);
                      		southPanel.add(replace);
                      		//add the panel to the frame at the bottom
                      
                      		northPanel.add(open);
                      		northPanel.add(save);
                      		pane.add(northPanel, "North");
                      		pane.add(scrollPane, "Center");
                      		pane.add(southPanel, "South");
                      
                      		setVisible(true);
                      }
                      public JButton makeButton(String label) { //creates a button
                      	JButton jb = new JButton(label);
                      	jb.setActionCommand(label); //This message will be set in the action for the button
                      	jb.addActionListener(this); //this (JFrame) will respond to this button's press
                      	return jb;
                      }
                      
                      public void actionPerformed(ActionEvent action) {
                      	String command = action.getActionCommand();
                      	if(command.equals("Find")) {
                      		JOptionPane.showMessageDialog(this, "Find");
                      	}
                      	else if(command.equals("Replace")) {
                      		JOptionPane.showMessageDialog(this, "Replace");
                      	}
                      	else if(command.equals("replace all")) {
                      		JOptionPane.showMessageDialog(this,"replace all");
                      	}
                      	else if(command.equals("find all"))	{
                      		JOptionPane.showMessageDialog(this,"replace all");
                      	}
                      	else if(command.equals("Open")) {
                      		int returnVal = fc.showOpenDialog(Tamara2.this);
                      		if (returnVal == JFileChooser.APPROVE_OPTION) {
                      			 File file = fc.getSelectedFile();
                      			 //This is where a real application would open the file.
                      			 Scanner inFile = null;
                      			 try {
                      				 inFile = new Scanner(new FileReader(file));
                      			 }
                      			 catch(IOException iOE) {
                      			 	iOE.printStackTrace();
                      			 }
                      			 while (inFile.hasNext()) {
                      			 	String line = inFile.nextLine();
                      			 	area.append(line + newline);
                      		 	 }
                      		 	 inFile.close();
                      	 	 }
                      	 	 else {
                      			 area.append("Open command cancelled by user." + newline);
                      		 }
                      		 area.setCaretPosition(area.getDocument().getLength());
                      	}
                      
                      }
                      
                      
                      public static void main(String[] args) {
                      	new Tamara2();
                      }
                      }
                      And so we come to that area of yours.
                      I have made use of
                      http://java.sun.com/docs/books/tutorial/uiswing/components/examples/FileChooserDemo .java
                      For the FileChooser.
                      Note that I am trying to get the basics of the programming running so that you can then work on it to perfection later. Make sure you understand what is going on so far.
                      I think one of your buttons is giving the wrong message.
                      If you understand this, we move over to designing how the user enters their search words

                      Comment

                      • soharto
                        New Member
                        • Oct 2006
                        • 2

                        #12
                        im arabic and i wnat help you mintaining your project so you can ask me via mail

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by soharto
                          im arabic and i wnat help you mintaining your project so you can ask me via mail
                          Hi Soharto, nice time to join in. Wouldn't you think that if you help him/her in this forum it would benefit others who read this thread as well rather than through email. Imagine everyone in Tamara's class requesting that you help them through email for the same project!

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #14
                            Signing off for the day now. You will see now that the rest of this exercise lies in manipulating methods of JTexArea and JTextComponent which should not take more than a day. You should now play around with those methods. Unless of course you've taken the email option.



                            God Bless

                            Comment

                            • tamara omar
                              New Member
                              • Sep 2006
                              • 23

                              #15
                              no im gonna be with u all the way,but there r more than one error :
                              tamara2.java=ca nt resolve symbol
                              import java.util.Scann er ; and the error sign is under the S !!!

                              Comment

                              Working...