Hi,

In order to create an instance of an inner class, you first need to create
an instance of the outer class.

For example,

public class Outer {

  public Outer(){
  }

  public class Inner {

    public Inner(){
    }
  }

}

With these classes, you cannot call new Inner() on its own. You need to have
an instance of Outer first.


Outer o = new Outer();
Inner i = o.new Inner();

or

Inner i = new Outer().new Inner();


Hope this helps.

James


-----Original Message-----
From: java-ee-j2ee-programming-with-passion@googlegroups.com
[mailto:java-ee-j2ee-programming-with-pass...@googlegroups.com] On Behalf Of
tedpottel
Sent: 24 June 2009 21:18
To: Java EE (J2EE) Programming with Passion!
Subject: [java ee programming] New Programmer needs help


Hi,
I'm trying to learn how to use buttons, I have the following code
public class mySwing {



        class action implements ActionListener {

                public void actionPerformed(ActionEvent e)
                {
                        // do something
                        System.out.println("ted");

                }
        }


        public static void main(String[] arg)
        {
                JFrame frame = new JFrame("The Frame");
                frame.setSize(400,400);
                frame.setLocation(10,10);
                frame.setVisible(true);

                Container con = frame.getContentPane();
                con.setLayout(new FlowLayout());
                con.add( new JLabel("hi"));
                con.add(new JLabel("ted"));

                // ad a button
                JButton but = new JButton("fred");
                action a = new action();

                but.addActionListener( a);

                con.add(but);


        }
}

I get a error on
action a = new action()
eclipse says
Description
No enclosing instance of type mySwing is accessible. Must qualify the
allocation with an enclosing instance of type mySwing (e.g. x.new A()
where x is an instance of mySwing).     mySwing.java    testswing/src   line
34
Java Problem
Can somebody explains what this means?????????
-Ted



No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.339 / Virus Database: 270.12.93/2205 - Release Date: 06/27/09
05:53:00


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Java 
EE (J2EE) Programming with Passion!" group.
To post to this group, send email to 
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to 
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to