[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

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
0
rachelee
Asked:
rachelee
  • 30
  • 22
  • 14
  • +2
3 Solutions
 
sciuriwareCommented:
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!
0
 
sciuriwareCommented:
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!
0
 
sciuriwareCommented:
Then you can display what you want.

;JOOP!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
following shows you what you need:

http://www.javalobby.org/java/forums/t19867.html
0
 
racheleeAuthor Commented:
thnx all, I will check how can i use it in my prog!!
give me some time

thnx a lot
0
 
zzynxSoftware engineerCommented:
>> From the tutorial by SUN:
That's http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html.
(paragraph "Bringing Up a Popup Menu")
0
 
zzynxSoftware engineerCommented:
0
 
racheleeAuthor Commented:
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);*/
0
 
zzynxSoftware engineerCommented:
>> how shall I add popup menu into this
Have a look at the link I posted
0
 
racheleeAuthor Commented:
Hello Zzynx,

Yes I will just check how can I work with the link u posted..
thnx a lot for the same.
0
 
objectsCommented:
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());
0
 
zzynxSoftware engineerCommented:
>> 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
0
 
zzynxSoftware engineerCommented:
         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());
            }
          }
      });

         
0
 
racheleeAuthor Commented:
Zzynx

its ggiving error that missplaced construction...after four lines of above programm till the end line
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You probably placed it outside a method.
0
 
racheleeAuthor Commented:
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());
            }
          }
      });
       
         
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Where is the error (what line) and what exactly is the message. Which method have you written this code in?
0
 
racheleeAuthor Commented:
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
0
 
sciuriwareCommented:
This is not a valid program:
not closed by }
ans many lines at the end outside a method.

;JOOP!
0
 
racheleeAuthor Commented:
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?

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

;JOOP!
0
 
racheleeAuthor Commented:
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
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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.
0
 
sciuriwareCommented:
Add 'actionPerformed()' to your program.

;JOOP!
0
 
racheleeAuthor Commented:
please if u can Mr Mayank
0
 
sciuriwareCommented:
Replace :

public class SmsManager extends JFrame

by:

public class SmsManager extends JFrame implements ActionListener

and you'll find out how.

;JOOP!
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> JMenuItem menuItem1= new JmenuItem ("Cut");

Should be: JMenuItem menuItem1 =  new JMenuItem ( "Cut" ) ;

>> public void mousePressed(mouseEvent evt){

Should be: public void mousePressed ( MouseEvent evt ){

>> public void mouseReleased(mouseEvent evt) {

Should be: public void mouseReleased ( MouseEvent evt ) {
0
 
sciuriwareCommented:
Who is Mayank?

0
 
zzynxSoftware engineerCommented:
rachelee, is it possible to
1) post the program exactly as you have it
2) post the exact error message(s) you get
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> Who is Mayank?

Yours truly.
0
 
sciuriwareCommented:
I feel this question is hyjacked; I retreat.
0
 
zzynxSoftware engineerCommented:
>> Who is Mayank?
I *think* that's mayankeagle ;°)
0
 
racheleeAuthor Commented:
error is in line

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

sorry i just did not typed last alphabates
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Did you make your class implement ActionListener as sciuriware suggested?
0
 
zzynxSoftware engineerCommented:
>> 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)
0
 
racheleeAuthor Commented:
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
0
 
racheleeAuthor Commented:
what shall I do if i want to add more items like paste and rename and blablab
0
 
racheleeAuthor Commented:
Well i got on my own
thnx a lot
0
 
zzynxSoftware engineerCommented:
just add more JMenuItem's to the popup menu
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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
}
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Any Q's left related to this?
0
 
racheleeAuthor Commented:
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
0
 
racheleeAuthor Commented:
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
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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
0
 
racheleeAuthor Commented:
thnx i will try to implement it then,

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

0
 
racheleeAuthor Commented:
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
  }
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> public void actionPerformed ( ActionEvent ae )

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

import java.awt.event.*;
0
 
zzynxSoftware engineerCommented:
>> giving error
It's always a good idea to tell us WHAT error
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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.
0
 
racheleeAuthor Commented:
syntax error on token ")",; is expected
0
 
racheleeAuthor Commented:
yes zzynx

i have added already import java.awt.event.*;
0
 
racheleeAuthor Commented:
>>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??
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> 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.
0
 
racheleeAuthor Commented:
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{
                                          
                        
                  };      
                         
                   }
            }
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> 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.
0
 
racheleeAuthor Commented:
no i did everything ok as per my views, u please tell me how shall i do it now?

thnx
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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
0
 
racheleeAuthor Commented:
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
0
 
zzynxSoftware engineerCommented:
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()

0
 
zzynxSoftware engineerCommented:
>> now its showing error again
The same error?
Can you post the exact text?
0
 
sciuriwareCommented:
This question has now a value of 3000 points ......................................
0
 
Mayank SAssociate Director - Product EngineeringCommented:
:-)
0
 
racheleeAuthor Commented:
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

}







0
 
Mayank SAssociate Director - Product EngineeringCommented:
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?
0
 
racheleeAuthor Commented:
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
0
 
racheleeAuthor Commented:
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"
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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 () ;
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>>  };    

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.


         
0
 
racheleeAuthor Commented:
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
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You implemented the changes we suggested above?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> I still facing the same problem.

Can you post your updated code after implementing the changes we mentioned?
0
 
racheleeAuthor Commented:
>> 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

}

0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> t.getTime();

What's that for? Its not required.

>> which method i have to close?

Can you elaborate on what the error is, now?
0
 
racheleeAuthor Commented:
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
0
 
zzynxSoftware engineerCommented:
Thanx
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 30
  • 22
  • 14
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now