Link to home
Start Free TrialLog in
Avatar of rachelee
racheleeFlag for Germany

asked on

Popup menu

Hello Experts,

I would like to have popup menu in text area such as cut ,copy, paste...so that as I right click with the mouse this all shaould come and work appropriately.

Please let me know how shall I start with it?

thnx a lot
Rachel
Avatar of sciuriware
sciuriware

From the tutorial by SUN:
To bring up a popup menu ( JPopupMenu), you must register a mouse listener on each component that the popup menu should be associated with. The mouse listener must detect user requests that the popup menu be brought up.

The exact gesture that should bring up a popup menu varies by look and feel. In Microsoft Windows, the user by convention brings up a popup menu by releasing the right mouse button while the cursor is over a component that is popup-enabled. In the Java look and feel, the customary trigger is either pressing the right mouse button (for a popup that goes away when the button is released) or clicking it (for a popup that stays up). In a future release, a new mechanism for automatically triggering popup menus in the appropriate way for the look and feel might be added; see bug #4634626.


The mouse listener brings up the popup menu by invoking the show method on the appropriate JPopupMenu instance.

;JOOP!
So, in general you set a MouseListener on the whole Frame.
The action can be started on MousePressed(MouseEvent e)
when e.isPopupTrigger() is true.

;JOOP!
Then you can display what you want.

;JOOP!
Avatar of Mick Barry
following shows you what you need:

http://www.javalobby.org/java/forums/t19867.html
Avatar of rachelee

ASKER

thnx all, I will check how can i use it in my prog!!
give me some time

thnx a lot
>> From the tutorial by SUN:
That's http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html.
(paragraph "Bringing Up a Popup Menu")
HEllo Mr Object,


thnx a lot...how shall I add those all menus in this, may i create subclasinside my label filename or how?

this below given is my prog, how shall I add popup menu into this?


                                JLabel fileNameLabel = new JLabel("File Name:");
            fileNameLabel.setBounds(10,45,130, 25);
            textFieldPanel.add(fileNameLabel);
            
            
            fileNameTextField.setBounds(100,45,225, 25);
            textFieldPanel.add(fileNameTextField);
            
            
            
            
            /*JPopupMenu popup = new JPopupMenu();
            JMenuItem menuItem1=new JMenuItem("First Item");
            menuItem1.addActionListener (this);
            popup.add(menuItem1);
            popup.setVisible(true);
            popup.show(frame,10,15);*/
>> how shall I add popup menu into this
Have a look at the link I posted
Hello Zzynx,

Yes I will just check how can I work with the link u posted..
thnx a lot for the same.
if you follow the code in  the link I posted you won't need to change your code at all
just add the following at the start of your main():

Toolkit.getDefaultToolkit().getSystemEventQueue().push(new MyEventQueue());
>> I will just check how can I work with the link u posted
Well, replace the variable 'component' in the link by yours: fileNameLabel and/or fileNameTextField
SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Zzynx

its ggiving error that missplaced construction...after four lines of above programm till the end line
You probably placed it outside a method.
no i did not, i placed it like below...

JLabel fileNameLabel = new JLabel("File Name:");
          fileNameLabel.setBounds(10,45,130, 25);
          textFieldPanel.add(fileNameLabel);
         
         
          fileNameTextField.setBounds(100,45,225, 25);
          textFieldPanel.add(fileNameTextField);

          final JPopupMenu popup = new JPopupMenu();
          JMenuItem menuItem1=new JMenuItem("First Item");
          menuItem1.addActionListener (this);
          popup.add(menuItem1);

          fileNameTextField.addMouseListener(new MouseAdapter() {
          public void mousePressed(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
                popup.show(evt.getComponent(), evt.getX(), evt.getY());
            }
          }
          public void mouseReleased(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
                popup.show(evt.getComponent(), evt.getX(), evt.getY());
            }
          }
      });
       
         
Where is the error (what line) and what exactly is the message. Which method have you written this code in?
I really do not understand java much . I have written below what I have done, And now I would like to have pop up menu for Filename and Directory text field, will u sort it out???


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import java.io.*;
import java.util.*;
import java.text.*;
import java.awt.event.*;


public class SmsManager extends JFrame{

      /** creates a Windows conform formated date and time string
         *  @return: data and time string
         */
        public static String getFormatedDateTime() {
          String s;
          Date t = new Date();
          t.getTime();
          s = DateFormat.getDateTimeInstance().format(t);
          
        
          return s;
        } // getFormatedDateTime

        /** creates a long value for the time
         *  @return: number of milliseconds since January 1, 1970,
         */
        public static long getLongTime() {
          long l;
          Date time = new Date();
          l = time.getTime();
          return l;
        } // getLongTime

      public void showDialog() {
            setSize(WIDTH, HEIGHT);
            setLocation(0, 0);
            //this.center();
            this.setTitle("SMS Manager");            
            layoutPanel();            
            this.setVisible(true);            
      }
      
      public void actionPerformed(ActionEvent event) {
          boolean loopbreak;
          int n, i;
          int[] index;
      }
      public void center() {
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

      //      this.setLocation( (d.width-getSize().width ) / 2,
                                // (d.height-getSize().height) / 2 );

      }

      private void layoutPanel() {
            //JLabel headinglabel = new JLabel("SMS MANAGER");
            //headinglabel.setBackground(Color.WHITE);
            //headinglabel.setBorder(new EmptyBorder(new Insets( 10, 10, 10, 10 )));
            
            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            
            JPanel textFieldPanel = new JPanel();
            textFieldPanel.setLayout(null);
            textFieldPanel.setBorder(new EtchedBorder());
            textFieldPanel.setBounds(0, HEIGHT - 97, 500, 30);
            textFieldPanel.setPreferredSize(new Dimension(125,50));
            
            JLabel directoryLabel = new JLabel("Directory:");
            directoryLabel.setBounds(10,10,130, 25);
            textFieldPanel.add(directoryLabel);
            
            //textFieldPanel.add(directoryTextField);
            
                        
            directoryTextField = new JTextField();
            directoryTextField.setBounds(100,10,225, 25);
      //      directoryTextField.setText(dirPath);
//            directoryTextField.disable(); // enabled by commenting this statement
            textFieldPanel.add(directoryTextField);
            directoryTextField.setText(dir);
            
            
            JLabel fileNameLabel = new JLabel("File Name:");
            fileNameLabel.setBounds(10,45,130, 25);
            textFieldPanel.add(fileNameLabel);
            
            
            fileNameTextField.setBounds(100,45,225, 25);
            textFieldPanel.add(fileNameTextField);
            
            final JPopupMenu popup=new JPopupMenu();
            JMenuItem menuItem1= new JmenuItem ("Cut");
            menuItem1.addActionListener(this);
            popup.add(menuItem1);
            
            fileNameTextField.addMouseListener(new MouseAdapter(){
                  public void mousePressed(mouseEvent evt){
                  if(evt.isPopupTrigger()){
                        popup.show(evt.getComponent(),evt.getX(),evt.getY());
                  }
                  }
                  
                  public void mouseReleased(mouseEvent evt){
                        if(evt.isPopupTrigger()){
                              popup.show(evt.getComponent(),evt.getX(),evt.getY());
                        }
                        }
                  
            });
            
            
            
            
            /*JPopupMenu popup = new JPopupMenu();
            JMenuItem menuItem1=new JMenuItem("First Item");
            menuItem1.addActionListener (this);
            popup.add(menuItem1);
            popup.setVisible(true);
            popup.show(frame,10,15);*/
            
            
            JLabel MatchingFilesLabel = new JLabel("Matching:");
            MatchingFilesLabel.setBounds(10,80,130, 25);
            textFieldPanel.add(MatchingFilesLabel);
            JLabel FilesLabel = new JLabel("Files Found:");
            FilesLabel.setBounds(10,90,130, 25);
            textFieldPanel.add(FilesLabel);
            
            JScrollPane sp = new JScrollPane (filesList);
            sp.setBounds(100,80,225,75);
            textFieldPanel.add(sp);
            
            sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            
            

            JLabel internationalPhoneNoLabel = new JLabel("Interntional");
            internationalPhoneNoLabel.setBounds(10,175,130, 25);
            textFieldPanel.add(internationalPhoneNoLabel);
            JLabel PhoneNoLabel = new JLabel("Phone Number:");
            PhoneNoLabel.setBounds(10,185,130, 25);
            textFieldPanel.add(PhoneNoLabel);
      //      scrollPane = new JScrollPane(textArea);
            
            
//            JTextField interPhoneNrTextField = new JTextField();
            interPhoneNrTextField.setBounds(100,175,225,25);
            textFieldPanel.add(interPhoneNrTextField);
            interPhoneNrTextField.setText(plus);
            

            
            
            //JLabel replaceLabel = new JLabel("Rename Sent File:");
            //replaceLabel.setBounds(10,275,130, 25);
            //textFieldPanel.add(replaceLabel);
            
            //renameSentFile = new JCheckBox();
            //renameSentFile.setBounds(146,275,20,20);
            //textFieldPanel.add(renameSentFile);

            JPanel buttonPanel = new JPanel();
            buttonPanel.setLayout(null);
            buttonPanel.setPreferredSize(new Dimension(125,200));

            
            JButton buttonSearch = new JButton("SEARCH");
            buttonSearch.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        
                        String fileNameSearchText = fileNameTextField.getText();
                        
                        if (!(fileNameSearchText.equals(""))){
                              File selectedFile = new File(directoryTextField.getText()); //For Not having Chooser Dialog
//                              File selectedFile = null;//this is when you want chooser
//                              selectedFile = showFileChooserDialog();  //this is when you want chooser
                              System.out.println(selectedFile.getName());
                              directoryTextField.setText(selectedFile.getPath());
                              
                              System.out.println(fileNameTextField.getText());
                              //File dir = new file (dirPath);
                              File dir = selectedFile;
                              System.out.println(dir.isDirectory());
                              TextFileFilter filter = new TextFileFilter(fileNameTextField.getText());
                              children = dir.list(filter);
                              if (children == null){
                                    System.out.println("Directory not exist or not a dir or no files found with specifications");
                              }
                              else{
                                    listModel.clear();
                                    for (int i = 0; i<children.length; i++){
                                    //      System.out.println(children[i]);                                          
                                          listModel.addElement(children[i]);
                                    }
                              }
                        
                              filesList.setModel(listModel);
                              
                              
                          }
                        
                        }
            });
                        
            buttonSearch.setBounds(20,15, 100, 30);
            buttonPanel.add(buttonSearch);
            
            
      /*      buttonIgnore = new JButton("IGNORE");
            buttonIgnore.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                         int index = filesList.getSelectedIndex();
                              listModel.remove(index);
                              
                              int size = listModel.getSize();
                              
                              if (size == 0){
                                    buttonIgnore.setEnabled(true);//To enable the ignore,searching files again.
                              }else{
                                    if(index == listModel.getSize()){
                                          index--;
                                    }
                                    filesList.setSelectedIndex(index);
                                    filesList.ensureIndexIsVisible(index);
                              }
                              
                              //filesList.setListData(children);
                              
                        }
                  
            });      
            
            buttonIgnore.setBounds(50, 65,100, 30);
            buttonPanel.add(buttonIgnore);      */
            
            JButton buttonSend = new JButton("SEND");
            buttonSend.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {                        
                        String absolutePath = directoryTextField.getText() + "\\" + filesList.getSelectedValue();
                        System.out.println("filesList. selectedva: " + filesList.getSelectedValue() );
                        TextParser tp = new TextParser(absolutePath);                        
                        String smsString = tp.getSmsString();      
                        //System.out.println("SMS String: " + smsString );
                        //System.out.println("SMS length: " + smsString.length() );
                        
                        String emailDialNumber = 00+interPhoneNrTextField.getText();
                        String smsDialNumber = 00+interPhoneNrTextField.getText();
                        try {
                          Port.open();
                          Msg.sendSMS(emailDialNumber, TOA_NATIONAL, smsString + "Testmail, PC send time: " + getFormatedDateTime());
                          Msg.sendSMS(smsDialNumber, TOA_INTERNATIONAL, "Test-SMS, PC send time: " + getFormatedDateTime());
                          Msg.sendSMS(emailDialNumber, TOA_NATIONAL, smsString);
                          Port.close();
                          
                          // Rename the sent file if the Rename Sent File checkbox is marked
                          if (renameSentFile.isSelected()) {
                                String renamedAbsolutePath = directoryTextField.getText() + "\\x" + filesList.getSelectedValue();
                                System.out.println(absolutePath + " File is Renamed " + renamedAbsolutePath);
                                File originalFile = new File(absolutePath);
                                File renamedFile = new File(renamedAbsolutePath);
                                originalFile.renameTo(renamedFile);                                
                          }
                          
                          
                        }  // try
                        catch (Exception e1) {
                          System.out.println("Exception in Main: " + e1);
                        }  // catch
                        
                        
                  }
                            //  {
                              //       File renameto = new File(file.getparent(),"existing" + file.getName());
                               //      file.renameTo(x + filename);
                              // }
                  
            });
            
            buttonSend.setBounds(20, 75,100, 30);
            buttonPanel.add(buttonSend);
            
            JButton buttonTimerStart = new JButton("AUTO SEND");
            buttonTimerStart.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        
                        ModelManager.currentDirectory = directoryTextField.getText();
                        //ModelManager.currentDirectory = matchingFiles;
                        ModelManager.currentFileNameSearchString = fileNameTextField.getText();
                        ModelManager.currentInternNumber = interPhoneNrTextField.getText();
                        //ModelManager.currentMatchingFilesSearchString = matchingFilesTextField.getText();//u added
                        
                        new TimelySearchAndSender();
                      
                  }
                          
                  
            });
            
            buttonTimerStart.setBounds(20, 135,100, 30);
            buttonPanel.add(buttonTimerStart);
            
            
      //      panel.add(headinglabel, BorderLayout.NORTH);
            panel.add(textFieldPanel, BorderLayout.CENTER);
            panel.add(buttonPanel, BorderLayout.EAST);

            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            getContentPane().add(BorderLayout.CENTER, panel);
      }
      

      
      File showFileChooserDialog(){
            EFileChooser chooser = new EFileChooser(ModelManager.currentDirectory,true);
            //chooser.setMultiSelectionEnabled(true);
            
            EFileFilter filter = new EFileFilter();
            //filter.addType("txt");
            //filter.setDescription("Text Files with SMS String");
            chooser.addFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            
            int returnVal = chooser.showOpenDialog(this);
            
            if (returnVal == EFileChooser.APPROVE_OPTION) {
                  //Parse the text file for SMS String
                  // if there is send it to mobile
                  File file = chooser.getSelectedFile();                  
//            showText("" + file.toString() + "    File is selected\n\n");
                  return file;      
            }
            return null;
      }
      
      public static void main(String[] args) {
            try {
                  UIManager.setLookAndFeel( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
            } catch ( Exception exception ) {
                  System.out.println( exception );
            }
            
            
            SmsManager smsManager = new SmsManager();
            smsManager.showDialog();
            
      }
      JTextField directoryTextField;
      JTextField MatchingFilesTextField;
      JCheckBox renameSentFile;
      JTextField fileNameTextField = new JTextField();
      //JTextField matchingFilesTextField = new JTextField();// u addaed
      
      String[] children;
      String[] fileNames = {""};
      DefaultListModel listModel = new DefaultListModel();
      //JList filesList = new JList(fileNames);            
      JList filesList = new JList();
      //JList filesList = new JScrollPanel();
      JButton buttonIgnore = null;
      
      private String plus = "";
      private String dir = "C:\\Programm\\Application Diagnostic Software \\Messages\\";
      
      
      private final static int WIDTH = 475;
      private final static int HEIGHT = 250;
      //private String dirPath = "";
      //private string matchingFiles = " ";// u added
      JTextField interPhoneNrTextField = new JTextField();  





thnx a lot
Rachel
This is not a valid program:
not closed by }
ans many lines at the end outside a method.

;JOOP!
Well I came to know thru error the same thing, I have not written any method for menuItem1.addActionListener(this);

how shall I write the method for the same?

rachelee, I answered your question long ago.
How long will you go on asking questions for the same 500 points?

;JOOP!
Hello Sciuriware,

I did run this program and worked as well.
only the problem now i am facing is >> I want to have popup menu in textfield of FILENAME and DIRECTORY
I guess its ok - you can just close it with a } after the last line:

>> JTextField interPhoneNrTextField = new JTextField();  

- because the data-members can be declared anywhere in the class (after methods) too. I'll compile it and see what are the other errors.
Add 'actionPerformed()' to your program.

;JOOP!
please if u can Mr Mayank
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Who is Mayank?

rachelee, is it possible to
1) post the program exactly as you have it
2) post the exact error message(s) you get
I can't compile all of it since I don't have Port and some other classes.

>> menuItem1.addActionListener(this);

Your class also needs to implement ActionListener.
>> Who is Mayank?

Yours truly.
I feel this question is hyjacked; I retreat.
>> Who is Mayank?
I *think* that's mayankeagle ;°)
error is in line

menuItem1.addActionListener (this);
saying
menuItemthe method addActionListener (ActionListener) in the type AbstractButton  is not applicable for the arguments(SmsManager)
ya Mayankeagle,

sorry i just did not typed last alphabates
Did you make your class implement ActionListener as sciuriware suggested?
>> menuItemthe method addActionListener (ActionListener) in the type AbstractButton  is not applicable for the arguments(SmsManager)

As sciuriware said:
>>Replace :
>>public class SmsManager extends JFrame
>>by:
>>public class SmsManager extends JFrame implements ActionListener
+
>> Add 'actionPerformed()' to your program. (= SmsManager class)
Mr sciuriware,

u were right
I did get popup menu thru ur answer, I just did implement  SMsmanager  extends JFrame implements ActionListener

thnx I would like to split the points, as Mr Mayankeagle gave me the codes for it but I did half code already thru Mr Zzynx as well,

thank u all brilliants.

best regards
Rachel
what shall I do if i want to add more items like paste and rename and blablab
Well i got on my own
thnx a lot
just add more JMenuItem's to the popup menu
You need to add more menu-items to you menu and implement the action-listener logic for them in your class. If you choose to use the same class, then you first need to find out the source of the event.

public void actionPerformed ( ActionEvent ae )
{
  Object source = ae.getSource () ;

  if ( source == menuItem1 )
  {
    // implement logic for cut
  }

  else if ( source == menuItem2 )
  {
    // implement logic for copy
  }

  // so on
}
Any Q's left related to this?
ya, sorry for late,

I tried to get it worked according to their functions like copy cut paste but its not working, shall i give what actions it has to perform when I say cut  or copy or anything which is in popup menu??

please let me know, thnx

Rachel
ya as u have given above, shall I implement logic for everything, or else if u have it ready, it would be good...

thnx a lot for everything

rachel
I don't have anything readily available for copy-paste but I guess you will find code here:

http://www.javapractices.com/Topic82.cjp

http://www.javaworld.com/javaworld/javatips/jw-javatip61.html
thnx i will try to implement it then,

thnx for the link , will see them and write back to u as soon as possible.

Hello Mr Mayankeagle

the very first line of this giving error, did not understand why?



public void actionPerformed ( ActionEvent ae )
{
  Object source = ae.getSource () ;

  if ( source == menuItem1 )
  {
    // implement logic for cut
  }
>> public void actionPerformed ( ActionEvent ae )

This line? What error? I hope you put it inside the class and outside all methods.
For being able to use the class ActionEvent you need to

import java.awt.event.*;
>> giving error
It's always a good idea to tell us WHAT error
Oh, well, did you make your class implement ActionListener? If yes, then it would give an error there too if the package is not imported.
syntax error on token ")",; is expected
yes zzynx

i have added already import java.awt.event.*;
>>Oh, well, did you make your class implement ActionListener? If yes, then it would give an error there too if the package is not imported

no error anywhere else than this??
>> no error anywhere else than this??

That's fine.

>> syntax error on token ")",; is expected

Post your updated code. Some statement/ block has not been closed or started properly.
JLabel internationalPhoneNoLabel = new JLabel("Interntional");
            internationalPhoneNoLabel.setBounds(10,175,130, 25);
            textFieldPanel.add(internationalPhoneNoLabel);
            JLabel PhoneNoLabel = new JLabel("Phone Number:");
            PhoneNoLabel.setBounds(10,185,130, 25);
            textFieldPanel.add(PhoneNoLabel);
      //      scrollPane = new JScrollPane(textArea);
            
            
//            JTextField interPhoneNrTextField = new JTextField();
            interPhoneNrTextField.setBounds(100,175,225,25);
            textFieldPanel.add(interPhoneNrTextField);
            interPhoneNrTextField.setText(plus);

            JPanel buttonPanel = new JPanel();
            buttonPanel.setLayout(null);
            buttonPanel.setPreferredSize(new Dimension(125,200));
            
            final JPopupMenu popupm=new JPopupMenu();
            JMenuItem menuItem01= new JMenuItem ("Cut");
            menuItem1.addActionListener(this);
            popup.add(menuItem1);
            popup.setVisible(true);
            
            JMenuItem menuItem02= new JMenuItem ("Copy");
            menuItem1.addActionListener(this);
            popup.add(menuItem2);
            popup.setVisible(true);
            
            JMenuItem menuItem03= new JMenuItem ("Paste");
            menuItem1.addActionListener(this);
            popup.add(menuItem3);
            popup.setVisible(true);
            
            JMenuItem menuItem04= new JMenuItem ("Rename");
            menuItem1.addActionListener(this);
            popup.add(menuItem4);
            popup.setVisible(true);
                  
            interPhoneNrTextField.addMouseListener(new MouseAdapter(){
                  public void mousePressed(MouseEvent evt){
                  if(evt.isPopupTrigger()){
                        popup.show(evt.getComponent(),evt.getX(),evt.getY());
                  }
                  }
                  
                  public void mouseReleased(MouseEvent evt){
                        if(evt.isPopupTrigger()){
                              popup.show(evt.getComponent(),evt.getX(),evt.getY());
                        }
                        }
                  
            });
            
            
            public void actionPerformed(ActionEvent ae){
                  Object source = ae.getSource();
                  
                   if (source==menuItem1){
                                    
                                    if (size == 0){
                                          menuItem1.setEnabled(true);
                                    }else{
                                          
                        
                  };      
                         
                   }
            }
>> public void actionPerformed(ActionEvent ae){

It has to be written after the current method is finished. That's why I said: >> "I hope you put it inside the class and outside all methods".

So put it outside that method as it is another method.
no i did everything ok as per my views, u please tell me how shall i do it now?

thnx
Like i said - it has to be outside the method. So you need to do:

>> public void mouseReleased(MouseEvent evt){
>> if(evt.isPopupTrigger()){
>> popup.show(evt.getComponent(),evt.getX(),evt.getY());
>> }
>> }
>> });

} // close this method here

public void actionPerformed ( ActionEvent ae ) { // start this as another method
I did it and now its showing error again, well i will see u after sometimes as its time to catch train , thnx being with me

Rachel
actionPerformed() is a method() like the method where
>> JLabel internationalPhoneNoLabel = new JLabel("Interntional");
is in, is a method.

So

public void whateverYourMethodIsCalled(...) {

    ...
    JLabel internationalPhoneNoLabel = new JLabel("Interntional");
    ...
    interPhoneNrTextField.addMouseListener(new MouseAdapter(){
               public void mousePressed(MouseEvent evt){
               if(evt.isPopupTrigger()){
                    popup.show(evt.getComponent(),evt.getX(),evt.getY());
               }
               }
               
               public void mouseReleased(MouseEvent evt){
                    if(evt.isPopupTrigger()){
                         popup.show(evt.getComponent(),evt.getX(),evt.getY());
                    }
                    }
               
     });
} // end of method whateverYourMethodIsCalled

public void actionPerformed(ActionEvent ae){
   ...
} // end of method actionPerformed()

>> now its showing error again
The same error?
Can you post the exact text?
This question has now a value of 3000 points ......................................
Well it is very tedious for me as i know very less about java programming but seems to be very easy for u all, i wish to increase point but only when I know how to do it??

thnx for the suggestion..

well coming to the important point , I would really want to have my poped up menu work according to their name i will send my all the code regarding to it now.....

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

import de.arvinmeritor.smstool.gui.utils.EFileChooser;
import de.arvinmeritor.smstool.gui.utils.EFileFilter;
import de.arvinmeritor.smstool.manager.ModelManager;

import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import java.io.*;
import java.util.*;
import java.text.*;
import java.awt.event.*;

import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import java.io.*;
import java.util.*;
import java.text.*;
import java.awt.event.*;

public class SmsManager extends JFrame implements ActionListener{

      /** creates a Windows conform formated date and time string
         *  @return: data and time string
         */
        public static String getFormatedDateTime() {
          String s;
          Date t = new Date();
          t.getTime();
          s = DateFormat.getDateTimeInstance().format(t);
          
        
          return s;
        } // getFormatedDateTime

        /** creates a long value for the time
         *  @return: number of milliseconds since January 1, 1970,
         */
        public static long getLongTime() {
          long l;
          Date time = new Date();
          l = time.getTime();
          return l;
        } // getLongTime

      public void showDialog() {
            setSize(WIDTH, HEIGHT);
            setLocation(0, 0);
            //this.center();
            this.setTitle("SMS Manager");            
            layoutPanel();            
            this.setVisible(true);            
      }
      
      public void actionPerformed(ActionEvent event) {
          boolean loopbreak;
          int n, i;
          int[] index;
      }
      public void center() {
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

      //      this.setLocation( (d.width-getSize().width ) / 2,
                                // (d.height-getSize().height) / 2 );

      }

      private void layoutPanel() {
            //JLabel headinglabel = new JLabel("SMS MANAGER");
            //headinglabel.setBackground(Color.WHITE);
            //headinglabel.setBorder(new EmptyBorder(new Insets( 10, 10, 10, 10 )));
            
            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            
            JPanel textFieldPanel = new JPanel();
            textFieldPanel.setLayout(null);
            textFieldPanel.setBorder(new EtchedBorder());
            textFieldPanel.setBounds(0, HEIGHT - 97, 500, 30);
            textFieldPanel.setPreferredSize(new Dimension(125,50));
            
            JLabel directoryLabel = new JLabel("Directory:");
            directoryLabel.setBounds(10,10,130, 25);
            textFieldPanel.add(directoryLabel);
            
            //textFieldPanel.add(directoryTextField);
            
                        
            directoryTextField = new JTextField();
            directoryTextField.setBounds(100,10,225, 25);
      //      directoryTextField.setText(dirPath);
//            directoryTextField.disable(); // enabled by commenting this statement
            textFieldPanel.add(directoryTextField);
            directoryTextField.setText(dir);
            
            
            JLabel fileNameLabel = new JLabel("File Name:");
            fileNameLabel.setBounds(10,45,130, 25);
            textFieldPanel.add(fileNameLabel);
            
            
            fileNameTextField.setBounds(100,45,225, 25);
            textFieldPanel.add(fileNameTextField);
            
            final JPopupMenu popup=new JPopupMenu();
            JMenuItem menuItem1= new JMenuItem ("Cut");
            menuItem1.addActionListener(this);
            popup.add(menuItem1);
            popup.setVisible(true);
            
            JMenuItem menuItem2= new JMenuItem ("Copy");
            menuItem1.addActionListener(this);
            popup.add(menuItem2);
            popup.setVisible(true);
            
            JMenuItem menuItem3= new JMenuItem ("Paste");
            menuItem1.addActionListener(this);
            popup.add(menuItem3);
            popup.setVisible(true);
            
            JMenuItem menuItem4= new JMenuItem ("Rename");
            menuItem1.addActionListener(this);
            popup.add(menuItem4);
            popup.setVisible(true);
                  
            fileNameTextField.addMouseListener(new MouseAdapter(){
                  public void mousePressed(MouseEvent evt){
                  if(evt.isPopupTrigger()){
                        popup.show(evt.getComponent(),evt.getX(),evt.getY());
                  }
                  }
                  
                  public void mouseReleased(MouseEvent evt){
                        if(evt.isPopupTrigger()){
                              popup.show(evt.getComponent(),evt.getX(),evt.getY());
                        }
                        }
                  
            });
            
            JLabel MatchingFilesLabel = new JLabel("Matching:");
            MatchingFilesLabel.setBounds(10,80,130, 25);
            textFieldPanel.add(MatchingFilesLabel);
            JLabel FilesLabel = new JLabel("Files Found:");
            FilesLabel.setBounds(10,90,130, 25);
            textFieldPanel.add(FilesLabel);
            
            JScrollPane sp = new JScrollPane (filesList);
            sp.setBounds(100,80,225,75);
            textFieldPanel.add(sp);
            
            sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
      
            
            JLabel internationalPhoneNoLabel = new JLabel("Interntional");
            internationalPhoneNoLabel.setBounds(10,175,130, 25);
            textFieldPanel.add(internationalPhoneNoLabel);
            JLabel PhoneNoLabel = new JLabel("Phone Number:");
            PhoneNoLabel.setBounds(10,185,130, 25);
            textFieldPanel.add(PhoneNoLabel);
      //      scrollPane = new JScrollPane(textArea);
            
            
//            JTextField interPhoneNrTextField = new JTextField();
            interPhoneNrTextField.setBounds(100,175,225,25);
            textFieldPanel.add(interPhoneNrTextField);
            interPhoneNrTextField.setText(plus);

            JPanel buttonPanel = new JPanel();
            buttonPanel.setLayout(null);
            buttonPanel.setPreferredSize(new Dimension(125,200));
            
            final JPopupMenu popupm=new JPopupMenu();
            JMenuItem menuItem01= new JMenuItem ("Cut");
            menuItem1.addActionListener(this);
            popup.add(menuItem1);
            popup.setVisible(true);
            
            JMenuItem menuItem02= new JMenuItem ("Copy");
            menuItem1.addActionListener(this);
            popup.add(menuItem2);
            popup.setVisible(true);
            
            JMenuItem menuItem03= new JMenuItem ("Paste");
            menuItem1.addActionListener(this);
            popup.add(menuItem3);
            popup.setVisible(true);
            
            JMenuItem menuItem04= new JMenuItem ("Rename");
            menuItem1.addActionListener(this);
            popup.add(menuItem4);
            popup.setVisible(true);
                  
            interPhoneNrTextField.addMouseListener(new MouseAdapter(){
                  public void mousePressed(MouseEvent evt){
                  if(evt.isPopupTrigger()){
                        popup.show(evt.getComponent(),evt.getX(),evt.getY());
                  }
                  }
                  
                  public void mouseReleased(MouseEvent evt){
                        if(evt.isPopupTrigger()){
                              popup.show(evt.getComponent(),evt.getX(),evt.getY());
                        }
                        }
                  
            });
      }
            
            public void actionPerformed1(ActionEvent ae){
                  Object source = ae.getSource();
                  
                   if (source==menuItem1){
                                    
                                    if (size == 0){
                                          menuItem1.setEnabled(true);
                                    }
                                          
                        
                  };      
                         
                  
            }
            
            
            

            
            JButton buttonSearch = new JButton("SEARCH");
            buttonSearch.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        
                        String fileNameSearchText = fileNameTextField.getText();
                        
                        if (!(fileNameSearchText.equals(""))){
                              File selectedFile = new File(directoryTextField.getText()); //For Not having Chooser Dialog
//                              File selectedFile = null;//this is when you want chooser
//                              selectedFile = showFileChooserDialog();  //this is when you want chooser
                              System.out.println(selectedFile.getName());
                              directoryTextField.setText(selectedFile.getPath());
                              
                              System.out.println(fileNameTextField.getText());
                              //File dir = new file (dirPath);
                              File dir = selectedFile;
                              System.out.println(dir.isDirectory());
                              TextFileFilter filter = new TextFileFilter(fileNameTextField.getText());
                              children = dir.list(filter);
                              if (children == null){
                                    System.out.println("Directory not exist or not a dir or no files found with specifications");
                              }
                              else{
                                    listModel.clear();
                                    for (int i = 0; i<children.length; i++){
                                    //      System.out.println(children[i]);                                          
                                          listModel.addElement(children[i]);
                                    }
                              }
                        
                              filesList.setModel(listModel);
                              
                              
                          }
                        
                        }
            });
                        
            buttonSearch.setBounds(20,15, 100, 30);
            buttonPanel.add(buttonSearch);
            
            
      /*      buttonIgnore = new JButton("IGNORE");
            buttonIgnore.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                         int index = filesList.getSelectedIndex();
                              listModel.remove(index);
                              
                              int size = listModel.getSize();
                              
                              if (size == 0){
                                    buttonIgnore.setEnabled(true);//To enable the ignore,searching files again.
                              }else{
                                    if(index == listModel.getSize()){
                                          index--;
                                    }
                                    filesList.setSelectedIndex(index);
                                    filesList.ensureIndexIsVisible(index);
                              }
                              
                              //filesList.setListData(children);
                              
                        }
                  
            });      
            
            buttonIgnore.setBounds(50, 65,100, 30);
            buttonPanel.add(buttonIgnore);      */
            
            JButton buttonSend = new JButton("SEND");
            buttonSend.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {                        
                        String absolutePath = directoryTextField.getText() + "\\" + filesList.getSelectedValue();
                        System.out.println("filesList. selectedva: " + filesList.getSelectedValue() );
                        TextParser tp = new TextParser(absolutePath);                        
                        String smsString = tp.getSmsString();      
                        //System.out.println("SMS String: " + smsString );
                        //System.out.println("SMS length: " + smsString.length() );
                        
                        String emailDialNumber = 00+interPhoneNrTextField.getText();
                        String smsDialNumber = 00+interPhoneNrTextField.getText();
                        try {
                          Port.open();
                          Msg.sendSMS(emailDialNumber, TOA_NATIONAL, smsString + "Testmail, PC send time: " + getFormatedDateTime());
                          Msg.sendSMS(smsDialNumber, TOA_INTERNATIONAL, "Test-SMS, PC send time: " + getFormatedDateTime());
                          Msg.sendSMS(emailDialNumber, TOA_NATIONAL, smsString);
                          Port.close();
                          
                          // Rename the sent file if the Rename Sent File checkbox is marked
                          if (renameSentFile.isSelected()) {
                                String renamedAbsolutePath = directoryTextField.getText() + "\\x" + filesList.getSelectedValue();
                                System.out.println(absolutePath + " File is Renamed " + renamedAbsolutePath);
                                File originalFile = new File(absolutePath);
                                File renamedFile = new File(renamedAbsolutePath);
                                originalFile.renameTo(renamedFile);                                
                          }
                          
                          
                        }  // try
                        catch (Exception e1) {
                          System.out.println("Exception in Main: " + e1);
                        }  // catch
                        
                        
                  }
                            //  {
                              //       File renameto = new File(file.getparent(),"existing" + file.getName());
                               //      file.renameTo(x + filename);
                              // }
                  
            });
            
            buttonSend.setBounds(20, 75,100, 30);
            buttonPanel.add(buttonSend);
            
            JButton buttonTimerStart = new JButton("AUTO SEND");
            buttonTimerStart.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        
                        ModelManager.currentDirectory = directoryTextField.getText();
                        //ModelManager.currentDirectory = matchingFiles;
                        ModelManager.currentFileNameSearchString = fileNameTextField.getText();
                        ModelManager.currentInternNumber = interPhoneNrTextField.getText();
                        //ModelManager.currentMatchingFilesSearchString = matchingFilesTextField.getText();//u added
                        
                        new TimelySearchAndSender();
                      
                  }
                          
                  
            });
            
            buttonTimerStart.setBounds(20, 135,100, 30);
            buttonPanel.add(buttonTimerStart);
            
            
      //      panel.add(headinglabel, BorderLayout.NORTH);
            panel.add(textFieldPanel, BorderLayout.CENTER);
            panel.add(buttonPanel, BorderLayout.EAST);

            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            getContentPane().add(BorderLayout.CENTER, panel);
      }
      

      
      File showFileChooserDialog(){
            EFileChooser chooser = new EFileChooser(ModelManager.currentDirectory,true);
            //chooser.setMultiSelectionEnabled(true);
            
            EFileFilter filter = new EFileFilter();
            //filter.addType("txt");
            //filter.setDescription("Text Files with SMS String");
            chooser.addFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            
            int returnVal = chooser.showOpenDialog(this);
            
            if (returnVal == EFileChooser.APPROVE_OPTION) {
                  //Parse the text file for SMS String
                  // if there is send it to mobile
                  File file = chooser.getSelectedFile();                  
//            showText("" + file.toString() + "    File is selected\n\n");
                  return file;      
            }
            return null;
      }
      
      
      
      public static void main(String[] args) {
            try {
                  UIManager.setLookAndFeel( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
            } catch ( Exception exception ) {
                  System.out.println( exception );
            }
            
            
            SmsManager smsManager = new SmsManager();
            smsManager.showDialog();
            
      }
      JTextField directoryTextField;
      JTextField MatchingFilesTextField;
      JCheckBox renameSentFile;
      JTextField fileNameTextField = new JTextField();
      JTextField matchingFilesFoundTextField = new JTextField();
      //JTextField matchingFilesTextField = new JTextField();// u addaed
      
      String[] children;
      String[] fileNames = {""};
      DefaultListModel listModel = new DefaultListModel();
      //JList filesList = new JList(fileNames);            
      JList filesList = new JList();
      //JList filesList = new JScrollPanel();
      JButton buttonIgnore = null;
      
      private String plus = "+9198793009";
      private String dir = "C:\\Programm\\Messages\\";
      
      
      private final static int WIDTH = 475;
      private final static int HEIGHT = 250;
      //private String dirPath = "";
      //private string matchingFiles = " ";// u added
      JTextField interPhoneNrTextField = new JTextField();  
      
      static final boolean TOA_NATIONAL = true;
        // TOA = type of address (= type of number || numbering plan identifier)
        // it is a international dialing number format (0x91, e.g. usual number format for normal calls)
        static final boolean TOA_INTERNATIONAL = true;  
        static final String SMSTEXTSIGN = ">";            // sign for the begin of the SMS text
        static final int TIMEOUT = 2*30*1000;             // timeout [ms] for SMS run time measurement
        static final int MAXNOSIMSMS = 20;                // maximal number of stored SMS in SIM
//        static final String SMSDIALNO = "757576";    // dialing number for SMS transmission, this is the number of the phone you want to send the SMS
//        static final String EMAILDIALNO = "68666";         // dialing number for eMail transmission, this is the number you have to dial if you want to convert a SMS into a e-Mail
//        static final String EMAILADR = "Hello There from Preeti";  // eMail adress
        static final String COMPORT = "COM6";             // used COM port for data transmission

}







You can't increase the points as its already a 500-point question.

Are there any compilation/ runtime errors in the code? If so, where?
Ok thnx for making me understand about points.

Frankly speaking there is nothing which I can understand about java properly, I just do not know all the things yet but would like to know and try the same.

Now in my program I have created popup menu and not the working of menu such as copy, cut , paste, open , rename .

So would like to have code for the same.

where shall I put that code and how?

thnx a lot for all
Rachel
there is an error at last line of below programm, Please check it and let me know, as I have not implemented any logic for cut copy paste, I would like to know that too.

JLabel internationalPhoneNoLabel = new JLabel("Interntional");
            internationalPhoneNoLabel.setBounds(10,175,130, 25);
            textFieldPanel.add(internationalPhoneNoLabel);
            JLabel PhoneNoLabel = new JLabel("Phone Number:");
            PhoneNoLabel.setBounds(10,185,130, 25);
            textFieldPanel.add(PhoneNoLabel);
      //      scrollPane = new JScrollPane(textArea);
            
      
//            JTextField interPhoneNrTextField = new JTextField();
            interPhoneNrTextField.setBounds(100,175,225,25);
            textFieldPanel.add(interPhoneNrTextField);
            interPhoneNrTextField.setText(plus);

            JPanel buttonPanel = new JPanel();
            buttonPanel.setLayout(null);
            buttonPanel.setPreferredSize(new Dimension(125,200));
            
            final JPopupMenu popupm=new JPopupMenu();
            JMenuItem menuItem01= new JMenuItem ("Cut");
            menuItem1.addActionListener(this);
            popup.add(menuItem1);
            popup.setVisible(true);
            
            JMenuItem menuItem02= new JMenuItem ("Copy");
            menuItem1.addActionListener(this);
            popup.add(menuItem2);
            popup.setVisible(true);
            
            JMenuItem menuItem03= new JMenuItem ("Paste");
            menuItem1.addActionListener(this);
            popup.add(menuItem3);
            popup.setVisible(true);
            
            JMenuItem menuItem04= new JMenuItem ("Rename");
            menuItem1.addActionListener(this);
            popup.add(menuItem4);
            popup.setVisible(true);
                  
            interPhoneNrTextField.addMouseListener(new MouseAdapter(){
                  public void mousePressed(MouseEvent evt){
                  if(evt.isPopupTrigger()){
                        popup.show(evt.getComponent(),evt.getX(),evt.getY());
                  }
                  }
                  
                  public void mouseReleased(MouseEvent evt){
                        if(evt.isPopupTrigger()){
                              popup.show(evt.getComponent(),evt.getX(),evt.getY());
                        }
                        }
                  
            });
      }
            
            public void actionPerformed1(ActionEvent ae){
                  Object source = ae.getSource();
                  
                   if (source==menuItem1){
                                    
                                    if (size == 0){
                                          menuItem1.setEnabled(true);
                                    }
                                          
                        
                  };      
                         
                  
            }"this line." error is "Syntax error on token "}", delete this token"
See the code at: >> http://www.javapractices.com/Topic82.cjp

You need to make a similar TextTransfer class. In your actionPerformed (), if the source was JMenuItem1 (for Cut), for example, then use:

textTransfer.setClipboardContents ( "whatever" ) ;

If the Paste menu-item was clicked, then paste it into the text-field which has focus using textTransfer.getClipboardContents () ;
>>  };    

Remove the semi-colon from there.

>> public void actionPerformed1(ActionEvent ae){
>> Object source = ae.getSource();
>> if (source==menuItem1){
>> if (size == 0){
>> menuItem1.setEnabled(true);
>> }
>> };    
>> }

The code after this is not in a method. You should instead remove this actionPerformed () method from there and paste it after the last line:

>> File showFileChooserDialog(){
....
>> return null;
>> }

After this - you can paste the actionPerformed () method.


         
HEllo there,

Sorry i was on vacation so could not be in touch, will u please tell me how shall i implement my pop up menu, I still facing the same problem.

regards
Rachel
You implemented the changes we suggested above?
>> I still facing the same problem.

Can you post your updated code after implementing the changes we mentioned?
>> plese, still need to have ur comment or assistance, I really do not understand java very well and , which method i have to close? let me know here .

my codes are as follows

import java.awt.BorderLayout;
//import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.*;
import java.awt.event.ActionEvent.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import java.io.*;
import java.util.*;
import java.text.*;
//import java.awt.*;
import java.awt.event.*;
//import javax.swing.*;
//import javax.swing.filechooser.*;
//import javax.swing.border.*;
//import java.beans.*;



public class SmsManager extends JFrame implements ActionListener{

      /** creates a Windows conform formated date and time string
         *  @return: data and time string
         */
        public static String getFormatedDateTime() {
          String s;
          Date t = new Date();
          t.getTime();
          s = DateFormat.getDateTimeInstance().format(t);
          
        
          return s;
        } // getFormatedDateTime

        /** creates a long value for the time
         *  @return: number of milliseconds since January 1, 1970,
         */
        public static long getLongTime() {
          long l;
          Date time = new Date();
          l = time.getTime();
          return l;
        } // getLongTime

      public void showDialog() {
            setSize(WIDTH, HEIGHT);
            setLocation(0, 0);
            //this.center();
            this.setTitle("SMS Manager");            
            layoutPanel();            
            this.setVisible(true);            
      }//Show dialog
      
      public void actionPerformed(ActionEvent event) {
          boolean loopbreak;
          int n, i;
          int[] index;
      }
      public void center() {
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

      //      this.setLocation( (d.width-getSize().width ) / 2,
                                // (d.height-getSize().height) / 2 );

      }//Center

      private void layoutPanel() {
            //JLabel headinglabel = new JLabel("SMS MANAGER");
            //headinglabel.setBackground(Color.WHITE);
            //headinglabel.setBorder(new EmptyBorder(new Insets( 10, 10, 10, 10 )));
            
            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            
            JPanel textFieldPanel = new JPanel();
            textFieldPanel.setLayout(null);
            textFieldPanel.setBorder(new EtchedBorder());
            textFieldPanel.setBounds(0, HEIGHT - 97, 500, 30);
            textFieldPanel.setPreferredSize(new Dimension(125,50));
            
            JLabel directoryLabel = new JLabel("Directory:");
            directoryLabel.setBounds(10,10,130, 25);
            textFieldPanel.add(directoryLabel);
            
            //textFieldPanel.add(directoryTextField);
            
                        
            directoryTextField = new JTextField();
            directoryTextField.setBounds(100,10,225, 25);
      //      directoryTextField.setText(dirPath);
//            directoryTextField.disable(); // enabled by commenting this statement
            textFieldPanel.add(directoryTextField);
            directoryTextField.setText(dir);
            
            
            JLabel fileNameLabel = new JLabel("File Name:");
            fileNameLabel.setBounds(10,45,130, 25);
            textFieldPanel.add(fileNameLabel);
            
            
            fileNameTextField.setBounds(100,45,225, 25);
            textFieldPanel.add(fileNameTextField);
            
            final JPopupMenu popup=new JPopupMenu();
            JMenuItem menuItem1= new JMenuItem ("Cut");
            menuItem1.addActionListener(this);
            popup.add(menuItem1);
            popup.setVisible(true);
            
            JMenuItem menuItem2= new JMenuItem ("Copy");
            menuItem1.addActionListener(this);
            popup.add(menuItem2);
            popup.setVisible(true);
            
            JMenuItem menuItem3= new JMenuItem ("Paste");
            menuItem1.addActionListener(this);
            popup.add(menuItem3);
            popup.setVisible(true);
            
            JMenuItem menuItem4= new JMenuItem ("Rename");
            menuItem1.addActionListener(this);
            popup.add(menuItem4);
            popup.setVisible(true);
            
            JMenuItem menuItem5= new JMenuItem ("Delete");
            menuItem1.addActionListener(this);
            popup.add(menuItem5);
            popup.setVisible(true);
      
            
            
                  
      fileNameTextField.addMouseListener(new MouseAdapter(){
                  public void mousePressed(MouseEvent evt){
                  if(evt.isPopupTrigger()){
                        popup.show(evt.getComponent(),evt.getX(),evt.getY());

                                    }
                  }
                  
                  public void mouseReleased(MouseEvent evt){
                        if(evt.isPopupTrigger()){
                              popup.show(evt.getComponent(),evt.getX(),evt.getY());
                        }
                        }
                  
            });
            
            
            
            
            JLabel MatchingFilesLabel = new JLabel("Matching:");
            MatchingFilesLabel.setBounds(10,80,130, 25);
            textFieldPanel.add(MatchingFilesLabel);
            JLabel FilesLabel = new JLabel("Files Found:");
            FilesLabel.setBounds(10,90,130, 25);
            textFieldPanel.add(FilesLabel);
            
            JScrollPane sp = new JScrollPane (filesList);
            sp.setBounds(100,80,225,75);
            textFieldPanel.add(sp);
            
            sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
      
            
            JLabel internationalPhoneNoLabel = new JLabel("Interntional");
            internationalPhoneNoLabel.setBounds(10,175,130, 25);
            textFieldPanel.add(internationalPhoneNoLabel);
            JLabel PhoneNoLabel = new JLabel("Phone Number:");
            PhoneNoLabel.setBounds(10,185,130, 25);
            textFieldPanel.add(PhoneNoLabel);
      //      scrollPane = new JScrollPane(textArea);
            
            
//            JTextField interPhoneNrTextField = new JTextField();
            interPhoneNrTextField.setBounds(100,175,225,25);
            textFieldPanel.add(interPhoneNrTextField);
            interPhoneNrTextField.setText(plus);

            JPanel buttonPanel = new JPanel();
            buttonPanel.setLayout(null);
            buttonPanel.setPreferredSize(new Dimension(125,200));
            
            final JPopupMenu popupm=new JPopupMenu();
            JMenuItem menuItem01= new JMenuItem ("Cut");
            menuItem1.addActionListener(this);
            popup.add(menuItem1);
            popup.setVisible(true);
            
            JMenuItem menuItem02= new JMenuItem ("Copy");
            menuItem1.addActionListener(this);
            popup.add(menuItem2);
            popup.setVisible(true);
            
            JMenuItem menuItem03= new JMenuItem ("Paste");
            menuItem1.addActionListener(this);
            popup.add(menuItem3);
            popup.setVisible(true);
            
            JMenuItem menuItem04= new JMenuItem ("Rename");
            menuItem1.addActionListener(this);
            popup.add(menuItem4);
            popup.setVisible(true);
                  
            interPhoneNrTextField.addMouseListener(new MouseAdapter(){
                  public void mousePressed(MouseEvent evt){
                  if(evt.isPopupTrigger()){
                        popup.show(evt.getComponent(),evt.getX(),evt.getY());
                  }//if
                  }//Mousepressed
                  
                  public void mouseReleased(MouseEvent evt){
                        if(evt.isPopupTrigger()){
                              popup.show(evt.getComponent(),evt.getX(),evt.getY());
                        }//If
                        }//Mouserealesed
                  
            });//Mouselistener
            
      
      
      

      public void actionPerformed1(ActionEvent ae){
            Object source = ae.getSource();
            
             if (source==menuItem1){
                              
                              if (size == 0){
                                    menuItem1.setEnabled(true);
                              }
                                    
                  
             }
                   
            
      };
      
            JButton buttonSearch = new JButton("SEARCH");
            buttonSearch.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        
                        String fileNameSearchText = fileNameTextField.getText();
                        
                        if (!(fileNameSearchText.equals(""))){
                              File selectedFile = new File(directoryTextField.getText()); //For Not having Chooser Dialog
//                              File selectedFile = null;//this is when you want chooser
//                              selectedFile = showFileChooserDialog();  //this is when you want chooser
                              System.out.println(selectedFile.getName());
                              directoryTextField.setText(selectedFile.getPath());
                              
                              System.out.println(fileNameTextField.getText());
                              //File dir = new file (dirPath);
                              File dir = selectedFile;
                              System.out.println(dir.isDirectory());
                              TextFileFilter filter = new TextFileFilter(fileNameTextField.getText());
                              children = dir.list(filter);
                              if (children == null){
                                    System.out.println("Directory not exist or not a dir or no files found with specifications");
                              }
                              else{
                                    listModel.clear();
                                    for (int i = 0; i<children.length; i++){
                                    //      System.out.println(children[i]);                                          
                                          listModel.addElement(children[i]);
                                    }
                              }
                        
                              filesList.setModel(listModel);
                              
                              
                          }
                        
                        }
            });
                        
            buttonSearch.setBounds(20,15, 100, 30);
            buttonPanel.add(buttonSearch);
            
            
      /*      buttonIgnore = new JButton("IGNORE");
            buttonIgnore.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                         int index = filesList.getSelectedIndex();
                              listModel.remove(index);
                              
                              int size = listModel.getSize();
                              
                              if (size == 0){
                                    buttonIgnore.setEnabled(true);//To enable the ignore,searching files again.
                              }else{
                                    if(index == listModel.getSize()){
                                          index--;
                                    }
                                    filesList.setSelectedIndex(index);
                                    filesList.ensureIndexIsVisible(index);
                              }
                              
                              //filesList.setListData(children);
                              
                        }
                  
            });      
            
            buttonIgnore.setBounds(50, 65,100, 30);
            buttonPanel.add(buttonIgnore);      */
            
            JButton buttonSend = new JButton("SEND");
            buttonSend.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {                        
                        String absolutePath = directoryTextField.getText() + "\\" + filesList.getSelectedValue();
                        System.out.println("filesList. selectedva: " + filesList.getSelectedValue() );
                        TextParser tp = new TextParser(absolutePath);                        
                        String smsString = tp.getSmsString();      
                        //System.out.println("SMS String: " + smsString );
                        //System.out.println("SMS length: " + smsString.length() );
                        
                        String emailDialNumber = 00+interPhoneNrTextField.getText();
                        String smsDialNumber = 00+interPhoneNrTextField.getText();
                        try {
                          Port.open();
                          Msg.sendSMS(emailDialNumber, TOA_NATIONAL, smsString + "Testmail, PC send time: " + getFormatedDateTime());
                          Msg.sendSMS(smsDialNumber, TOA_INTERNATIONAL, "Test-SMS, PC send time: " + getFormatedDateTime());
                          Msg.sendSMS(emailDialNumber, TOA_NATIONAL, smsString);
                          Port.close();
                          
                          // Rename the sent file if the Rename Sent File checkbox is marked
                          if (renameSentFile.isSelected()) {
                                String renamedAbsolutePath = directoryTextField.getText() + "\\x" + filesList.getSelectedValue();
                                System.out.println(absolutePath + " File is Renamed " + renamedAbsolutePath);
                                File originalFile = new File(absolutePath);
                                File renamedFile = new File(renamedAbsolutePath);
                                originalFile.renameTo(renamedFile);                                
                          }//If
                          
                          
                        }  // try
                        catch (Exception e1) {
                          System.out.println("Exception in Main: " + e1);
                        }  // catch
                        
                        
                  }//Try
                            //  {
                              //       File renameto = new File(file.getparent(),"existing" + file.getName());
                               //      file.renameTo(x + filename);
                              // }
                  
            });//Action performed
            
            buttonSend.setBounds(20, 75,100, 30);
            buttonPanel.add(buttonSend);
            
            JButton buttonTimerStart = new JButton("AUTO SEND");
            buttonTimerStart.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        
                        ModelManager.currentDirectory = directoryTextField.getText();
                        //ModelManager.currentDirectory = matchingFiles;
                        ModelManager.currentFileNameSearchString = fileNameTextField.getText();
                        ModelManager.currentInternNumber = interPhoneNrTextField.getText();
                        //ModelManager.currentMatchingFilesSearchString = matchingFilesTextField.getText();//u added
                        
                        new TimelySearchAndSender();
                      
                  }// Autosend
                          
                  
            });//Layout panel
            
            buttonTimerStart.setBounds(20, 135,100, 30);
            buttonPanel.add(buttonTimerStart);
            
            
      //      panel.add(headinglabel, BorderLayout.NORTH);
            panel.add(textFieldPanel, BorderLayout.CENTER);
            panel.add(buttonPanel, BorderLayout.EAST);

            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            getContentPane().add(BorderLayout.CENTER, panel);
      }
      

      
      File showFileChooserDialog(){
            EFileChooser chooser = new EFileChooser(ModelManager.currentDirectory,true);
            //chooser.setMultiSelectionEnabled(true);
            
            EFileFilter filter = new EFileFilter();
            //filter.addType("txt");
            //filter.setDescription("Text Files with SMS String");
            chooser.addFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            
            int returnVal = chooser.showOpenDialog(this);
            
            if (returnVal == EFileChooser.APPROVE_OPTION) {
                  //Parse the text file for SMS String
                  // if there is send it to mobile
                  File file = chooser.getSelectedFile();                  
//            showText("" + file.toString() + "    File is selected\n\n");
                  return file;      
            }
            return null;
      }
      
      
      
      public static void main(String[] args) {
            try {
                  UIManager.setLookAndFeel( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
            } catch ( Exception exception ) {
                  System.out.println( exception );
            }
            
            
            SmsManager smsManager = new SmsManager();
            smsManager.showDialog();
            
      }
      JTextField directoryTextField;
      JTextField MatchingFilesTextField;
      JCheckBox renameSentFile;
      JTextField fileNameTextField = new JTextField();
      JTextField matchingFilesFoundTextField = new JTextField();
      //JTextField matchingFilesTextField = new JTextField();// u addaed
      
      String[] children;
      String[] fileNames = {""};
      DefaultListModel listModel = new DefaultListModel();
      //JList filesList = new JList(fileNames);            
      JList filesList = new JList();
      //JList filesList = new JScrollPanel();
      JButton buttonIgnore = null;
      
      private String plus = "  ";
      private String dir = "C:\\Programm";
      
      
      private final static int WIDTH = 475;
      private final static int HEIGHT = 250;
      //private String dirPath = "";
      //private string matchingFiles = " ";// u added
      JTextField interPhoneNrTextField = new JTextField();  
      
      static final boolean TOA_NATIONAL = true;
        // TOA = type of address (= type of number || numbering plan identifier)
        // it is a international dialing number format (0x91, e.g. usual number format for normal calls)
        static final boolean TOA_INTERNATIONAL = true;  
        static final String SMSTEXTSIGN = ">";            // sign for the begin of the SMS text
        static final int TIMEOUT = 2*30*1000;             // timeout [ms] for SMS run time measurement
        static final int MAXNOSIMSMS = 20;                // maximal number of stored SMS in SIM
//        static final String SMSDIALNO = "  ";    // dialing number for SMS transmission, this is the number of the phone you want to send the SMS
//        static final String EMAILDIALNO = "  ";         // dialing number for eMail transmission, this is the number you have to dial if you want to convert a SMS into a e-Mail
//        static final String EMAILADR = "  hello there ";  // eMail adress
        static final String COMPORT = "COM6";             // used COM port for data transmission

}

>> t.getTime();

What's that for? Its not required.

>> which method i have to close?

Can you elaborate on what the error is, now?
thnx a lot for ur help i will give u the points as u did help me , on whta i wanted , thnx  a lot

best regards
Rachel
Thanx