001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package examples.imageviewer;
043:
044: public class ImageViewer extends javax.swing.JFrame {
045:
046: /** Creates new form ImageViewer */
047: public ImageViewer() {
048: initComponents();
049: pack();
050: setBounds(100, 100, 400, 400);
051: }
052:
053: /** This method is called from within the constructor to
054: * initialize the form.
055: * WARNING: Do NOT modify this code. The content of this method is
056: * always regenerated by the FormEditor.
057: */
058: private void initComponents() {//GEN-BEGIN:initComponents
059: desktop = new javax.swing.JDesktopPane();
060: jMenuBar1 = new javax.swing.JMenuBar();
061: fileMenu = new javax.swing.JMenu();
062: openMenuItem = new javax.swing.JMenuItem();
063: jSeparator1 = new javax.swing.JSeparator();
064: exitMenuItem = new javax.swing.JMenuItem();
065:
066: setTitle("Image Viewer");
067: addWindowListener(new java.awt.event.WindowAdapter() {
068: public void windowClosing(java.awt.event.WindowEvent evt) {
069: exitForm(evt);
070: }
071: });
072:
073: getContentPane().add(desktop, java.awt.BorderLayout.CENTER);
074:
075: fileMenu.setText("File");
076: openMenuItem.setText("Open");
077: openMenuItem
078: .addActionListener(new java.awt.event.ActionListener() {
079: public void actionPerformed(
080: java.awt.event.ActionEvent evt) {
081: openMenuItemActionPerformed(evt);
082: }
083: });
084:
085: fileMenu.add(openMenuItem);
086: fileMenu.add(jSeparator1);
087: exitMenuItem.setText("Exit");
088: exitMenuItem
089: .addActionListener(new java.awt.event.ActionListener() {
090: public void actionPerformed(
091: java.awt.event.ActionEvent evt) {
092: exitMenuItemActionPerformed(evt);
093: }
094: });
095:
096: fileMenu.add(exitMenuItem);
097: jMenuBar1.add(fileMenu);
098: setJMenuBar(jMenuBar1);
099:
100: }//GEN-END:initComponents
101:
102: private void exitMenuItemActionPerformed(
103: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
104: // Add your handling code here:
105: System.exit(0);
106: }//GEN-LAST:event_exitMenuItemActionPerformed
107:
108: private void openMenuItemActionPerformed(
109: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
110: // Add your handling code here:
111: java.awt.FileDialog fd = new java.awt.FileDialog(this );
112: fd.show();
113: if (fd.getFile() == null)
114: return;
115: ImageFrame ifr = new ImageFrame(fd.getDirectory()
116: + fd.getFile());
117: desktop.add(ifr, javax.swing.JLayeredPane.DEFAULT_LAYER);
118:
119: ifr.setVisible(true);
120: ifr.setSize(200, 200);
121: ifr.setLocation(0, 0);
122: }//GEN-LAST:event_openMenuItemActionPerformed
123:
124: /** Exit the Application */
125: private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
126: System.exit(0);
127: }//GEN-LAST:event_exitForm
128:
129: /**
130: * @param args the command line arguments
131: */
132: public static void main(String args[]) {
133: new ImageViewer().show();
134: }
135:
136: // Variables declaration - do not modify//GEN-BEGIN:variables
137: private javax.swing.JDesktopPane desktop;
138: private javax.swing.JMenuItem exitMenuItem;
139: private javax.swing.JSeparator jSeparator1;
140: private javax.swing.JMenu fileMenu;
141: private javax.swing.JMenuBar jMenuBar1;
142: private javax.swing.JMenuItem openMenuItem;
143: // End of variables declaration//GEN-END:variables
144:
145: }
|