Algorithm-VSM

 view release on metacpan or  search on metacpan

examples/corpus/WindowWithMenu.java  view on Meta::CPAN

            } 
        });

        MenuBar menuBar = new MenuBar();    
  
        ta.setEditable( false );              
        getContentPane().add( ta, "North" );                   

        Menu menu = new Menu( "File" );

        MenuItem menuItem = new MenuItem( "New" );
        menuItem.addActionListener( this );                       //(D)
        menu.add( menuItem );

        menuItem = new MenuItem( "Open" );
        menuItem.addActionListener( this );                       //(E)
        menu.add( menuItem );

        menuItem = new MenuItem( "Save" );
        menuItem.addActionListener( this );                       //(F)
        menu.add( menuItem );

        menuBar.add (menu );
        setMenuBar( menuBar );
    }

    public void actionPerformed( ActionEvent evt ) {              //(G)
        String arg = evt.getActionCommand(); 
        if ( arg.equals( "New" ) ) ta.setEditable( true );            
        if ( arg.equals( "Open" ) ) {          
            loadDialog.setDirectory(".");
            loadDialog.show();
            filename = loadDialog.getFile();                      //(H)
            String superString = "";
            if (filename != null) {
                try {
                    FileInputStream fin = 
                             new FileInputStream( filename );
                    while (true) {
                        int ch = fin.read();                      //(I)
                        if ( ch == -1 ) break;
                        superString += (char) ch;                 //(J)
                    }
                    fin.close();
                } catch( IOException e ) { 
                    System.out.println( "IO error" ); 
                }
            }
            ta.append( superString );                             //(K)
            ta.setEditable( true );
        }
        if ( arg.equals( "Save" ) ) {         
            saveDialog.setDirectory(".");
            saveDialog.show();
            filename = saveDialog.getFile();
            String superString = ta.getText();                    //(L)
            if (filename != null) {
                try {
                    FileOutputStream fout = 
                            new FileOutputStream( filename );
                    for (int i=0; i<superString.length(); i++)
                        fout.write( superString.charAt(i) );      //(M)
                    fout.close();
                } catch( IOException e ) { 
                    System.out.println( "IO error" ); 
                }
            }
        }
    }

    public static void main(String[] args){
        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension d = tk.getScreenSize();
        int screenHeight = d.height;
        int screenWidth = d.width;
        Frame wb = new WindowWithMenu();   
        wb.setSize( 2*screenWidth/3, 3*screenHeight/4 );
        wb.setLocation(screenWidth / 5, screenHeight / 5);
        wb.show();
    }
}



( run in 0.594 second using v1.01-cache-2.11-cpan-39bf76dae61 )