HandleEvent for a Frame

Im very new too Java(Few Weeks). I have created a compression program in C++ and tried to convert it to Java. Just few mins after i started, i got a problem.
Here it is. I cant close Frame frmMain. Does anybody knows what im doing wrong here?
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
import java.*;
public class Compression {
     private Frame frmMain = new Frame();
     public static void main( String args[] )
          new Compression();     
     Compression()
          initGUI();
     long getFileSize( String sFile )
          return 0;
     long fileExist( String sFile )
          return 0;
     void initGUI()
          frmMain.setTitle( "Compression Program" );
          frmMain.setSize( 400, 200 );
          frmMain.show();
     // Not working windowClosing
     public boolean handleEvent( Event e )
          if( e.id == Event.WINDOW_DESTROY )
               System.exit( 0 );
          return frmMain.handleEvent( e );
}

How to Make Frames:
http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html

Similar Messages

  • How do i use jbutton for mutiple frames(2frames)???

    im an creating a movie database program and i have a problem with the jButtons on my second frame i dont know how to make them work when clicked on. i managed to make the jButtons work on my first frame but not on the second....
    here is that code so far----
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    * real2.java
    * Created on December 7, 2007, 9:00 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    * @author J
    public class real2 extends JPanel  implements ActionListener{
        private JButton addnew;
        private JButton help;
        private JButton exit;
        private JFrame frame1;
        private JButton save;
        private JButton cancel;
        private JButton save2;
        private JLabel moviename;
        private JTextField moviename2;
        private JLabel director;
        private JTextField director2;
        private JLabel year;
        private JTextField year2;
        private JLabel genre;
        private JTextField genre2;
        private JLabel plot;
        private JTextField plot2;
        private JLabel rating;
        private JTextField rating2;
        /** Creates a new instance of real2 */
        public real2() {
            super(new GridBagLayout());
            //Create the Buttons.
            addnew = new JButton("Add New");
            addnew.addActionListener(this);
            addnew.setMnemonic(KeyEvent.VK_E);
            addnew.setActionCommand("Add New");
            help = new JButton("Help");
            help.addActionListener(this);
            help.setActionCommand("Help");
            exit = new JButton("Exit");
            exit.addActionListener(this);
            exit.setActionCommand("Exit");
           String[] columnNames = {"First Name",
                                    "Last Name",
                                    "Sport",
                                    "# of Years",
                                    "Vegetarian"};
            Object[][] data = {
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)}
            final JTable table = new JTable(data, columnNames);
            table.setPreferredScrollableViewportSize(new Dimension(600, 100));
            table.setFillsViewportHeight(true);
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
            //Add the scroll pane to this panel.
            add(scrollPane);
            GridBagConstraints c = new GridBagConstraints();
            c.weightx = 1;
            c.gridx = 0;
            c.gridy = 1;
            add(addnew, c);
            c.gridx = 0;
            c.gridy = 2;
            add(help, c);
            c.gridx = 0;
            c.gridy = 3;
            add(exit, c);
        public static void addComponentsToPane(Container pane){
            pane.setLayout(null);
            //creating the components for the new frame
            JButton save = new JButton("Save");
            JButton save2 = new JButton("Save and add another");
            JButton cancel = new JButton("Cancel");
            JLabel moviename= new JLabel("Movie Name");
            JTextField moviename2 = new JTextField(8);
            JLabel director = new JLabel("Director");
            JTextField director2 = new JTextField(8);
            JLabel genre = new JLabel("Genre");
            JTextField genre2 = new JTextField(8);
            JLabel year = new JLabel("year");
            JTextField year2 = new JTextField(8);
            JLabel plot = new JLabel("Plot");
            JTextField plot2 = new JTextField(8);
            JLabel rating = new JLabel("Rating(of 10)");
            JTextField rating2 = new JTextField(8);
            //adding components to new frame
            pane.add(save);
            pane.add(save2);
            pane.add(cancel);
            pane.add(moviename);
            pane.add(moviename2);
            pane.add(director);
            pane.add(director2);
            pane.add(genre);
            pane.add(genre2);
            pane.add(year);
            pane.add(year2);
            pane.add(plot);
            pane.add(plot2);
            pane.add(rating);
            pane.add(rating2);
            //setting positions of components for new frame
                Insets insets = pane.getInsets();
                Dimension size = save.getPreferredSize();
                save.setBounds(100 , 50 ,
                         size.width, size.height);
                 size = save2.getPreferredSize();
                save2.setBounds(200 , 50 ,
                         size.width, size.height);
                 size = cancel.getPreferredSize();
                cancel.setBounds(400 , 50 ,
                         size.width, size.height);
                 size = moviename.getPreferredSize();
                moviename.setBounds(100 , 100 ,
                         size.width, size.height);
                size = moviename2.getPreferredSize();
                moviename2.setBounds(200 , 100 ,
                         size.width, size.height);
                 size = director.getPreferredSize();
                director.setBounds(100, 150 ,
                         size.width, size.height);
                 size = director2.getPreferredSize();
                director2.setBounds(200 , 150 ,
                         size.width, size.height);
                size = genre.getPreferredSize();
                genre.setBounds(100 , 200 ,
                         size.width, size.height);
                 size = genre2.getPreferredSize();
                genre2.setBounds(200 , 200 ,
                         size.width, size.height);
                 size = year.getPreferredSize();
                year.setBounds(100 , 250 ,
                         size.width, size.height);
                size = year2.getPreferredSize();
                year2.setBounds(200 , 250 ,
                         size.width, size.height);
                 size = plot.getPreferredSize();
                plot.setBounds(100 , 300 ,
                         size.width, size.height);
                 size = plot2.getPreferredSize();
                plot2.setBounds(200 , 300 ,
                         size.width, size.height);
                size = rating.getPreferredSize();
                rating.setBounds(100 , 350 ,
                         size.width, size.height);
                 size = rating2.getPreferredSize();
                rating2.setBounds(200 , 350 ,
                         size.width, size.height);
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            frame.add(new real2());
            //Display the window.
            frame.setSize(600, 360);
            frame.setVisible(true);
            frame.pack();
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
        public void actionPerformed(ActionEvent e) {
            if ("Add New".equals(e.getActionCommand())){
               frame1 = new JFrame("add");
               frame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
               addComponentsToPane(frame1.getContentPane());
               frame1.setSize(600, 500);
               frame1.setVisible(true);
                //disableing first frame etc:-
                if (frame1.isShowing()){
                addnew.setEnabled(false);
                help.setEnabled(false);
                exit.setEnabled(true);
                frame1.setVisible(true);
               }else{
                addnew.setEnabled(true);
                help.setEnabled(true);
                exit.setEnabled(true);           
            if ("Exit".equals(e.getActionCommand())){
                System.exit(0);
            if ("Save".equals(e.getActionCommand())){
                // whatever i ask it to do it wont for example---
                help.setEnabled(true);
            if ("Save" == e.getSource()) {
                //i tried this way too but it dint work here either
                help.setEnabled(true);
    }so if someone could help me by either telling me what to type or by replacing what iv done wrong that would be great thanks...

    (1)Java class name should begin with a capital letter. See: http://java.sun.com/docs/codeconv/
            JButton save = new JButton("Save");
            JButton save2 = new JButton("Save and add another");
            // ... etc. ...(2)Don't redeclare class members in a method as its local variable. Your class members become eternally null, a hellish null.
    how to make them work when clicked on(3)Add action listener to them.

  • To use one SessionInfo for multiple frames

    how to use one SessionInfo for master frame and other frame the detail
    Thanks for your reply.

    You can instantiate the SessionInfo and other dataproducer objects in frame1 and bind them to controls in the first and second frames.
    If you plan to change/execute queries pass the sessionInfo instance to the second frame.
    Hope this helps.
    Sathish
    null

  • How can i set each still image to show for 1 frame?

    im trying to create a 60fps timelapse but i just can't get each image to show for less than 2 frames, i've gone to edit>preferences>import and set the still footage length to 0:00:00:01. and i've set the sequence footage to 60fps(although i'm not positive what this does)
    i then bring my photos down to create new composition set it to 0:00:00:01 still duration and then each photo shows for 2 frames, any ideas?
    thanks a lot!

    If you import a single frame as an image sequence it will be 2 frames long.
    If you import an image sequence as an image sequence you won't be able to see the individual frames in the timeline as being 2 frames long. However, if your composition is set to 60 fps and the image sequence is interpreted as 30 fps, when you step through the footage there will be pairs of identical frames. Change the interpretation to 60 fps and the image sequence will be half as long but each frame will be unique.

  • How to change FM8 default setting for Anchored Frame?

    Hello,
    I would like to change the default settings in FrameMaker 8 for Anchored Frame.
    Currently, when I import an .ai file into FrameMaker 8, I have to change the Anchored Frame default setting from "Below Current Line" to "At Insertion Point".
    Is there a way to make "At Insertion Point" the default option in FrameMaker 8 (.e.g *.ini file)?
    Thanks,
    -J

    Hello again,
    Okay, I took the plunge (followed the instructions) and put the ShrinkWrapAsIs.dll in the following folder:
    C:\Program Files\Adobe\FrameMaker8\fminit\Plugins
    But, it did not work on my version of FrameMaker 8 (in Structured FM8).
    Thanks again for the ideas.
    -J

  • Workflow WS400012  Release for payment (frame)

    Hi, I need to know if the  WS400012  Release for payment (frame) is trigger when a invoice is register to
    I need to know if workflow to shoot when a logistic invoice is registered from the MIRO transaction, since a book entry is registered (type RE),
    I tested and single an the workflow to shoot with financial transactions (FB01, FB60), although I formed in the payment liberation the type of document RE.
    Regards
    Dayana

    Hi,
    Just go through the following links
    1. http://help.sap.com/saphelp_nw04s/helpdata/en/fb/135d89457311d189440000e829fbbd/content.htm
    2.http://aiokeh.wdf.sap.corp:1080/SAPIKS2/contentShow.sap_SCLASS=IWB_STRUCT&_SLOIO=9B4460FF454711D189430000E829FBBD&TMP_IWB_TASK=DISPLAY&RELEASE=647&LANGUAGE=EN&_SEQNUM=104&_LOIO=84CB8D3880B8E060E10000009B38F842&_CLASS=IWB_EXTHLP
    <b>Reward Points if Useful</b>

  • Stopping invoice Parking for Second time Parking for a frame work PO...

    Hi SAP Guru's..
    there is a Requirement from Client site that ..
    for a Frame work PO which comes with a Invoice plan ..
    we should be able to Stop Second time invoicing Maintained in Invoice Plan...
    How to Go for this ...
    Any workable suggestion would be Rewarded with Points ...
    Thanks and warm Regards..
    Adarsh Srivastava..

    You can control the changing of PO in the enhancement which name you can search here. There are three kinds of enhancement: check, change and save. You need select the kind of 'change'.

  • Stop motion chroma screen problem for multi frames

    I am trying to use green screen for stop motion movies and I do know how to set it for each frame but how do you get all the frames to accept a single back ground picture at once? I have to insert the effect one at a time into each frame. I cannot use "select all" and then insert...the option will only work on single frames which for hundreds of frames is very time consumming. Is there a batch frames work around?
    Thanks
    Kevin

    Just remember that doing the Paste Attributes will add ALL the effects from the copied clip to ALL of the selected clips. Any effects already applied to those clips will still remain expect for Adjust, Motion or Opacity keyframes, those will be overwritten.
    Best to practice on one or two clips to see what the results will be before doing a large group of them.

  • Gutter Rules for text frames

    Here's a special request. As a publication designer, if I choose to have rules in my column gutters, it's real pain because I have to place those rules manually, style them and then move and/or lengthen/shorten them if my column's height or postioning changes.
    How great would it be to have a "Gutter Rules" option in the Object Style specifications for text frames? You could specify the rule's style, width, colour, offset etc., and choose whether to have them extend to the full height of the box, or just to the height of the content, aligning it to x-hieght, base height and so on. Would love to see this feature in future versions of Adobe Indesign, and if anyone knows of a script, please let me know!

    Starting with Eugene's questions of 8/31: There are NO InDesign “embedded” footnotes, all the “notes” are simply text in a text frame. When they refer to a note reference in text, the note numbers at the start of the footnote are superscripted with a character style. Just for info, the notes without the superscript numbers at the start (25-35, 33, 35) are notes that refer to the line numbers.
    Unfortunately using a rule above the first note in the frame won’t work all the time either. Just as the notes for the right page (6, 7 and 8) start on the left page and continue with note number 9 on the right page, a single long note can start on the left page and end on the right page. At that point we’d have to break the paragraph and restyle the 2nd half of the note with out the rule. We did this in another book and it was only a minor irritation. If this series though it would be a killer over the long haul.
    After looking at it again last night for a while I think anchoring a rule in the first line of the footnote still seems to be the best way. It’s easy to place if a library is left open, I can script it if I find it necessary and it keeps the text flow in tact for possible later repurposing. Maybe the best place for the anchor is the middle of the line giving the best chance that it will stay in the right place if text moves a bit forward or backward. The one good thing about the way it anchors is that the anchor’s horizontal position doesn’t matter.
    Thanks to both of you for your time and all the best.
    Ken

  • "Baud Rate" AttrId not found for CAN frame API's ncGetAttr and ncSetAttr

    Hi,
    Well, everything is in the Subject : "Baud Rate" AttrId not found for CAN frame API's ncGetAttr and ncSetAttr
    Although it is listed in the LabVIEW Documentation,  it is not in the enum's items gotten from `right click` -> `create` -> `contsant` on their `AttrId` connector.
    My actuall need would be for checking a formerly opened CANNet handle compatibility against hardware  requirement, so ... ncGetAttr.vi
    Anyway, if somebody knows the actual u32 to hardwire instead of the enum constant, or did I get something wrong ?
    Thanks

    Hello,
    You are quite right about the ncGetAttr.vi however the ncSetAttr does have a Baud Rate item if you scroll further down.
    To get the Baud Rate wire a x80000007 to the AttrId pin. Or you can double click on the the ncSetAttr and then go into its block diagram, now
    in the case structure select case 27 copy the numeric constant (which should be x80000007) and use it as the input to the ncGetAttr
    Let us know if this helps.
    Christian A
    National Instruments
    Applications Engineer

  • Quick key launch for next frame in sequenced loop?

    Hi, 
    I want go quickly through my sequence loop. Is there a key combo for next frame?
    Thanks
    Solved!
    Go to Solution.

    ctrl + mousewheel will skip through frames in all structures
    - Cheers, Ed

  • How to set my own icon for java frame ??

    I create a java class it extends JFrame. I want to change default icon on the left_top corner and using my own icon. It is a --.gif file. How to do it. When I try to modify it using setIconImage( Image image), I met problem. I cann't new Image("--.gif"). I don't know how to create a Image object using a string(file name). I try to use ImageIcon , but it is not image obj. Thanks. Gary

    According to the documentation setIconImage does the following: Sets the image to be displayed in the minimized icon for this frame. Not all platforms support the concept of minimizing a window.
    So,
    1) It does not change the icon in the top-left corner
    2) It does not work on all platforms.

  • Set Stroke weight for a frame not working in CS4.

    Hi All,
    How to set Stroke weight for a frame.
    I tried using CreateStrokeWeightCommand of IGraphicAttributeUtils, but its not working in CS4.
    Regards,
    Jasmine
    Message was edited by: Jasmine_Shaikh

    Hi All,
    CreateStrokeWeightCommand of IGraphicAttributeUtils works only when if the frame has some stroke weight already applied to it.
    So do i need to set something else before using CreateStrokeWeightCommand to make it work programatically on a frame with no stroke weight.
    Jasmine

  • Time Lapse import creates new clip for every frame!

    I shot a time lapse film - five hours reduced to 4 minutes ie one frame every 4 seconds. The iMovie Import wizard created a separate 'Clip' for every frame, (which is unusable), and then crashes the program every time I try to open it, I guess because there are too many 'Clips' to handle.
    Is there a way to import these discontinuous shots as a single clip? If iMovie can't do it, any ideas on a better way? I couldn't get Quicktime Pro to do any better - it opened thousands of separate windows on the desktop.
    Fortunately, the original is on DV, though each frame has a different time stamp on it.
    Thanks for any ideas!

    FYI
    I found that iMovie 6 was able to handle the multiple files and I could export them as an MPEG4 file. iMovie 08 bombed big time.

  • Looking for part no. for M93z frame stand

    Hi Everyone,
    I bought a new machine with product id 10AECTO1WW (23" non-touch M93Z all-in-one machine) from a lenovo warehouse sale. This came without any stand (this was known to me). Now i am looking for a frame stand, but can't locate its part number. Also if it is possible to order this from lenovo.
    Thanks

    Actually i am looking for monitor stand instead. Thanks

Maybe you are looking for

  • Airport no longer sharing internet

    I have been using the airport extreme (802.11n) for several years, with few problems. Now it seems that it is only sharing the wireless connection from my modem to one computer at a time, rebooting the modem will allow any OTHER (or the same) compute

  • Extreme (b/g/n) can't connect to the internet

    my iMac has no problem seeing my airport extreme (b/g/n), but I can't connect to the internet. I have tried soft / hard reset & factory reset as well, none of them worked. The extreme just keep flashing its amber light. On my iMac, I have full signal

  • What is the Lumia 520 Music Subscription period..

    Hi, I recently bought a new lumia 520 and the music account activated saying "Nokia music unlimited subscription activated." 1)What is the correct period of such subscription? 2) when i logged in again , it said  "Subscription ends on Jan 01". That i

  • Conn to Ms-Access thru Forms

    Hi everyone i m getting a problem while connecting to MS-Access thru ODBC in forms, using EXEC_SQL Pkg its giving me a message Frm-40734:internal error. the error is at line EXEC_SQL.OPEN_CONNECTION(/@odbc:conac) where "conac" is the ODBC connection

  • CLIENT point of view

    I am a SAP BW consultant just started and willing to learn from Other expereiences. I want to know certain things which might have occured to so many of you 1. In an ERP environment,  How SAP BW migration from other External Data Warehouses will bene