0

I have a class which extends JPanel and implements ActionListener.
I am having 2 menuItem. When I implemented the abstract method actionPerformed(ActionEvent e) and used repaint if the event source are the menuItem paint method is not called. What can be the possible reasons?

This is what I am doing inside the ActionListener implemantation

FileInputStream fstream = null;
            try {
                JFileChooser fc = new JFileChooser();
                int returnVal = fc.showOpenDialog(frame);
                File file1 = null;
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    file1 = fc.getSelectedFile();
                }
                fstream = new FileInputStream(file1);
                br = new BufferedReader(new InputStreamReader(new DataInputStream(fstream)));
                String str;
                while ((str = br.readLine()) != null) {
                     this.repaint();
                    String[] strarr = str.split(",");
                    
                    if (strarr[0].trim().equals("$GPGGA")) {
                        //System.out.println(str);
                        String latstringint = strarr[2].trim().substring(0, 2);
                        double latstringdec = Double.parseDouble(strarr[2].trim().substring(2)) / 60;
                        if (strarr[3].trim().equals("N")) {
                            Lat = Integer.parseInt(latstringint) + latstringdec;
                        } else {
                            Lat = -(Integer.parseInt(latstringint) + latstringdec);
                        }
                        String lonstringint = strarr[4].trim().substring(0, 3);
                        double lonstringdec = Double.parseDouble(strarr[4].trim().substring(3)) / 60;
                        if (strarr[5].trim().equals("E")) {
                            Lon = Integer.parseInt(lonstringint) + lonstringdec;
                        } else {
                            Lon = -(Integer.parseInt(lonstringint) + lonstringdec);
                        }
                        System.out.println(Lat+"\t"+Lon);
                        //pos[0]= Lat;
                        //pos[1]= Lon;
                        //path.add(pos);
                                                 
                        this.repaint();
                        Thread.sleep(250);
                        
                    }
                    if (strarr[0].trim().equals("$GPVTG")) {
                        heading = Double.parseDouble(strarr[1]);
                        sog = Double.parseDouble(strarr[7]);
                        this.repaint();
                    }
                }
            } catch (Exception ex) {
                Logger.getLogger(MovingMap.class.getName()).log(Level.SEVERE, null, ex);
            }
3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by JamesCherrill
Featured Replies
  • Google the Java Event Dispatch Thread and read about Swing threads. Your repaint() calls won't do anything until your event method completes, even if it sleeps in the meantime.. Read More

1

Google the Java Event Dispatch Thread and read about Swing threads.
Your repaint() calls won't do anything until your event method completes, even if it sleeps in the meantime..

0

Google the Java Event Dispatch Thread and read about Swing threads.
Your repaint() calls won't do anything until your event method completes, even if it sleeps in the meantime..

Thanks for your reply. I tried to solve it out by creating a new class java.util.Timer which will add the data and call the repaint periodically but that is also not working.
What are your suggestions on how to overcome this problem

0

Use javax.swing.Timer, it's better adapted to work with the swing EDT.
As for the latest version of your code - I've no idea wht may be wrong with it (for an obvious reason :-) )

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.