What's wrong with static methods?

Answers on an postcard please.

I think the point here is that sometimes people come from a procedural background (or maybe no background) and they start with main, and one static method leads to another. They reach a tipping point where they are reluctant to define non-static methods to a class because it's all static elsewhere. And static method can't access instance data, so their data becomes largely static as well. When the dust settles, they are programming procedually in Java. So too many static methods is a sign that you may be programming procedurally instead of doing OOP, but using static appropriately is still cool.
And let's not get pedantic. What goes wrong if I make my String class's getLength method static?
public final class MyString {
    private int length;
    public static int getLength(String s) {
        return s.length;
}It's a misuse of static, but it doesn't break my design.

Similar Messages

  • What's wrong with this method()?

    Applications : Messenger Server
    IDE: Netbeans 6.7.1
    OS: Mac OS 10.6.4 Snow Leopard
    Java Version: 1.6
    Code…
    private void startButtonActionPerformed(java.awt.event.ActionEvent evt)
    startButton.setEnabled(false);
    stopButton.setEnabled(true);
    r = new ResourceRelease();
    c = new Connector();
    c.initiateServerSocket();
    c.startListening();
    through the properties window of the start and stop buttons in Netbeans i have set the initial state of start button as enable and stop as disabled.
    what I'm trying is that as soon as the start button is pressed the program should disable the start button and enable the stop button and then continue with the job it does (initiating a serversocket and looking for connections).
    this happens fine as long as the last 4 lines are commented. with the last 4 lines in the method, the working of the server is fine except the fact that it doesn't disable the start button and enable the stop button.
    so there remains no way i can stop the server except quitting the application.
    any help as to what could be wrong?

    I changed the code a little bit to improve it and debug it.
    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
    System.out.println("in startbuttonActionPerformed");
    System.out.println("1");
    startButton.setEnabled(false);
    System.out.println("2");
    stopButton.setEnabled(true);
    System.out.println("3");
    r = new ResourceRelease();
    c = new Connector();
    c.initiateServerSocket();
    r.registerSS(c);
    c.listen();
    System.out.println("out startbuttonActionPerformed");
    the listen() method is same as the startListening() method. and it turns out that it is the culprit. as soon as i put it in comments, the start - stop buttons work fine.
    any knowledge what could be going wrong?
    here is the listen() method…
    //inisitates a loop that listens for socket connections until stopSignal flag is set.
    void listen()
    System.out.println("in listen");
    while(stopSignal==false)
    try
    sc = ss.accept(); //start listenining
    Lists.scVector.addElement(sc); //add socket object to vector
    threadDispatcher(sc); //call thread dispatcher to initiate new thread for the new socket
    catch(IOException ioe)
    System.out.println(ioe);
    System.out.println("in listen");
    }

  • What is wrong with this method?

    When i try to compile
         public double generateXPos()
              double d = Math.random()*100;
              if (d > 37.0)
                   generateXPos();
              else
                   return d;
    it says: "this method must return a result of type double", bit doesn't it do so?!?
    By the way I am using eclipse v. 3.0.1
    Thanks in advance,
    Floesch

    Because i could not think of this way of doing that,
    for i am a bloody beginner.A "bloody" beginner? You should wipe yourself off with a damp cloth.
    Could you tell me how to do it then?I can point you in the right direction. The first line of your method generates a number between 1 and 100. Either you intentionally wrote it to work that way, in which case you should very easily be able to re-write it to generate a number between 1 and 37 instead; Or, perhaps you copied it from somewhere else not understanding what it does, in which case you should take the time to understand it before continuing.
    Either way, as you now know that the first line generates a number between 1 and 100, you should be able to make a good guess at how to change it so that the generated number is between 1 and 37. If nothing at all springs to mind here, then I really genuinely do believe you aren't the kind of person that's gonna do well as a programmer.

  • What's wrong with my method

    I have a method with 2 parameters:
    public void getFileInfo(int array_length,String user_name)
    int arraylength=array_length;
    username=user_name;
    downloadname_files = new String[arraylength];
    displayname_files = new String[arraylength];
    size_files = new String[arraylength];
    date_files = new String[arraylength];
    but when I call this method I get a IllegalStateException?
    Can't I pass a parameter that will give the length of my array???
    when I delete the parameter that will determine the arraylength and I replce this arraylength value with foe example 2 then I get no more errors??
    ANY IDEAS????

    WEIRD!!!!!!!!!!!!!!
    I'm using this function from a jsp page, and I can't pass anything more than this username. I tried debugging and even if I didn't call this method I still get the error, now I temporarly deleted the arraylength parameter and everything works fine, though I still can not pass that specific parameter
    perhaps I should write a simple get method to require the value instead of passing it through

  • What's wrong with the method Package.getPackages() ?

    Hello,
    has anyone an idea why this code doesn't print "java.sql" and other packages' names ?
    for (Package pack : Package.getPackages()) {
         System.out.println(pack.getName());
    }this is what figures in the javadoc :
    public static Package[] getPackages()
    Get all the packages currently known for the caller's ClassLoader instance. Those packages correspond to classes loaded via or accessible by name to that ClassLoader instance. If the caller's ClassLoader instance is the bootstrap ClassLoader instance, which may be represented by null in some implementations, only packages corresponding to classes loaded by the bootstrap ClassLoader instance will be returned.
    Returns:
    a new array of packages known to the callers ClassLoader instance. An zero length array is returned if none are known.
    thank you..

    Well, I find my self a solution !
    there is it :
    public final static String apiJarName = "rt.jar";
    /* Gives the path of rt.jar */
    public static String getAPIPath() {
         String paths[] = System.getProperty("sun.boot.class.path").split(System.getProperty("path.separator"));
         String APIPath = "";
         int i=0;
         while (APIPath.equals("")) {
              if (paths.endsWith(apiJarName)) {
                   APIPath = paths[i];
              else {
                   i++;
         return APIPath;
    /* Gives the list of packages that a mentioned package contains */
    public static ArrayList<String> getPackageList(String packageName) {
         try {
              ArrayList<String> packageList = new ArrayList<String>();
              JarFile apiJar = new JarFile(getAPIPath());
              Enumeration<JarEntry> entries = apiJar.entries();
              while (entries.hasMoreElements()) {
                   String entry = entries.nextElement().getName();
                   if (entry.startsWith("java")) {
                        String pack = entry.substring(0, entry.lastIndexOf("/")).replaceAll("/", ".");
                        if (!packageList.contains(pack)) {
                             packageList.add(pack);
              apiJar.close();
              return packageList;
         catch (IOException e) {
              return null;
    }thanks too much *JoachimSauer* and *tschodt*, I couldn't done it without you :)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Can someone tell me what's wrong with this method

    public boolean drop(int col, int piece) {
              if (isLegalMove(col)) {
                   for (int r = 0; r < getNumRows(); r++) {
                        if (mySpaces[r][col] == EMPTY) {
                             mySpaces[r][col] = piece;
                             return true;
              } else
                   return false;
         }it always asks that I need to return something, what should I do??

    public boolean drop(int col, int piece) {
        if (isLegalMove(col)) {
            for (int r = 0; r < getNumRows(); r++) {
              if (mySpaces[r][col] == EMPTY) {
                mySpaces[r][col] = piece;
                return true;
        } //else <--- remove the else
        return false;
    }

  • I can't figure out what's wrong with this code

    First i want this program to allow me to enter a number with the EasyReader class and depending on the number entered it will show that specific line of this peom:
    One two buckle your shoe
    Three four shut the door
    Five six pick up sticks
    Seven eight lay them straight
    Nine ten this is the end.
    The error message i got was an illegal start of expression. I can't figure out why it is giving me this error because i have if (n = 1) || (n = 2) statements. My code is:
    public class PoemSeventeen
    public static void main(String[] args)
    EasyReader console = new EasyReader();
    System.out.println("Enter a number for the poem (0 to quit): ");
    int n = console.readInt();
    if (n = 1) || (n = 2)
    System.out.println("One, two, buckle your shoe");
    else if (n = 3) || (n = 4)
    System.out.println("Three, four, shut the door");
    else if (n = 5) || (n = 6)
    System.out.println("Five, six, pick up sticks");
    else if (n = 7) || (n = 8)
    System.out.println("Seven, eight, lay them straight");
    else if (n = 9) || (n = 10)
    System.out.println("Nine, ten, this is the end");
    else if (n = 0)
    System.out.println("You may exit now");
    else
    System.out.println("Put in a number between 0 and 10");
    I messed around with a few other thing because i had some weird errors before but now i have narrowed it down to just this 1 error.
    The EasyReader class code:
    // package com.skylit.io;
    import java.io.*;
    * @author Gary Litvin
    * @version 1.2, 5/30/02
    * Written as part of
    * <i>Java Methods: An Introduction to Object-Oriented Programming</i>
    * (Skylight Publishing 2001, ISBN 0-9654853-7-4)
    * and
    * <i>Java Methods AB: Data Structures</i>
    * (Skylight Publishing 2003, ISBN 0-9654853-1-5)
    * EasyReader provides simple methods for reading the console and
    * for opening and reading text files. All exceptions are handled
    * inside the class and are hidden from the user.
    * <xmp>
    * Example:
    * =======
    * EasyReader console = new EasyReader();
    * System.out.print("Enter input file name: ");
    * String fileName = console.readLine();
    * EasyReader inFile = new EasyReader(fileName);
    * if (inFile.bad())
    * System.err.println("Can't open " + fileName);
    * System.exit(1);
    * String firstLine = inFile.readLine();
    * if (!inFile.eof()) // or: if (firstLine != null)
    * System.out.println("The first line is : " + firstLine);
    * System.out.print("Enter the maximum number of integers to read: ");
    * int maxCount = console.readInt();
    * int k, count = 0;
    * while (count < maxCount && !inFile.eof())
    * k = inFile.readInt();
    * if (!inFile.eof())
    * // process or store this number
    * count++;
    * inFile.close(); // optional
    * System.out.println(count + " numbers read");
    * </xmp>
    public class EasyReader
    protected String myFileName;
    protected BufferedReader myInFile;
    protected int myErrorFlags = 0;
    protected static final int OPENERROR = 0x0001;
    protected static final int CLOSEERROR = 0x0002;
    protected static final int READERROR = 0x0004;
    protected static final int EOF = 0x0100;
    * Constructor. Prepares console (System.in) for reading
    public EasyReader()
    myFileName = null;
    myErrorFlags = 0;
    myInFile = new BufferedReader(
    new InputStreamReader(System.in), 128);
    * Constructor. opens a file for reading
    * @param fileName the name or pathname of the file
    public EasyReader(String fileName)
    myFileName = fileName;
    myErrorFlags = 0;
    try
    myInFile = new BufferedReader(new FileReader(fileName), 1024);
    catch (FileNotFoundException e)
    myErrorFlags |= OPENERROR;
    myFileName = null;
    * Closes the file
    public void close()
    if (myFileName == null)
    return;
    try
    myInFile.close();
    catch (IOException e)
    System.err.println("Error closing " + myFileName + "\n");
    myErrorFlags |= CLOSEERROR;
    * Checks the status of the file
    * @return true if en error occurred opening or reading the file,
    * false otherwise
    public boolean bad()
    return myErrorFlags != 0;
    * Checks the EOF status of the file
    * @return true if EOF was encountered in the previous read
    * operation, false otherwise
    public boolean eof()
    return (myErrorFlags & EOF) != 0;
    private boolean ready() throws IOException
    return myFileName == null || myInFile.ready();
    * Reads the next character from a file (any character including
    * a space or a newline character).
    * @return character read or <code>null</code> character
    * (Unicode 0) if trying to read beyond the EOF
    public char readChar()
    char ch = '\u0000';
    try
    if (ready())
    ch = (char)myInFile.read();
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    if (ch == '\u0000')
    myErrorFlags |= EOF;
    return ch;
    * Reads from the current position in the file up to and including
    * the next newline character. The newline character is thrown away
    * @return the read string (excluding the newline character) or
    * null if trying to read beyond the EOF
    public String readLine()
    String s = null;
    try
    s = myInFile.readLine();
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    if (s == null)
    myErrorFlags |= EOF;
    return s;
    * Skips whitespace and reads the next word (a string of consecutive
    * non-whitespace characters (up to but excluding the next space,
    * newline, etc.)
    * @return the read string or null if trying to read beyond the EOF
    public String readWord()
    StringBuffer buffer = new StringBuffer(128);
    char ch = ' ';
    int count = 0;
    String s = null;
    try
    while (ready() && Character.isWhitespace(ch))
    ch = (char)myInFile.read();
    while (ready() && !Character.isWhitespace(ch))
    count++;
    buffer.append(ch);
    myInFile.mark(1);
    ch = (char)myInFile.read();
    if (count > 0)
    myInFile.reset();
    s = buffer.toString();
    else
    myErrorFlags |= EOF;
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    return s;
    * Reads the next integer (without validating its format)
    * @return the integer read or 0 if trying to read beyond the EOF
    public int readInt()
    String s = readWord();
    if (s != null)
    return Integer.parseInt(s);
    else
    return 0;
    * Reads the next double (without validating its format)
    * @return the number read or 0 if trying to read beyond the EOF
    public double readDouble()
    String s = readWord();
    if (s != null)
    return Double.parseDouble(s);
    // in Java 1, use: return Double.valueOf(s).doubleValue();
    else
    return 0.0;
    Can anybody please tell me what's wrong with this code? Thanks

    String[] message = {
        "One, two, buckle your shoe",
        "One, two, buckle your shoe",
        "Three, four, shut the door",
        "Three, four, shut the door",
        "Five, six, pick up sticks",
        "Five, six, pick up sticks",
        "Seven, eight, lay them straight",
        "Seven, eight, lay them straight",
        "Nine, ten, this is the end",
        "Nine, ten, this is the end"
    if(n>0)
        System.out.println(message[n]);
    else
        System.exit(0);

  • What's wrong with this simple code?

    What's wrong with this simple code? Complier points out that
    1. a '{' is expected at line6;
    2. Statement expected at the line which PI is declared;
    3. Type expected at "System.out.println("Demostrating PI");"
    However, I can't figure out them. Please help. Thanks.
    Here is the code:
    import java.util.*;
    public class DebugTwo3
    // This class demonstrates some math methods
    public static void main(String args[])
              public static final double PI = 3.14159;
              double radius = 2.00;
              double area;
              double roundArea;
              System.out.println("Demonstrating PI");
              area = PI * radius * radius;
              System.out.println("area is " + area);
              roundArea = Math.round(area);
              System.out.println("Rounded area is " + roundArea);

    Change your code to this:
    import java.util.*;
    public class DebugTwo3
         public static final double PI = 3.14159;
         public static void main(String args[])
              double radius = 2.00;
              double area;
              double roundArea;
              System.out.println("Demonstrating PI");
              area = PI * radius * radius;
              System.out.println("area is " + area);
              roundArea = Math.round(area);
              System.out.println("Rounded area is " + roundArea);
    Klint

  • What's wrong with this code (in recursion there may be a problem )

    // ELEMENTS OF TWO VECTORS ARE COMPARED HERE
    // CHECK WHAT IS WRONG WITH THIS PGM
    // there may be a problem in recursion
    import java.util.*;
    class Test
    Vector phy,db;
    public static void main(String adf[])
         Vector pp1=new Vector();
         Vector dp1=new Vector();
         //adding elements to the vector
         pp1.add("1");
         pp1.add("a");
         pp1.add("b");
         pp1.add("h");
         pp1.add("c");
         dp1.add("q");
         dp1.add("c");
         dp1.add("h");
         dp1.add("w");
         dp1.add("t");
         printVector(dp1);
         printVector(pp1);
         check2Vectors(pp1,dp1);
    public static void printVector(Vector v1)
         System.out.println("Vector size "+v1.size());
         for(int i=0;i<v1.size();i++)
              System.out.println(v1.get(i).toString());
    public static void check2Vectors(Vector p,Vector d)
         System.out.println("p.size() "+p.size()+" d.size() "+d.size());
         printVector(p);
         printVector(d);
         for(int i=0;i<p.size();i++)
                   for(int j=0;j<d.size();j++)
                        System.out.println(" i= "+i+" j= "+j);
                        Object s1=p.elementAt(i);
                        Object s2=d.elementAt(j);
              System.out.println("Checking "+s1+" and "+s2);
                        if(s1.equals(s2))
    System.out.println("Equal and Removing "+s1+" and "+s2);
                             p.remove(i);
                             d.remove(j);
                             printVector(p);
                             printVector(d);                    
                        check2Vectors(p,d);
                   }//inner for
              }//outer for     
    if(p.size()==0||d.size()==0)
    System.out.println("Vector checking finished and both match");
    else
    System.out.println("Vector checking finished and both do not match");
    }//method
    }

    hi,
    but the upper limit is changing everytime you call the function recursively
    so there should not be any problem(i suppose)
    my intension is to get the unmatched elements of the two vectors
    suggest me changes and thanks in advancce
    ashok
    The problems comes from the fact that you remove
    elements for a Vector while iterating in a loop where
    the upper limit as been set to the initial size of the
    Vector.
    You should use so while loops with flexible stop
    conditions that would work when the size of the Vector
    changes.
    Finally: why don't you use Vector.equals() ?

  • HELP!What's wrong with my GZIP program?

    Here's part of the source code:
    static void Compress(String strfilename)     
         int iTemp;
         try
              BufferedReader brIn=new BufferedReader(new FileReader(strfilename));
              BufferedOutputStream bosOut=new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(strfilename+".gz")));
              while(true)
                   iTemp=brIn.read();
                   if(iTemp==-1) break;
                   bosOut.write(iTemp);                         }
              brIn.close();
              bosOut.close();
         catch(Exception e)
              System.out.println("Error: "+e);
    If I use it to compress a small file(20k),the compression is successful,and I can also see it using WINRAR;but once I decompress
    this GZIP file,all the English words are correct,while other unicodes
    such as Chinese become unrecognizable;
    If I use it to compress a "large" file(3M) such as abc.chm,the size of the compressed file is about 2M(INCREDIBLE! WINRAR can only decrease
    the size of this file by 30k);But..the size of decompressed file is
    still about 2M,and windows cannot read it (Invalid page error).
    I wonder what's wrong with my program? Even if I use "javac -encoding
    gb2312 ..." to compile my program,the result is also the same.
    HOW SHOULD I DO??

    Hi, jchc,
    Let me help you a little bit, here. hwalkup is correct that for data compression you should use input and output stream instead of readers and writers. I don't think that mixing a reader with an output stream would work anyway as streams read and write bytes (8-bit data), while readers and writers read and write characters (16-bit data). hwalkup is also correct to suggest that you should use a buffer (a byte[]) to improve the performance of your streaming processes.
    Here is code for methods to compress and decompress one file into another. Note: the decompress() method will throw an IOException if the file to decompress (inFile) is not actually compressed in the first place.
        public static void compress(File inFile, File outFile)
                throws FileNotFoundException, IOException {
            InputStream in = null;
            OutputStream out = null;
            try {
                in = new BufferedInputStream(new FileInputStream(inFile));
                GZIPOutputStream gzipOut = new GZIPOutputStream(
                                           new FileOutputStream(outFile));
                out = new BufferedOutputStream(gzipOut);
                byte[] buffer = new byte[512];
                for (int i = 0; (i = in.read(buffer)) > -1; ) {
                    out.write(buffer, 0, i);
                out.flush();
                gzipOut.finish(); // absolutely necessary
            } finally {
                // always close your output streams before your input streams
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
        public static void decompress(File inFile, File outFile)
                throws FileNotFoundException, IOException {
            InputStream in = null;
            OutputStream out = null;
            try {
                GZIPInputStream gzipIn = new GZIPInputStream(
                                         new FileInputStream(inFile));
                in = new BufferedInputStream(gzipIn);
                out = new BufferedOutputStream(new FileOutputStream(outFile));
                byte[] buffer = new byte[512];
                for (int i = 0; (i = in.read(buffer)) > -1; ) {
                    out.write(buffer, 0, i);
                out.flush();
            } finally {
                // always close your output streams before your input streams
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
        }Shaun

  • What is wrong with as3

    this is not a question about 'how i do X'. is rather a 'discussion' (flame or whatever, but to defend or argue about aspects, not people) about 'what is wrong with as3' and what aspects whould be taken into consideration for updates. right now i am using as3, and since i paid for this license, i choose this tool over some alternatives and i am using it to do stuff for other people who pay me to do it, i think it can be helpful for all of us if some actions are started in the right direction. i have already posted about 'all people in adobe are dumbasses that do not know how to make a scripting tool and are messing up my work', but i was pissed at the time (i still am pissed) but i believe this is not the right aproach. instead, if this goes to the right people in adobe, we all may get something in the future, like better and easier todo apps and web presentations.
    pre: not only about the as3 specification, but COMPLY with the specification that you set. for example, some time ago there were problems with matrix transforms. this was corrected later with a patch. but this means it is not even doing what is is supposed to do
    1. scriptable masks and movement, sprites and child sprites: there is a sprite with a mask, the mask is a shape drawn via script, something like
    somemask=new shape();
    somemask.graphics.beginfill();
    (...etc)
    somesprite.mask=somemask;
    just like that. now add some child sprites to 'somesprite', and make 'somesprite' move, scale and rotate. there you will have something like a kaleidoscope, but not what you expected to do with your script. as the child sprites move in the parent mask, you will see that the child sprites appear or dissapear kind of randomly, and if the child sprites are textfields, it may be that the text is rendered outside the mask, or partially rendered outside the mask (as in only part of the text), rendered with the wrongf rotation or in the wrong place. some child sprites are clipped correctly, some dissapear totally when only a part should dissapear (clipped) etc.
    way around: have not tried it yet, but i have the impression that bitmaps have different criteria for clipping, so i am thinking of trying this: appli an empty filter (a filter with params so it does not have any effect on the sprite or in the textfield) so the sprite is rendered as bitmap before doing anything else with it. as i said, i have not done it yet, but it may be a way around this problem, to avoid all this inconsistency with clipping
    1-b. inconsistency between hierarchy and coordinates, specially masks: you apply a mask to a sprite, yet the sprite has a set of coordinates (so 'x' in the sprite means an x relative to its container), yet the mask applied to the very same sprite, as another reference as reference for coordinates (like the stage)
    2. painting via script: in any other languaje, in any other situation, something like:
    beginFill(params);
    (...stuff 1)
    endFill();
    beginFill(params);
    (...stuff 2)
    endFill();
    (...etc)
    means: render region of block 1, then render region of block 2 etc, and no matter what, it should be consistent, since there is noplace for ambiguity. if you read it, you may think what that means, even if you dont run it you may have an idea of the picture you want to draw, but not with as3. as3 somehow manages to screw something that simple, and mixes all the blocks, and somehow uses the boundaries of one block as boundaries for other block. is like all blocks are dumped into whatever, and then uses all lines defined into it as boundaries for a unique block. it changes all boundaries and generates inconsistency between what is shown and redraw regions of the resulting picture, like lines that go to the end of the screen and then dont go away in the next frames, even tough the beginfill endfill block should prevent it
    3. event flow: i dont know what was the policy behind as3 event flow design. it is in no way similar or an extension to previous event flow, neither with any event flow in any other plattform. i dont know how most people start with as3; in my case, i unpacked, installed and when i tried to do something with what i already knew i could not, so i started reading the as3 docs, and since is like 800 pages long, i just read the basics and the rest i would 'wing it'. in the part of the event flow, there was something about bubbling and stuff, it was not clear at all and when i tried to do what is was said in the documentation (like preventing events to 'bubble', as is called in the documentation), i could not see any effect but i could see it was a mess. flash is not the only thing out there to work with pictures or to work with mouse events, but is the only one that deals with things like 'target' and 'currentTarget'. my first experience on needing this was when i was dealing with my own event handlers (so the only thing that had control over mouse was the stage, and i would admin everything via script). there were events generated everywhere, the stage got events that were not genrated directly over the stage, but got there not with stage coordinates but the coordinates relative to the sprite that generated the event. so if i hover the mopuse over the stage, and the stage has some things on it how does it work? i get multiple event calls, like it was hovering multiple times over the stage in a single frame, but in each call with different coordinates? and what if i set all child sprites as mouseenabled=false or compare like 'if (event.target != event.currenttarget)', what if i move the mouse over a child, does it prevent the move mouse event at all? or does it filter only the event call with only stage coordinates? in my case, every time i move over another clip (with mouseenabled = true), the stage gets it as 'mouse up', even tough there was never a mouse release, what the hell? do even the people at adobe know how to handle events with their own tool when they require it? why does an event 'bubble' when i have not specifically tell it to do it? mi thought is that this event flow was very poorly conceived, and tough the intention may have been that there were different cases and it shopuld cover all cases, they actually introduced new problems that were not present in traditional ways to handle it, and it is neither the easier way to handle things, and this way, a very simple problem turns into a very ugly thing because it must handle things that were not neccesary to handle, or were implicit in other situations.
    4. legacy: since as3, all interaction is different, and if you want to do things in the new plattform, using the new features, what you already knew just goes to the garbage can. when a new tool arrives, it should be an extension to previous tools (which is a reason to update instead of just buying a new tool from a different vendor). if everything i had or knew just means nothing from now on, then i can not say 'i know flash script', and my previous knowledge gives me no advantage when aproaching the new version. as3 is a new aproach that requires doc reading and stuff, even if you knew something about previous as specifications or other oo languajes. if you decide to change things from now on, like the things mentioned in this post, instead of just throwing away everything the users alerady knew about the tool, do like in java releases, they mark some things as 'deprecated', they keep working as they should, give a warning, but also a message saying this feature is deprecated, we suggest you use this library instead.
    5. lack of previous functionality: if you 'update' something, it meand all previos functionality is still there (probably improved, but not with bugs if it was working fine), plus something else. now it seems backwards, there are some things that could be done in previous versions but not in this one, like 'duplicatemovieclip'
    6. inconsistency with scripting/programming paradigms: (ok, fancy work, but fits perfectly here): as3 proposed ways to handle things, but the people who designed it got 'too creative', and they did something that is not consistent neither with previous versions of as or with other languajes. the documentations is full of things like 'it looks like x languaje or languaje family, but instead of using XXX word, you must use YYY'. great, what is this? namespaces 'work like', but 'differently' for example from java, .net, .c. its got the idea that a namespace means a grouped functionality but there are rules about where should be placed the file (ok, java has this also, .net takes care of it automatically if all files are registered in the project), but what you got is a mess that 'if you know other languajes you got the general idea, but nonetheless, even if you knew this or previosu versions of as, you still have to read whatever we decided arbitrarily just to be different'. namespaces, event handling, vars definition which is not like previous scripting neither like fully typed languajes.. is just a mess.
    7. lack of scripting and graphics integration: unlike flash and adobe tools that just got on the graphics side leaving all the scripting integratuion apart, most tools from other vendors integrate very well interacton with what is on the screen. the script editor: very poor. autocompletion? a drop down list that does not heklp at all, appears in the wrong places, and when you need it to go, it does not go (so if i want to move away from the uncalled drop down list, i have to click somewhere else, making developement slowewr instead of helping, so the drop down list does not capture all events when i dont want to). in other ides you double click somewhere and it will go to the part of code relevant to that event or whatever. for example microsoft tools, ok i am antimicrosoft, and one of the reasons was that when windows 95 got to market proposing itself as the ONLY pc os you could use if you wanted to keep useing the apps you already had, it was a lousy product full of flaws but you had to keep using it because you had no choice. what is so different from what is happening with flash just now? yet the ide of c# is awesome, works very well and seems reliable.
    adobe people: not all user are designers that just make pretty pictures. if it is not intended for scripting then why is it there. and if there are corrections to be done, they should patch all versions, not only the last one. previous version users also paid for their versions.

    Well, there is no point in arguing.
    I personally believe AS3 does exactly what it promises to do within limits (read: reasonable limits) of ECMA type of language. And sometimes it doesn’t do what we expect it to for it cannot possibly emulate everyone’s thinking process. The task, I guess, is to learn to think in terms of AS3 – not to try to make AS3 think like us. No language covers all the grounds. And no, it is not Java - with no negative or positive connotation. It is what it is. Period. I just hope that AS5 will be more Java like.
    You are right about the fact that it is not necessary to know all the aspects of language in order to perform the majority of tasks. But it is paramount to have a clear idea about such fundamental concepts as display list model and events. For instance, depth swap has no meaning in terms of AS3 because display list object stacking is controlled automatically and there is no need for all these jumping through hoops one has to perform in order to control depth in AS2. There no more gaps in depths and one always know where to find things.
    Similarly, there is no point in having duplicateMovieClip method. More conventional OOP ways of object instantiation accomplishes just that and much more. Just because OOP object instantiation needs to be learned doesn’t mean past hacks have place in modern times. duplicateMovieClip is a horse carriage standing next to SUV. What one should choose to travel?
    Events are implemented to the tee in the context of ECMA specifications. I consider Events model as very solid, it works great (exactly as expected) and never failed me. True, it takes time to get used to it. But what doesn’t?
    By the way, speaking about events, contrary to believe in Adobe’s inconsideration to their following. Events are implemented with weakly reference set to false although it would be better to have it set to true. I think this is because there are smart and considerate people out there who knew how difficult it would be for programming novices to deal with lost listeners.
    I think AS3 is million times better than AS2. And one of the reasons it came out this way is that Adobe made a very brave and wise decision to break totally loose from AS2’s inherent crap. They have created a totally new and very solid language. If they had tried to make it backward compatible – it would be a huge screw up, similar to how our friends at Microsoft are prostituting VB and VBA – extremely irritating approach IMHO.
    Also, Flash legacy issues shouldn’t be overlooked. Flash did not start as a platform for programmers. Entire timeline concept in many ways is not compatible with the best OOP practices and advancements. I think for anyone who is used to writing classes the very fact of coding on timeline sounds awkward. It feels like a hack (and AS2 IS a pile of hacks) – the same things can be nicely packaged into classes and scale indefinitely. As such I wouldn’t expect Adobe to waste time on hacking timeline concept issues by making smarter editor. They have made a new one – FlexBuilder – instead. Serious programmers realize very soon that Flash IDE is not for developing industrial strength applications anyway. So, why bother with channeling great minds into polishing path to the dead end?
    I would like to state that all this is coming form a person who knew Flash when there was no AS at all. And I applaud every new generation of this wonderful tool.
    I believe Adobe does a great job making transition from timeline paradigm to total OOP venue as smooth as possible. And no, they don’t leave their devoted followers behind contrary to many claims. They are working on making developing Flash applications as easy as possible for people of all walks. Welcome Catalyst!
    Of course there is not enough information about AS3 capabilities and features. But, on the other hand, I don’t know any area of human kind activities that does.

  • I need help figuring out what is wrong with my Macbook Pro

    I have a mid 2012 Macbook Pro with OS X Mavericks on it and for the past few weeks it has running VERY SLOW! I have no idea what is wrong with it, i have read other discussion forums trying to figure it out on my own. So far i have had no luck in fixing the slowness. When i open applications the icon will bounce in dock forever before opening and then my computer will freeze with the little rainbow wheel circling and circling for a few minutes... and if i try to browse websites it take forever for them to load or youtube will just stop working for me. Everything i do, no matter what i click, the rainbow wheel will pop up! The only thing i can think of messing it up was a friend of mine plugging in a flash drive a few weeks ago to take some videos and imovie to put on his Macbook Pro, he has said his laptop has been running fine though... so idk if that was the problem. Anyways, could someone please help me try something? Thank you!!

    OS X Mavericks: If your Mac runs slowly?
    http://support.apple.com/kb/PH13895
    Startup in Safe Mode
    http://support.apple.com/kb/PH14204
    Repair Disk
    Steps 1 through 7
    http://support.apple.com/kb/PH5836
    Reset SMC.     http://support.apple.com/kb/HT3964
    Choose the method for:
    "Resetting SMC on portables with a battery you should not remove on your own".
    Increase disk space.
    http://support.apple.com/kb/PH13806

  • What is Wrong with My html-el:reset Tag?

    In my JSP, I used <html-el:form ...>, <htim-el:checkbox ...>, <html-el:hidden ... >, <html-el:submit ... > without any problem.
    But, I got Error 500:(class: org/apache/strutsel?taglib/html/ELResetTag, method: release signature: ?V) Illegal use of nonvirtual method call
    when I used:
    <html-el:reset accesskey="C">Clear</html-el:reset>And the reset button does not get displayed when I
    <html-el:reset>Clear</html-el:reset>Would anybody point out what is wrong with the way I used the reset tag? Thank you.

    In my JSP, I used <html-el:form ...>, <htim-el:checkbox ...>, <html-el:hidden ... >, <html-el:submit ... > without any problem.
    But, I got Error 500:(class: org/apache/strutsel?taglib/html/ELResetTag, method: release signature: ?V) Illegal use of nonvirtual method call
    when I used:
    <html-el:reset accesskey="C">Clear</html-el:reset>And the reset button does not get displayed when I
    <html-el:reset>Clear</html-el:reset>Would anybody point out what is wrong with the way I used the reset tag? Thank you.

  • What is wrong with my Data Guard system?

    What is wrong with my Data Guard system(10g10.2.0 on OEL5.0)? What method should I take to diagnose it and repair it?
    After shutting down last night, my Data Guard does not run normally today.
    On the primary database I issue the following commands:
    DGMGRL> show configuration verbose;
    Configuration
    Name: sdb10g
    Enabled: YES
    Protection Mode: MaxAvailability
    Fast-Start Failover: ENABLED
    Databases:
    sdb10g - Primary database
    stdby10g - Physical standby database
    - Fast-Start Failover target
    Fast-Start Failover
    Threshold: 30 seconds
    Observer: hostp
    Current status for "sdb10g":
    Warning: ORA-16607: one or more databases have failed
    DGMGRL> show fast_start failover;
    show fast_start failover;
    Syntax error before or at "fast_start"
    SQL> startup
    ORACLE instance started.
    Database mounted.
    ORA-16649: database will open after Data Guard broker has evaluated Fast-Start
    Failover status
    On the physical standby database I issue the commands:
    SQL> startup mount
    ORACLE instance started.
    Database mounted.
    SQL> recover managed standby database disconnect;
    Media recovery complete.
    DGMGRL> show configuration verbose;
    Configuration
    Name: sdb10g
    Enabled: YES
    Protection Mode: MaxAvailability
    Fast-Start Failover: ENABLED
    Databases:
    sdb10g - Primary database
    stdby10g - Physical standby database
    - Fast-Start Failover target
    Fast-Start Failover
    Threshold: 30 seconds
    Observer: hostp
    Current status for "sdb10g":
    Warning: ORA-16607: one or more databases have failed
    DGMGRL> disable fast_start failover;
    Error: ORA-01034: ORACLE not available
    Failed.
    Message was edited by:
    frank.qian
    null
    null

    The primary database cannot be opened and the fast_start failover cannot be discabled:
    SQL> SQL> ALTER DATABASE open
    ERROR at line 1:
    ORA-16649: database will open after Data Guard broker has evaluated Fast-Start
    Failover status
    DGMGRL> disable fast_start failover;
    Error: ORA-01034: ORACLE not available

  • What's wrong with my code? compliation error

    There is a compilation error in my program
    but i follow others sample prog. to do, but i can't do it
    Please help me, thanks!!!
    private int selectedRow, selectedCol;
    final JTable table = new JTable(new MyTableModel());
    public temp() {     
    super(new GridLayout(1, 0));                         
    table.setPreferredScrollableViewportSize(new Dimension(600, 200));     
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);     
    ListSelectionModel rowSM = table.getSelectionModel();
    rowSM.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
         //Ignore extra messages.
    if (e.getValueIsAdjusting()) return;
    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
    if (lsm.isSelectionEmpty()) {
         System.out.println("No rows are selected.");
    else {
         selectedRow = lsm.getMinSelectionIndex();
    System.out.println("Row " + selectedRow+ " is now selected.");
    JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane);
    createPopupMenu();
    public void createPopupMenu() {       
    //Create the popup menu.
    JPopupMenu popup = new JPopupMenu();
    // display item
    JMenuItem menuItem = new JMenuItem("Delete selected");
    popup.add(menuItem);
    menuItem.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
              System.out.println("Display selected.");
              System.out.println("ClientID: "+table.getValueAt(selectedRow,0));
              int index = table.getSelectedColumn();
              table.removeRow(index);     <-------------------------------compliation error     
         }}); //what's wrong with my code? can anyone tell
    //me what careless mistake i made?
    MouseListener popupListener = new PopupListener(popup);
    table.addMouseListener(popupListener);
    public class MyTableModel extends AbstractTableModel {
    private String[] columnNames = { "ClientID", "Name", "Administrator" };
    private Vector data = new Vector();
    class Row{
         public Row(String c, String n, String a){
              clientid = c;
              name = n;
              admin = a;
         private String clientid;
         private String name;
         private String admin;
    public MyTableModel(){}
    public void removeRow(int r) {    
         data.removeElementAt(r);
         fireTableChanged(null);
    public int getColumnCount() {
    return columnNames.length;
    public int getRowCount() {
    return data.size();
    public String getColumnName(int col) {
    return columnNames[col];
    public Object getValueAt(int row, int col) {
         return "";
    public boolean isCellEditable(int row, int col) {   
    return false;
    public void setValueAt(Object value, int row, int col) {}
    }

    Inside your table model you use a Vector to hold your data. Create a method on your table model
    public void removeRow(int rowIndex)
        data.remove(rowIndex); // Remove the row from the vector
        fireTableRowDeleted(rowIndex, rowIndex); // Inform the table that the rwo has gone
    [/data]
    In the class that from which you wish to call the above you will need to add a reference to your table model.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • New to the itunes game....help!

    I just bought a new computer and would like to put my existing itunes library on my new computer. How do I do it ?

  • TCP Open and Close using NI TCP VI's

    Do I need to close the TCP connections on both ends.  For example, I have a "server" that Listens and then a client that opens the TCP connection.  Do I have to close the TCP connections on both ends.  I'm closing it at the client side but is it also

  • [Solved]Bash: get positional parameter '$num'

    I can't figure out how to do it without using eval: eval param='$'{$num} I'm pretty sure it's safe, because num will either be $# or the result of $(( $# - 1 )). But it seems like there should be a non-hackish way to do this. XYZ: I use diff a lot to

  • Photosmart 3210 only prints black and white??

    Hi everyone, I have an HP Photosmart 3210 that I just installed the lastest HP drivers onto my up to date macbook. Once finishing the install and completing the setup, I can only print in black and white / grey scale. Is this driver issue? Has anyone

  • Line-size 220

    hi   if i will use LINE-SIZE 220 in my report , will i be able to get print out on A4 landscape , of this out put.