Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4225469

mouse click on menu or tree node throws UnsatisfiedLinkError

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_95, windows_nt

      Description



      Name: dbT83986 Date: 03/30/99


      This is a bug reported against jdk 1.1.8 release candidate, used
      with swing 1.1.

      When clicking on a menu bar or menu item, an UnsatisfiedLinkError
      occurs.

      1. Compile and run the application from the source code included
      below. Use the mouse and click on the 'File' menu, then the 'New'
      menu item.

      2. I used this source code, taken from the examples provided with
      Core Java Foundation Classes, ISBN 0-13-080301-4:

      package JFCBook.Chapter6;

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.io.*;
      import java.util.*;

      public class MenuExample2 extends JFrame {
      public MenuExample2(String title) {
      super(title);

      JMenuBar mb = new JMenuBar();
      this.setJMenuBar(mb);

      JMenu fileMenu = new JMenu("File");
      mb.add(fileMenu);

      newItem = new JMenuItem("New...");
      openItem = new JMenuItem("Open...");
      closeItem = new JMenuItem("Close");
      fileMenu.add(newItem);
      fileMenu.add(openItem);
      fileMenu.add(closeItem);

      fileMenu.addSeparator();

      saveItem = new JMenuItem("Save");
      saveAsItem = new JMenuItem("Save As...");
      fileMenu.add(saveItem);
      fileMenu.add(saveAsItem);

      fileMenu.addSeparator();

      fileListMenu = new JMenu("Recent Files");
      fileMenu.add(fileListMenu);
      emptyListItem = new JMenuItem("Empty");
      emptyListItem.setEnabled(false);
      fileListMenu.add(emptyListItem);

      fileMenu.addSeparator();

      JMenuItem exitItem = new JMenuItem("Exit");
      fileMenu.add(exitItem);
      exitItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      closeWindow();
      }
      });

      this.getContentPane().add(new JScrollPane(textArea = new JTextArea(20, 40)));
      fileManager = new FileManager();

      // Processing for "New..." menu item
      newItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      String name = getFileName("New File", FileDialog.SAVE);
      if (name != null) {
      if (fileManager.isFileOpen()) {
      // Close any open file
      try {
      fileManager.closeFile(textArea.getText());
      } catch (Throwable e) {
      // Ignore any exception
      }
      }
      try {
      fileManager.newFile(name);
      textArea.setText("");
      addRecentFile(name);
      } catch (IOException e) {
      // Do nothing - message already printed
      }
      }
      }
      });

      // Processing for "Open..." menu item
      openItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      String name = getFileName("Open File", FileDialog.LOAD);
      if (name != null) {
      try {
      String text = fileManager.openFile(name);
      textArea.setText(text);
      addRecentFile(name);
      } catch (IOException e) {
      // Do nothing - message already printed
      }
      }
      }
      });

      // Processing for "Close..." menu item
      closeItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      try {
      fileManager.closeFile(textArea.getText());
      textArea.setText("");
      } catch (IOException e) {
      // Do nothing - message already printed
      }
      }
      });

      // Processing for "Save..." menu item
      saveItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      try {
      fileManager.saveFile(textArea.getText());
      } catch (IOException e) {
      // Do nothing - message already printed
      }
      }
      });

      // Processing for "Save As..." menu item
      saveAsItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      if (fileManager.isFileOpen()) {
      String name = getFileName("Save As File", FileDialog.SAVE);
      if (name != null) {
      try {
      fileManager.saveAsFile(name, textArea.getText());
      } catch (IOException e) {
      // Do nothing - message already printed
      }
      }
      }
      }
      });

      // Create the handler for the recent file list
      menuListener = new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      JMenuItem mi = (JMenuItem)(evt.getSource());
      String fileName = mi.getActionCommand();
      try {
      String text = fileManager.openFile(fileName);
      textArea.setText(text);
      addRecentFile(fileName);
      } catch (IOException e) {
      // Do nothing - message already printed
      }
      }
      };
      }

      // Add a name to the recent file list
      public void addRecentFile(String fileName) {
      int offset;

      // Check whether this file is already in the file list
      if ((offset = recentFiles.indexOf(fileName)) == -1) {
      // Not present - add it at the beginning
      recentFiles.insertElementAt(fileName, 0);
      if (recentFiles.size() > RECENT_FILES) {
      // List was full - remove the last (oldest) item
      recentFiles.removeElementAt(RECENT_FILES);
      }
      } else {
      // Already present: move this item to the front of the list
      recentFiles.removeElementAt(offset);
      recentFiles.insertElementAt(fileName, 0);
      }


      // Rebuild the file menu
      buildRecentFileMenu();
      }

      // Build the recent file menu
      public void buildRecentFileMenu() {
      int size = recentFiles.size();

      fileListMenu.removeAll();

      for (int i = 0; i < size; i++) {
      String fileName = (String)(recentFiles.elementAt(i));
      JMenuItem mi = new JMenuItem(fileName);
      fileListMenu.add(mi);
      mi.addActionListener(menuListener);
      }
      }

      // Get a file name
      public String getFileName(String title, int mode) {
      FileDialog fd = new FileDialog(this, title, mode);
      fd.setFile("*.*");
      fd.setDirectory(directory);

      fd.setVisible(true);

      String dir = fd.getDirectory();
      String file = fd.getFile();
      if (dir == null || file == null) {
      return null;
      }
      directory = dir;

      String separator = System.getProperty("file.separator");
      if (dir.endsWith(separator)) {
      return dir + file;
      } else {
      return dir + System.getProperty("file.separator") + file;
      }
      }


      // Take any action needed to close the application
      public void closeWindow() {
      try {
      fileManager.closeFile(textArea.getText());
      } catch (IOException e) {
      System.out.println("Failed to write data on close.");
      }
      System.exit(0);
      }

      public static void main(String[] args) {
      JFrame f = new MenuExample2("Menu Example 2");
      f.pack();
      f.setVisible(true);
      f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent evt) {
      MenuExample2 frame = (MenuExample2)(evt.getSource());
      frame.closeWindow();
      }
      });
      }

      JMenuItem newItem;
      JMenuItem openItem;
      JMenuItem closeItem;
      JMenuItem saveItem;
      JMenuItem saveAsItem;
      JMenuItem emptyListItem;
      JMenu fileListMenu;
      JTextArea textArea;
      FileManager fileManager;
      String directory = ""; // Current directory

      ActionListener menuListener;

      // Recently-used file list
      static final int RECENT_FILES = 4;
      Vector recentFiles = new Vector(RECENT_FILES);
      }

      package JFCBook.Chapter6;

      import java.io.*;
      import java.awt.Toolkit;

      // Helper class to manage an open file
      public class FileManager {
      // Check whether a named file exists
      boolean fileExists(String fileName) {
      return (new File(fileName)).exists();
      }

      // Open a new file
      void newFile(String fileName) throws IOException {
      if (fileExists(fileName)) {
      System.out.println("File <" + fileName + "> already exists.");
      throw new IOException("File exists");
      }

      this.canWriteFile = true; // Assume we can write
      this.fileName = fileName;
      }

      // Open a file
      String openFile(String fileName) throws IOException, FileNotFoundException {
      this.fileName = fileName;
      openFile = new File(fileName);
      try {
      canWriteFile = openFile.canWrite();
      FileInputStream fs = new FileInputStream(openFile);
      long l = openFile.length();
      byte[] content = new byte[(int)l];
      fs.read(content);
      fs.close();
      return new String(content);
      } catch (FileNotFoundException e) {
      System.out.println("Failed to open \"" + fileName + "\".");
      Toolkit.getDefaultToolkit().beep();
      throw e;
      } catch (IOException e) {
      System.out.println("Failed to read \"" + fileName + "\".");
      Toolkit.getDefaultToolkit().beep();
      throw e;
      }
      }

      // Save to the file
      void saveFile(String text) throws IOException {
      if (fileName != null && userWantsWrite == true && canWriteFile == true) {
      openFile = new File(fileName);
      try {
      FileOutputStream fs = new FileOutputStream(openFile);
      byte[] content = text.getBytes();
      fs.write(content);
      fs.close();
      } catch (FileNotFoundException e) {
      System.out.println("Failed to open \"" + fileName + "\" for writing.");
      Toolkit.getDefaultToolkit().beep();
      throw e;
      } catch (IOException e) {
      System.out.println("Failed to write to \"" + fileName + "\".");
      Toolkit.getDefaultToolkit().beep();
      throw e;
      }
      }
      }

      // Save with a different file name
      void saveAsFile(String fileName, String text) throws IOException {
      this.fileName = fileName;
      if (userWantsWrite && canWriteFile == true) {
      saveFile(text);
      }
      }

      // Close the open file, writing data if required
      void closeFile(String text) throws IOException {
      if (isFileOpen()) {
      // Write file content
      saveFile(text);
      }

      fileName = null;
      openFile = null;
      }

      // Make the file writable or not
      public void setWritable(boolean writable) {
      this.userWantsWrite = writable;
      }

      // Check whether we have an open file
      boolean isFileOpen() {
      return openFile != null;
      }

      // Check whether we can write to the file
      boolean canWrite() {
      return canWriteFile;
      }

      // Get current file name
      String getFileName() {
      return fileName;
      }

      File openFile; // File object for open file
      String fileName; // Name of current open file
      boolean userWantsWrite = true;
      // User wants to be able to write
      boolean canWriteFile = true;
      // File can be written to
      }

      3. & 4. I got these error messages:

      D:\object_code\etools>java JFCBook.Chapter6.MenuExample2
      Exception occurred during event dispatching:
      java.lang.UnsatisfiedLinkError: requestFocus
              at java.awt.Component.requestFocus(Component.java:2669)
              at javax.swing.plaf.basic.BasicMenuUI$ChangeHandler.validateKeyboardActi
      ons(BasicMenuUI.java:380)
              at javax.swing.plaf.basic.BasicMenuUI$ChangeHandler.stateChanged(BasicMe
      nuUI.java:318)
              at javax.swing.AbstractButton.fireStateChanged(AbstractButton.java:991)
              at javax.swing.AbstractButton$ButtonChangeListener.stateChanged(Abstract
      Button.java:1034)
              at javax.swing.DefaultButtonModel.fireStateChanged(DefaultButtonModel.ja
      va:336)
              at javax.swing.DefaultButtonModel.setSelected(DefaultButtonModel.java:22
      7)
              at javax.swing.JMenu.setSelected(JMenu.java:231)
              at javax.swing.JMenu.menuSelectionChanged(JMenu.java:948)
              at javax.swing.MenuSelectionManager.setSelectedPath(MenuSelectionManager
      .java:72)
              at javax.swing.MenuSelectionManager.clearSelectedPath(MenuSelectionManag
      er.java:109)
              at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseRelease
      d(BasicMenuItemUI.java:673)
              at java.awt.Component.processMouseEvent(Component.java:2355)
              at java.awt.Component.processEvent(Component.java:2200)
              at java.awt.Container.processEvent(Container.java:904)
              at java.awt.Component.dispatchEventImpl(Component.java:1809)
              at java.awt.Container.dispatchEventImpl(Container.java:949)
              at java.awt.Component.dispatchEvent(Component.java:1741)
              at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1739
      )
              at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1537)

              at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1453)
              at java.awt.Container.dispatchEventImpl(Container.java:936)
              at java.awt.Window.dispatchEventImpl(Window.java:491)
              at java.awt.Component.dispatchEvent(Component.java:1741)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:79)
      Exception occurred during event dispatching:
      java.lang.UnsatisfiedLinkError: show
              at java.awt.Dialog.show(Dialog.java:219)
              at java.awt.Component.show(Component.java:511)
              at java.awt.Component.setVisible(Component.java:473)
              at JFCBook.Chapter6.MenuExample2.getFileName(MenuExample2.java:192)
              at JFCBook.Chapter6.MenuExample2$2.actionPerformed(MenuExample2.java:57)

              at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:10
      66)
              at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
      ctButton.java:1101)
              at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
      .java:378)
              at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250
      )
              at javax.swing.AbstractButton.doClick(AbstractButton.java:226)
              at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseRelease
      d(BasicMenuItemUI.java:674)
              at java.awt.Component.processMouseEvent(Component.java:2355)
              at java.awt.Component.processEvent(Component.java:2200)
              at java.awt.Container.processEvent(Container.java:904)
              at java.awt.Component.dispatchEventImpl(Component.java:1809)
              at java.awt.Container.dispatchEventImpl(Container.java:949)
              at java.awt.Component.dispatchEvent(Component.java:1741)
              at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1739
      )
              at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1537)

              at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1453)
              at java.awt.Container.dispatchEventImpl(Container.java:936)
              at java.awt.Window.dispatchEventImpl(Window.java:491)
              at java.awt.Component.dispatchEvent(Component.java:1741)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:79)
      Exception occurred during event dispatching:
      java.lang.NullPointerException: null component
              at sun.awt.windows.WGraphics.<init>(WGraphics.java:59)
              at sun.awt.windows.WComponentPeer.getGraphics(WComponentPeer.java:141)
              at java.awt.Component.getGraphics(Component.java:1175)
              at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:98)

      5. java -version returns java version "1.1.8", java -fullversion returns java full version "JDK1.1.8K"

      6. none.
      (Review ID: 56320)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            sswingtrsunw Swingtraq Swingtraq (Inactive)
            Reporter:
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: