Hw To Make Inner Class Distinguish Func Parameter And Outer Class Var

i fail to make an inner class distinguish among function parameter and outer class variable.
consider the following code:
public class a {
     int var; // i want to access this one using inner class.
     public a(int var) {
          this.var = var;
          class b {
               public void fun() {
                    var = 100;
i get an error a.java:9: local variable var is accessed from within inner class; needs to be declared final.
when i change the code to this:
public class a {
     int var; // i want to access this one using inner class.
     public a() {          
          class b {
               public void fun() {
                    var = 100;
it compiled no problem.it seems that inner class is accessing function parameter rather than outer class member.
is there any syntax i can use to make me access the outer class member variable whithout renaming or removing the function parameter?
thank you.

a.this.var = 100; //Use this in the inner class.Amazing syntax -:)

Similar Messages

  • Inner classes use

    what is the main goal behind using inner classes in java design

    The best thing about inner classes in Java (something they missed in the C++ spec) is that a non-static inner class has direct access to everything in the containing class without the need to maintain an explicit reference.
    That makes inner class instances ideal as a kind of "delegate" from the main object into another context, e.g. to generate several ActionListener objects to be added to various gadgets, or as an Iterator which moves through some child elements.

  • Passing Inner class name as parameter

    Hi,
    How i can pass inner class name as parameter which is used to create object of inner class in the receiving method (class.formane(className))
    Hope somebody can help me.
    Thanks in advance.
    Prem

    No, because an inner class can never have a constructor that doesn't take any arguments.
    Without going through reflection, you always need an instance of the outer class to instantiate the inner class. Internally this instance is passed as a parameter to the inner class's constructor. So to create an instance of an inner class through reflection you need to get the appropriate constructor and call its newInstance method. Here's a complete example:import java.lang.reflect.Constructor;
    class Outer {
        class Inner {
        public static void main(String[] args) throws Exception{
            Class c = Class.forName("Outer$Inner");
            Constructor cnstrctr = c.getDeclaredConstructor(new Class[] {Outer.class});
            Outer o = new Outer();
            Inner i = (Inner) cnstrctr.newInstance(new Object[]{o});
            System.out.println(i);
    }

  • JLS3: Scope of type parameter and inner class declaration

    The following code:
    class Foo<E>
      class E
        E foo()
          return this;
    }produces this error message:
    $ javac Foo.java
    Foo.java:7: incompatible types
    found   : Foo<E>.E
    required: E
          return this;
                 ^
    1 errorApparently, the type parameter E of the outer class Foo shadows the inner class declaration E. An alternative way to check is to create a new E() in this method, which results in an error message about using a type parameter where a type is expected.
    Of course this code is sick, but I would like to know where this is defined in the JLS3, since I cannot find out in which way this shadowing works. What I've found until now:
    Page 179:
    "The scope of a class' type parameter is the entire declaration of the class."
    Page 190:
    "The scope of a declaration of a member m declared in or inherited by a class type C is the entire body of C, ... "
    Page 132:
    "If a type name consists of a single Identifier, then the identifier must occur in the scope of exactly one visible declaration of type with this name, or a compile time error occurs."
    Section 6.3.1 (Shadowing declarations) specifies the shadowing rules, but does not mention type parameters.
    Any help is appreciated.

    The current behaviour in eclilpse seems to be the one we get if the bug in javac is fixed as described.
    This code compiles
    public class Shadow1 {
         class Foo<E>
           class E
              E foo()
               return this;
    }but this code
            Foo<E>.E foo()
               return this;
             }shows
    Type mismatch: cannot convert from Shadow1.Foo<E>.E to Shadow1.Foo<Shadow1.Foo<E>.E>. E
    Not sure if this error message is correct.

  • How to make an object of inner class and use it ?

    Hi tecs,
    In my JSF application i have a need to make an inner member class in one of my bean class.
    How can i make the object of this class?(what should be the entry in faces-config)
    And there are text box and check box (in the JSP) associated with the elements of this inner class. What should be the coding in JSP so that elements in the JSP can be linked with the corresponding members of the inner class ?
    Plz help.
    Thnx in advance.

    Hi
    I am havin 10 text boxes in my application.
    But out of 10 , 3 will be always together(existence of one is not possible without the other two.)
    Now i want to create a vector of objects ( here object will consist of the value corresponding to these three boxes),there can be many elements in this vector.
    So i m thinking to make an inner class which have three String variables corresponding to these text boxes that exists together.
    What can b done ?

  • Problems with inner classes

    I ran into the following problems when I tried to read into an inner class:
    This is my .jdo file
    <?xml version="1.0"?>
    <jdo>
    <package name="com.globalrefund.jdo.mna">
    <class name="Parameter$Syspar" objectid-class="SysparId">
    <extension vendor-name="kodo" key="table" value="syspar"/>
    <extension vendor-name="kodo" key="lock-column" value="none"/>
    <extension vendor-name="kodo" key="class-column" value="none"/>
    <field name="landescode" primary-key="true">
    <extension vendor-name="kodo" key="data-column"
    value="landescode"/>
    </field>
    <field name="waehrungscode">
    <extension vendor-name="kodo" key="data-column"
    value="waehrungscode"/>
    </field>
    </class>
    </package>
    </jdo>
    1.) appidtool does not work for this inner class, I get this stack trace
    C:\users\Bernhard\jbProject\refundManual>appidtool
    src\com\globalrefund\jdo\mna\Parameter$Syspar.jdo
    Generating an application id for type "class
    com.globalrefund.jdo.mna.Parameter$Syspar"...
    Exception in thread "main" java.lang.NullPointerException
    at com.solarmetric.kodo.enhance.ApplicationIdTool.getFile(Unknown
    Source)
    at
    com.solarmetric.kodo.enhance.ApplicationIdTool.writeApplicationId(Unknown
    Source)
    at
    com.solarmetric.kodo.enhance.ApplicationIdTool.writeApplicationId(Unknown
    Source)
    at com.solarmetric.kodo.enhance.ApplicationIdTool.main(Unknown
    Source)
    2.) I tried to use a hand coded inner class as ID class, but id did not work
    (is this not possible ?)
    Exception in thread "main" java.lang.NoSuchMethodError:
    com.globalrefund.jdo.mna.Parameter$SysparId: method <init>()V not found
    at
    com.globalrefund.jdo.mna.Parameter$Syspar.jdoNewObjectIdInstance(Parameter.j
    ava)
    at
    javax.jdo.spi.JDOImplHelper.newObjectIdInstance(JDOImplHelper.java:166)
    at com.solarmetric.kodo.util.ObjectIds.fromPKValues(Unknown Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.createFromResultSet(
    Unknown Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager$2.getResultObject(Un
    known Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.instantiateRow(Unknown
    Source)
    at com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.get(Unknown
    Source)
    at java.util.AbstractList$Itr.next(AbstractList.java:416)
    at com.solarmetric.kodo.runtime.ResultListIterator.next(Unknown
    Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.ResultListFactory.createResultList(Un
    known Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.executeQuery(Unknown
    Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCQuery.executeQuery(Unknown
    Source)
    at com.solarmetric.kodo.query.QueryImpl.executeWithMap(Unknown
    Source)
    at com.solarmetric.kodo.query.QueryImpl.execute(Unknown Source)
    at
    com.solarmetric.kodo.query.QueryImpl$SynchronizedQuery.execute(Unknown
    Source)
    at com.globalrefund.jdo.mna.Parameter.<init>(Parameter.java:71)
    3.) It worked after I moved the ID class into a separate class
    Regards,
    Bernhard

    1.) appidtool does not work for this inner class, I get this stack traceThis is a bug. It will be corrected in the final release of 2.3, due out
    Real Soon Now. Thanks for catching this!
    2.) I tried to use a hand coded inner class as ID class, but id did not work
    (is this not possible ?)
    Exception in thread "main" java.lang.NoSuchMethodError:
    com.globalrefund.jdo.mna.Parameter$SysparId: method <init>()V not foundThis exception is saying that your application ID class does not have a
    no-args constructor. Make sure the id class is a static inner class;
    otherwise Java transparently adds a parent object parameter to each
    constructor, and so the application id class will violoate the JDO constraint
    of having a no-args constructor.

  • Inner classes in my interface - ok, no k, indifferent?

    I have an interface and a set of ComparatorS which are only used for objects which implement the interface. So I put the ComparatorS in the interface like so (not actual code because it is for my job):
    public interface Abc {
      //Class loader should only do this once so they are basically singleton constants
      public static final Comparator C_1 = new C1();
      public static final Comparator C_2 = new C2();
      //... there is one more
      public String getSomething();
      public String getSomethingElse();
      //First Comparator inner class
      public class C1 implements Comparator {
         private C1(){ }
         //implements appropriate methods checking for instanceof Abc in the compareTo method
        //Compares something (using getSomething())
      /* Second Comparator inner class */
      public class C2 implements Comparator {
        //same thing
        //Compares somethingElse (using getSomethingElse())
    } //End interfaceUsage:
    Set s = new TreeSet(Abc.C_1);
    s.add(abc1);Because the Comparator implementations were specific to objects which implement the interface I felt that was the best way to make that fact clear. If they were over in a separate package it would be confusing that these are for the one interface. If they were in the same package as Abc it wouldn't fit (IMO) because they are more utility type classes.
    So it was either that or make them a singleton in their own class files or something like this and I found myself liking this.
    Any comments on pros/cons of doing it this way?

    I'm confused as to why it would make sense to put the
    Comparators 'in' the interface but not in the package
    with the interface. You can't put them 'in' the
    interface without putting them in the package. In
    reality, nesting them in the interface just creates
    classes in the interface's package.My whole deal is that after talking it out I see that it is bad for reuse to have something which could be so generic residing in a particular interface (and therefore deduced soon after that in the same package as my interface). Which made me decide not to have the inner classes because it IS in the same package at that point. But I am saying that is bad. As I tried to state before, for the same reason I now think it is bad to have the classes in the interface (not much i.e. no reuse outside of the interface) then it is bad to have it in the same package as the interface (unelegant reuse outside of the package). Because if the getSomething() is getName() that could be used as a comparator for many different objects in different packages. I don't want to limit. This stance was a progression, once I decided not in the interface, I then also decided not in the same package.
    Java is strongly typed. If the class isn't an
    instance of the class you are casting to (in this
    case the interface) it doesn't matter if it has a
    method with the same signature. The cast will fail.Yes, of course, but like generics, you are not limited to just one type (Object is the type of the parameter). So I can either use instanceof before casting (not the best way) or I could have private overloads of the compareTo() method, a new one for every type I support and each supported type which has a getName() could come from a couple different packages. Not that generics does it the same way but on top of being about to declare hierachies that a genericized object can deal with you can also have comma delimitted other objects. They don't have to be related by package or hierarchy in generics. So I don't think it would be so bad for my Comparator to be (if it fit that these different types all had the same method needed by my Comparator).
    >>
    Here's anothe reason not to do that. Let's say that
    someone is using the interface. They need to compare
    it to something else, if the Comparators are right
    there with the interface, they will be likely to find
    them. If they are in some other package, they'd have
    to know where to go look for them.If that is the case, where I was worried about easy to find then I would go back to using inner classes with each Comparator as a constant. If I was worried about ease of finding where these ComparatorS are over code reuse across packages.
    I mean, I think if I am going to tie the ComparatorS so close to a particular Type then I am going to add it as an inner class whether my type was an interface or a class. At least that is what I am thinking now.
    >
    This is what I am talking about. So many Java
    developers treat packages like filing cabinets. I
    put things that do this here and things that do that
    there. But this is actually not very useful and it
    hamstrings your designs.
    Java doesn't have a friend class syntax like C++. So
    there's no way to say this class over here has access
    to this but no one else does. These kinds of
    relationships are very desireable. Some classes will
    need to access things in another class that shouldn't
    be public. You can do this cleanly if they ae in the
    same package but not otherwise.But I am not talking about taking an abstract class putting it in pack1 an a subclass in pack2. I am talking about putting a utility class that could eventially work on 50 classes in a place that is playingfield neutral and not in the original type it deals with today only. I am dealing with public accessor methods on my objects.
    >
    For example. Let's say you want to create a Factory
    (I'm using Factory in a loose way here not
    necessarily a GoF Pattern) for a public class. You
    don't want every class to have access to contructor
    because it creates the Object without initializing
    all the necessary atttributes. The factory is
    specially crafted to do this with protected info and
    access rights. If you put the class and the factory
    together it;s a snap. You create a package-protected
    constructor, some package-protected methods and/or
    fields and do it. No class outside the package will
    be able to do these dangerous operations. How do you
    do this if you have a factory package and a data
    object package?That is a whole nother situation I think. In that case it is obvious. I thought my situation was a little less obvious because of the utility nature of the classes (ComparatorS) that I was dealing with.

  • A question about local inner classes

    Suppose an inner class created in a method:
    public void thisMethod(final int a){
                 class InnerClass {
                   //code
    }Why, in order to use the parameter a in the inner class, I have to pass it final?

    Aurelious wrote:
    JoachimSauer wrote:
    Because you can't refer to the argument of a method once the method call is completed (since the method argument lives on the stack).Why does that matter? If the parameter is of a primitive type, the object will get a copy of it anyway. If the parameter is not primitive, then the value on the stack will be a reference to the argument and not the argument-object itself. In either case, it should then be safe to modify the value after the method returns, as it will either be the primitive copy or a copy of a reference to the object which is itself not on the stack, so the field referenced by the object is still valid either way.
    Am I missing something?If your inner class is using a local variable in the calling method, the expectation is that it's the same variable. But it's not. If it were, then when the stack frame was popped, the variable would be out of scope, which is incompatible with the fact that the inner object can live on.
    On the other hand, if we copy it without making it final, then that's misleading. It looks like I have the same variable, but if I change it in the method, it doesn't change in the object, and vice versa.
    So we have to make a copy to prevent scope/lifetime problems, and we have to make it final so that the copy can be indistinguishable from it being the same variable.

  • Servicegen and inner class

    I try to generate web service using servicegen. I got the error message: No defualt
    constructor was found for class ClassName$InnerClassName. I checked the inner
    class it does have a default constructor taking no parameter. Anyone knows why?
    Thanks

    Hi Ron,
    Sounds like a bug. Could you supply a short example?
    Thanks,
    Bruce
    Ron Mak wrote:
    I have a class that contains a public non-static inner class. Even though the inner class has a public default contructor, servicegen claims it can't find the constructor.
    Is this a servicegen bug or limitation with inner classes?

  • Problem with constructor of inner class.

    Hi everybody!
    I have an applet which loads images from a database.
    i want to draw the images in a textarea, so i wrote an inner class, which extends textarea and overrides the paint method.
    but everytime i try to disply the applet in the browser this happens:
    java.lang.NoClassDefFoundError: WohnungSuchenApplet$Malfl�che
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
    at java.lang.Class.getConstructor0(Class.java:1762)
    at java.lang.Class.newInstance0(Class.java:276)
    at java.lang.Class.newInstance(Class.java:259)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:567)
    at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1778)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:496)
    at sun.applet.AppletPanel.run(AppletPanel.java:293)
    at java.lang.Thread.run(Thread.java:536)
    so my class has no own constructor, it just has the paint method overwritten.
    my class looks like this:
    public class Malfl�che extends javax.swing.JTextArea{
    public void paint(Graphics g){
    Color grey=new Color(220,220,220);
    g.drawImage(img,10,10,null);
    how should a constructor for this class look like?
    sorry i am quite new to this, so i really dont have a clue!
    my class does not have any attributes or requires any so it doesnt need a constructor, doesnt it?
    thanks a lot
    tim

    First off, unlike regular classes, inner classes can be declared public, private, protected, and default.
    Secondly, why are you using the JTextArea to display an image, why not use a JLabel, which takes an Image object as its constructor.
    Thirdly, when you drew your image you did not give it a width and height
    g.drawImage(img, 0,0, img.getWidth(null), img.getHeight(null), null);
    otherwise it will make your image 1 X 1 pixels. not big enough to see.

  • Help: Factory Class using Inner Class and Private Constructor?

    The situation is as follows:
    I want a GamesCollection class that instantiates Game objects by looking up the information needed from a database. I would like to use Game outside of GamesCollection, but only have it instantiated by GamesCollection to ensure the game actually exist. Each Game object is linked to a database record. If a Game object exist, it must also exist in the database. Game objects can never be removed from the database.
    I thought about making the Game object an inner class of GamesCollection, but this means that Game class constructor is still visible outside. So what if I made Game constructor private? Well, now I can't create Game objects without a static method inside Game class (static Object factory).
    Basically what I need is a constructor for the inner Game class accessible to GamesCollection, but not to the rest of the world (including packages). Is there a way to do this?

    leesiulung wrote:
    As a second look, I was initially confused about your first implementation, but it now makes more sense.
    Let me make sure I understand this:
    - the interface is needed to make the class accessible outside the outer classBetter: it is necessary to have a type that is accessible outside of GameCollection -- what else could be the return type of instance?
    - the instance() method is the object factory
    - the private modifier for the inner class is to prevent outside classes to instantiate this objectRight.
    However, is a private inner class accessible in the outer class? Try it and see.
    How does this affect private/public modifiers on inner classes?Take about five minutes and write a few tests. That should answer any questions you may have.
    How do instantiate a GameImpl object? This basically goes back to the first question.Filling out the initial solution:
    public interface Game {
        String method();
    public class GameCollection {
        private static  class GameImpl implements Game {
            public String method() {
                return "GameImpl";
        public Game instance() {
            return new GameImpl();
        public static void main(String[] args) {
            GameCollection app = new GameCollection();
            Game game = app.instance();
            System.out.println(game.method());
    }Even if you were not interested in controlling game creation, defining interfaces for key concepts like Game is always going to be a good idea. Consider how you will write testing code, for example. How will you mock Game?

  • How to access var in outter class inside inner class

    I've problem with this, how to access var number1 and number2 at outter class inside inner class? what statement do i have to use to access it ? i tried with " int number1 = Kalkulator1.this.number1; " but there no value at class option var y when the program was running...
    import java.io.*;
    public class Kalkulator1{
    int number1,number2,x;
    /* The short way to create instance object for input console*/
    private static BufferedReader stdin =
    new BufferedReader( new InputStreamReader( System.in ) );
    public static void main(String[] args)throws IOException {
    System.out.println("---------------------------------------");
    System.out.println("Kalkulator Sayur by Cumi ");
    System.out.println("---------------------------------------");
    System.out.println("Tentukan jenis operasi bilangan [0-4] ");
    System.out.println(" 1. Penjumlahan ");
    System.out.println(" 2. Pengurangan ");
    System.out.println(" 3. Perkalian ");
    System.out.println(" 4. Pembagian ");
    System.out.println("---------------------------------------");
    System.out.print(" Masukan jenis operasi : ");
    String ops = stdin.readLine();
         int numberops = Integer.parseInt( ops );
    System.out.print("Masukan Bilangan ke-1 : ");
    String input1 = stdin.readLine();
    int number1 = Integer.parseInt( input1 );
    System.out.print("Masukan Bilangan ke-2 : ");
    String input2 = stdin.readLine();
    int number2 = Integer.parseInt( input2 );     
         Kalkulator1 op = new Kalkulator1();
    Kalkulator1.option b = op.new option();
         b.pilihan(numberops);
    System.out.println("Bilangan yang dimasukkan adalah = " + number1 +" dan "+ number2 );
    class option{
    int x,y;
         int number1 = Kalkulator1.this.number1;
         int number2 = Kalkulator1.this.number2;
    void pilihan(int x) {
    if (x == 1)
    {System.out.println("Operasi yang digunakan adalah Penjumlahan");
            int y = (number1+number2);
            System.out.println("Hasil dari operasi adalah = " + y);}
    else
    {if (x == 2) {System.out.println("Operasi yang digunakan adalah Pengurangan");
             int y = (number1-number2);
             System.out.println("Hasil dari operasi adalah = " + y);}
    else
    {if (x == 3) {System.out.println("Operasi yang digunakan adalah Perkalian");
             int y = (number1*number2);
             System.out.println("Hasil dari operasi adalah = " + y);}
    else
    {if (x == 4) {System.out.println("Operasi yang digunakan adalah Pembagian ");
             int y = (number1/number2);
             System.out.println("Hasil dari operasi adalah =" + y);}
    else {System.out.println( "Operasi yang digunakan adalah Pembagian ");
    }

    Delete the variables number1 and number2 from your inner class. Your inner class can access the variables in the outer class directly. Unless you need the inner and outer class variables to hold different values then you can give them different names.
    In future place code tags around your code to make it retain formatting. Highlight code and click code button.

  • Inner classes in ABAP

    Hello!
    Is it possible to declare inner classes, that is, classes within classes in ABAP? If yes, please provide example.
    Thanks!
    Kind regards,
    Igor

    > No. I need a class to be declared within a class, or
    > even within a method in order to make it visible only
    > to the containing class (or method).
    You cannot <b><i>nest</i></b> class declarations, but there <b><u>happens to be</u></b> a way of implementing the functionality you desire, though too tedious to be useful practically. You can use a combination of a <b>"CREATE PRIVATE"</b> class and the <b>Friendship</b> idea to do this. A quick and dirty example is :
    REPORT  zootest.
    CLASS lcl_test_outer DEFINITION DEFERRED.
    *       CLASS lcl_test_inner DEFINITION
    CLASS lcl_test_inner
                     DEFINITION CREATE PRIVATE
                     FRIENDS lcl_test_outer.
      PUBLIC SECTION.
        DATA: test.
    ENDCLASS.              
    *       CLASS lcl_test_outer DEFINITION
    CLASS lcl_test_outer DEFINITION.
      PUBLIC SECTION.
        METHODS: test_inst.
    ENDCLASS.                  
    *       CLASS lcl_test_outer IMPLEMENTATION
    CLASS lcl_test_outer IMPLEMENTATION.
      METHOD test_inst.
        DATA: ref1 TYPE REF TO lcl_test_inner.
        CREATE OBJECT ref1.
      ENDMETHOD.
    ENDCLASS.
    DATA: ref1 TYPE REF TO lcl_test_inner,
          ref2 TYPE REF TO lcl_test_outer.
    START-OF-SELECTION.
      CREATE OBJECT ref2.
    Crude, but it can be refined further, but I hope this helps
    Regards,
    Dushyant Shetty

  • Null pointer exception with inner class

    Hi everyone,
    I've written an applet that is an animation of a wheel turning. The animation is drawn on a customised JPanel which is an inner class called animateArea. The main class is called Rotary. It runs fine when I run it from JBuilder in the Applet Viewer. However when I try to open the html in internet explorer it gives me null pointer exceptions like the following:
    java.lang.NullPointerException      
    at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2761)      
    at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2722)      
    at Rotary$animateArea.paintComponent(Rotary.java:251)      
    at javax.swing.JComponent.paint(JComponent.java:808)      
    at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4771)      
    at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4724)      
    at javax.swing.JComponent._paintImmediately(JComponent.java:4668)      
    at javax.swing.JComponent.paintImmediately(JComponent.java:4477)      
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)      
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)      
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)      
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)      
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)      
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)      
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)      
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)      
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    Do inner classes have to be compiled seperately or anything?
    Thanks a million for you time,
    CurtinR

    I think that I am using the Java plugin ( Its a computer in college so I'm not certain but I just tried running an applet from the Swing tutorial and it worked)
    Its an image of a rotating wheel and in each sector of the wheel is the name of a person - when you click on the sector it goes red and the email window should come up (that doesn't work yet though). The stop and play buttons stop or start the animation. It is started by default.
    This is the code for the applet:
    import java.applet.*;
    import javax.swing.JApplet;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import java.awt.image.*;
    import java.util.StringTokenizer;
    import java.net.*;
    public class Rotary extends JApplet implements ActionListener, MouseListener
    public boolean rotating;
    private Timer timer;
    private int delay = 1000;
    private AffineTransform transform;
    private JTextArea txtTest; //temp
    private Container c;
    private animateArea wheelPanel;
    private JButton btPlay, btStop;
    private BoxLayout layout;
    private JPanel btPanel;
    public Image wheel;
    public int currentSector;
    public String members[];
    public int [][]coordsX, coordsY; //stores sector no. and x or y coordinates for that point
    final int TOTAL_SECTORS= 48;
    //creates polygon array - each polygon represents a sector on wheel
    public Polygon polySector1,polySector2,polySector3, polySector4, polySector5,polySector6,polySector7,polySector8,polySector9,polySector10,
    polySector11,polySector12,polySector13,polySector14,polySector15,polySector16,polySector17,polySector18,polySector19,polySector20,
    polySector21,polySector22,polySector23,polySector24,polySector25,polySector26,polySector27,polySector28,polySector29,polySector30,
    polySector31,polySector32,polySector33,polySector34,polySector35,polySector36,polySector37,polySector38,polySector39,polySector40,
    polySector41,polySector42,polySector43,polySector44,polySector45,polySector46,polySector47,polySector48;
    public Polygon polySectors[]={polySector1,polySector2,polySector3, polySector4, polySector5,polySector6,polySector7,polySector8,polySector9,polySector10,
                      polySector11,polySector12,polySector13,polySector14,polySector15,polySector16,polySector17,polySector18,polySector19,polySector20,
                      polySector21,polySector22,polySector23,polySector24,polySector25,polySector26,polySector27,polySector28,polySector29,polySector30,
                      polySector31,polySector32,polySector33,polySector34,polySector35,polySector36,polySector37,polySector38,polySector39,polySector40,
                      polySector41,polySector42,polySector43,polySector44,polySector45,polySector46,polySector47,polySector48};
    public void init()
    members = new String[TOTAL_SECTORS];
    coordsX= new int[TOTAL_SECTORS][4];
    coordsY= new int[TOTAL_SECTORS][4];
    currentSector = -1;
    rotating = true;
    transform = new AffineTransform();
    //***********************************Create GUI**************************
    wheelPanel = new animateArea(); //create a canvas where the animation will be displayed
    wheelPanel.setSize(600,580);
    wheelPanel.setBackground(Color.yellow);
    btPanel = new JPanel(); //create a panel for the buttons
    btPanel.setLayout(new BoxLayout(btPanel,BoxLayout.Y_AXIS));
    btPanel.setBackground(Color.blue);
    btPanel.setMaximumSize(new Dimension(30,580));
    btPanel.setMinimumSize(new Dimension(30,580));
    btPlay = new JButton("Play");
    btStop = new JButton("Stop");
    //txtTest = new JTextArea(5,5); //temp
    btPanel.add(btPlay);
    btPanel.add(btStop);
    // btPanel.add(txtTest); //temp
    c = getContentPane();
    layout = new BoxLayout(c,layout.X_AXIS);
    c.setLayout(layout);
    c.add(wheelPanel); //add panel and animate canvas to the applet
    c.add(btPanel);
    wheel = getImage(getDocumentBase(),"rotary2.gif");
    getParameters();
    for(int k = 0; k <TOTAL_SECTORS; k++)
    polySectors[k] = new Polygon();
    for(int n= 0; n<4; n++)
    polySectors[k].addPoint(coordsX[k][n],coordsY[k][n]);
    btPlay.addActionListener(this);
    btStop.addActionListener(this);
    wheelPanel.addMouseListener(this);
    startAnimation();
    public void mouseClicked(MouseEvent e)
    if (rotating == false) //user can only hightlight a sector when wheel is not rotating
    for(int h= 0; h<TOTAL_SECTORS; h++)
    if(polySectors[h].contains(e.getX(),e.getY()))
    currentSector = h;
    wheelPanel.repaint();
    email();
    public void mouseExited(MouseEvent e){}
    public void mouseEntered(MouseEvent e){}
    public void mouseReleased(MouseEvent e){}
    public void mousePressed(MouseEvent e){}
    public void email()
    try
    URL rotaryMail = new URL("mailto:[email protected]");
    getAppletContext().showDocument(rotaryMail);
    catch(MalformedURLException mue)
    System.out.println("bad url!");
    public void getParameters()
    StringTokenizer stSector;
    String parCoords;
    for(int i = 0; i <TOTAL_SECTORS; i++)
    {               //put member names in applet parameter list into an array
    members[i] = getParameter("member"+i);
    //separate coordinate string and store coordinates in 2 arrays
    parCoords=getParameter("sector"+i);
    stSector = new StringTokenizer(parCoords, ",");
    for(int j = 0; j<4; j++)
    coordsX[i][j] = Integer.parseInt(stSector.nextToken());
    coordsY[i][j] = Integer.parseInt(stSector.nextToken());
    public void actionPerformed(ActionEvent e)
    wheelPanel.repaint(); //repaint when timer event occurs
    if (e.getActionCommand()=="Stop")
    stopAnimation();
    else if(e.getActionCommand()=="Play")
    startAnimation();
    public void startAnimation()
    if(timer == null)
    timer = new Timer(delay,this);
    timer.start();
    else if(!timer.isRunning())
    timer.restart();
    Thanks so much for your help!

  • Java Inner classes within the Threading paradigm

    Hi all.
    Im familiar with static nested classes, method local classes, inner classes and anonymous classes.
    But what I am a little perplexed by, is when exactly to use inner classes or static nested classes? (forgetting anonymous classes and method local classes).
    I read this article (http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html) and the first point makes for a good argument, but why nest the class? Why not define it as an external class?
    Also you typically find nested classes within the Threading paradigm, but why?
    I typically would create a top level class (non nested) that would implement the Runnable interface, override run() and then
    use this class when constructing a new Thread.
    Any clarification would be greatly received.
    Thanks and Happy Friday.

    Boeing-737 wrote:
    I read this article (http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html) and the first point makes for a good argument, but why nest the class? Why not define it as an external class?
    I was going to provide some reasons, but when I read the article I found they were already there. Following the DRY principle I'm going to let the article speak for itself.
    Also you typically find nested classes within the Threading paradigm, but why?No, I don't. If that's where you typically find them then you haven't had a varied experience.
    I typically would create a top level class (non nested) that would implement the Runnable interface, override run() and then
    use this class when constructing a new Thread.So carry on doing that, if it works for you.

Maybe you are looking for

  • Regarding sending email alert through RFC

    Hi, Iam creating an email alert to my Alert Inbox via RFC when Message mapping error occurs and I created a UDF which contains the following code public void UDF_ALERT (String[] message,String[] Category,ResultList result,Container container){ try {

  • Steps to create my azure app

    hello, I have coded a mathematical c++ solver that take input data in json file , and I want to execute it on cloud within a client application. Is these steps right? 1- create an azure service that hos my solver. 2- Create a client application that

  • Please help! not serializableException: im not sure why!

    hello all, im using a JTable and would like to save the information in the table. whe the user presses the save button, i would like to call my save methods, but i end up with a serializable exception on my filfilter. I am not sue why this occurs, so

  • Slitting programme for mother coil in SAP

    Hi Our client want sltting programme for the mother coils. They want the system to propose the best combination of width & thickness and weight so that the scrap is minmum.Foe eg, lets say the width of mother coils is 1000mm  , thickness is 1.2mm and

  • How do I differentiate iPad 2 from 3

    I want to know how one can differentiate iPad 2 from iPad 3