Help me pls.  i so new in this

Pls tell me why this doesn't close the window.
import java.awt.*;
import java.awt.event.*;
class TicTacGui extends Frame {
          Button button[];
     TicTacGui(){
          Frame mainframe = new Frame();
          MenuBar mainmenu = new MenuBar();
          Menu m1 = new Menu("File");
          Panel forButtons= new Panel();
          Panel forText= new Panel();
          m1.add(new MenuItem("Exit"));
          mainmenu.add(m1);
          mainframe.add(forButtons, BorderLayout.CENTER);
          mainframe.add(forText, BorderLayout.SOUTH);
          mainframe.setMenuBar(mainmenu);
          forButtons.setLayout(new GridLayout(3,3,1,1));
          //adding buttons               
     button=new Button[9];
     for(int i=0;i<9;i++)
     button[i] = new Button("Button");
     forButtons.add(button);
          mainframe.setSize(300,300);
          mainframe.setVisible(true);
          //Listener for exiting the window
          addWindowListener( new WindowAdapter() {
               public void windowClosing( WindowEvent event ) {
          System.exit( 0 );
public static void main(String args[]) {
          TicTacGui tic = new TicTacGui();

mainframe is not the same thing as your instance of TicTacGui... there is no need for mainframe. What you are doing is adding everything to mainframe, then showing mainframe, and adding the WindowListener to your instance of TicTacGui... instead, get rid of mainframe and use the instance of TicTacGui that you are creating for everything. since TicTacGui extends frame it gets all of the methods in frame. hope that made sense

Similar Messages

Maybe you are looking for

  • How to access values in process request

    Hi guys, Wondering if some one could shed some light on the process of getting values in PR. The situation is that i have linked two pages and both have dateFrom and dateTo fields, the values of the fields are being copied across to the other page au

  • ITunes 10.1.2 and Store

    I just updated to iTunes 10.1.2 and now the Apple iTunes Stores seems to be flaky. It will load some times, hang and get beach ball o'death, or come back and say unavailable. My downloads are responding in a similar manner. I was notified through e-m

  • Case for MB Pro(Retina)?

    Is there any  Speck 15" SeeThru Satin Case for MacBook Pro(Retina) to come? cheers

  • Proper Data Not showing in Preview Mode

    Hello, I'm using the Dashboard Design tool to create a dashboard with Input controls on 2 stack column charts. There are 7 Input Targets  pointing to 1st stack column chart, the SUM of all these targets need to be populated on one of the values in th

  • 10.1.3 cache synchronization using custom RMI code

    I am trying to port our custom RMI synchronization code (overriding RMIClusteringService) from 9.0.4 to 10.1.3. It works by sending an update message to the remote cache whenever an object gets changed on the local cache as follows: 2006.05.15 11:28: