Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old October 5th, 2002, 07:09 PM
gaspacho soup gaspacho soup is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 5 gaspacho soup User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to gaspacho soup Send a message via AIM to gaspacho soup
Exclamation frames

2 more questions... ^^;

1) System.exit(0) ... it's great for shutting down apps. How would i do this to an applet though?



2)

can someone pleaes tell me if they can *RUN* the MyFirstFrame class? Everything in the code is 100% correct because i downloaded it off the developers website:

Code:

import java.awt.*;
import java.awt.event.*;

/**
 *  MyFirstFrame class
 *
 * <p>
 * A sample frame to illustrate the placing of GUI objects and event handling.
 */
class MyFirstFrame extends Frame implements ActionListener
{

//----------------------------------
//    Data Members
//----------------------------------
    
    /**
     * Default frame width
     */
    private static final int FRAME_WIDTH    = 300;
    
    /**
     * Default frame height
     */
    private static final int FRAME_HEIGHT   = 200;
    
    /**
     * X coordinate of the frame default origin point
     */
    private static final int FRAME_X_ORIGIN = 150;
    
    /**
     * Y coordinate of the frame default origin point
     */
    private static final int FRAME_Y_ORIGIN = 250;

    /**
     * Default width for buttons
     */
    private static final int BUTTON_WIDTH  = 60;
     
    /**
     * Default height for buttons
     */
    private static final int BUTTON_HEIGHT = 30;

    /**
     * The GUI button for Cancel
     */
    private Button cancelButton;
    
    
    /**
     * The GUI button for OK
     */
    private Button okButton;
    
   

//----------------------------------
//    Constructors
//----------------------------------
                                
    /**
     * Default constructor
     */
    public MyFirstFrame()
    {
        //set the frame properties
        setSize      (FRAME_WIDTH, FRAME_HEIGHT);
        setResizable (false);
        setTitle     ("Program MyFirstFrame");
        setLocation  (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
        setLayout    (null);
        
        //create and place two buttons on the frame
        okButton = new Button("OK");
        okButton.setBounds(100, 150, BUTTON_WIDTH, BUTTON_HEIGHT);
        add(okButton);
        
        cancelButton = new Button("CANCEL");
        cancelButton.setBounds(170, 150, BUTTON_WIDTH, BUTTON_HEIGHT);
        add(cancelButton);
  
        //register this frame as an action listener of the two buttons
        cancelButton.addActionListener(this);
        okButton.addActionListener(this);
        
        //register a ProgramTerminator object as the window listener of this frame
        addWindowListener(new ProgramTerminator());
    }
   
//-------------------------------------------------
//      Public Methods:
// 
//          void    actionPerformed   (   ActionEvent        )
//
//------------------------------------------------
                                
    /**
     * Standard method to respond the action event.
     * 
     * @param event the ActionEvent object
     *
     */
    public void actionPerformed(ActionEvent event) 
    {
        Button clickedButton = (Button) event.getSource();
        
        if (clickedButton == cancelButton) {
           setTitle("You clicked CANCEL");
        }
        else { //the event source must be okButton
           setTitle("You clicked OK");
        }
    }
   
}


Code:
/*
    ProgramTerminator Class

    A ProgramTerminator object terminates the program when its main window
    generates a window closing event.
*/

import java.awt.event.*;

class ProgramTerminator implements WindowListener
{

/******************************

    Window Event Handling

*******************************/

   public void windowClosing( WindowEvent event )
   {
      System.exit(0);
   }

   public void windowActivated   (WindowEvent event) { }
   public void windowClosed      (WindowEvent event) { }
   public void windowDeactivated (WindowEvent event) { }
   public void windowDeiconified (WindowEvent event) { }
   public void windowIconified   (WindowEvent event) { }
   public void windowOpened      (WindowEvent event) { }

}


It basically comes down to me not understanding how to run frames

Last edited by gaspacho soup : October 6th, 2002 at 01:12 AM.

Reply With Quote
  #2  
Old October 6th, 2002, 07:04 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
You don't run Frames, you create them.

From the Frame javadoc:
Quote:
Frame f = new Frame(GraphicsConfiguration gc);
Rectangle bounds = gc.getBounds();
f.setLocation(10 + bounds.x, 10 + bounds.y);

replace Frame with MyFirstFrame.

As for the other, have a look at the stop() and destroy() methods in the Applet javadoc.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > applet version of System.exit(0)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway