Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default working with AWt

    hello,

    actually this is just a simple program as to create a child frame window from within an applet

    but i really dnt understand why the error is cuming as invalid method declaration - return type required

    public MywindowAdapter(SampleFrame sampleFrame)



    //Create a child Frame window from within a applet.

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

    //Create a subclass of frame.

    class SampleFrame extends Frame
    {
    SampleFrame (String title)
    {
    super (title);
    //create an object to handle the window events

    MyWindowAdapter adapter = new MyWindowAdapter(this);

    //register it to recieve the events
    addWindowListener(adapter);
    }
    public void paint(Graphics g)
    {
    g.drawString(" this is in the frame window:",10,40);
    }
    }
    class MyWindowAdapter extends WindowAdapter
    {
    SampleFrame sampleFrame;

    public MywindowAdapter(SampleFrame sampleFrame)
    {
    this.sampleFrame = sampleFrame;
    }
    public void windowClosing (WindowEvent we)
    {
    sampleFrame.setVisible(false);
    }
    }

    //create a frame window
    public class AppletFrame extends Applet
    {
    Frame F;
    public void init()
    {
    f = new SampleFrame(" A frame window");
    f.setSize(250,250);
    f.setvisible(true);
    }
    public void start()
    {
    f.setVisible(true);
    }

    public void stop()
    {
    f.setVisible(false);
    }
    public void paint(Graphics g)
    {
    g.drawString(" this is in the applet window:",10,20);
    }
    }


    kindly help me guys

  2. #2
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: working with AWt

    kindly reply for me

  3. #3
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default Re: working with AWt

    Problem with lowercase/uppercase
    Java Code:
    //Create a child Frame window from within a applet.
    
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    
    //Create a subclass of frame.
    
    class SampleFrame extends Frame
    {
    SampleFrame (String title)
    {
    super (title);
    //create an object to handle the window events
    
    MyWindowAdapter adapter = new MyWindowAdapter(this);
    
    //register it to recieve the events
    addWindowListener(adapter);
    }
    public void paint(Graphics g)
    {
    g.drawString(" this is in the frame window:",10,40);
    }
    }
    class MyWindowAdapter extends WindowAdapter
    {
    SampleFrame sampleFrame;
    
    public MyWindowAdapter(SampleFrame sampleFrame)
    {
    this.sampleFrame = sampleFrame;
    }
    public void windowClosing (WindowEvent we)
    {
    sampleFrame.setVisible(false);
    }
    }
    
    //create a frame window
    public class AppletFrame extends Applet
    {
    Frame f;
    public void init()
    {
    f = new SampleFrame(" A frame window");
    f.setSize(250,250);
    f.setVisible(true);
    }
    public void start()
    {
    f.setVisible(true);
    }
    
    public void stop()
    {
    f.setVisible(false);
    }
    public void paint(Graphics g)
    {
    g.drawString(" this is in the applet window:",10,20);
    }
    }
    Swastik

  4. #4
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: working with AWt

    Thank you but yes there is a new problem as now the error is as -class AppletFrame is public ,should be declared in a file name d AppletFrame.java.

  5. #5
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default Re: working with AWt

    You have multiple classes in this code. Your file name should be (AppletFrame.java) same as the public class name i.e AppletFrame, and you need to compile it as javac AppletFrame.java
    Swastik

Similar Threads

  1. Collisions are working & not working
    By Jayayoh in forum Java 2D
    Replies: 1
    Last Post: 06-24-2011, 05:21 PM
  2. if else not working
    By silverglade in forum New To Java
    Replies: 5
    Last Post: 05-12-2011, 07:29 PM
  3. Replies: 2
    Last Post: 01-04-2011, 04:30 AM
  4. This Is Not Working.
    By FatalSylence in forum New To Java
    Replies: 8
    Last Post: 10-16-2010, 02:15 AM
  5. Replies: 8
    Last Post: 05-28-2008, 07:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •