ArrayList - clear() or new ArrayList() ?

Hi everybody,
I have a loop which runs ~100-100000 times and in each looping an ArrayList is filled and holds elements ranging from 1 to 30000. I'm reusing the list and I'm wondering whether I should use clear() or better reinstantiate the List.
I know that with StringBuffer the setLength(0) does not decrease the capacity of the StringBuffer, so that it might take much more memory than it actually needs.
How about List?
Does clear() decrease the capacity of the List?
Would a reinstantiation be the better way?
Or doesn't it matter anyway and a list with too much capacity is fine to use?
Hope you can help
Cheers
bgcl

Hi everybody,
I have a loop which runs ~100-100000 times and in each
looping an ArrayList is filled and holds elements
ranging from 1 to 30000. I'm reusing the list and I'm
wondering whether I should use clear() or better
reinstantiate the List.
I know that with StringBuffer the setLength(0) does
not decrease the capacity of the StringBuffer, so that
it might take much more memory than it actually
needs.
How about List?
Does clear() decrease the capacity of the List?
Would a reinstantiation be the better way?
Or doesn't it matter anyway and a list with too much
capacity is fine to use?
Hope you can help
Cheers
bgclclear() will be better than new ArrayList() but the performance difference of clear() and new ArrayList(int) (with an int of an appropriate size) will be negligable.

Similar Messages

  • Ios7 - is there a way to shut off or clear the new photo stream activity?

    Ios7 - is there a way to shut off or clear the new photo stream activity?  I am not asking how to shut off photo streams, just would like to clear or shut off the new 'social' activity portion of photo stream

    Thank you, but that is not it, and I am talking about the iCloud photo streams.  I know how to modify who can see or post to a shared stream, that's extremely easy. 
    What is an issue is the new 'social' style activity that summarizes all of the shared streams.  It now posts/summarizes them in an activity thread in 'streams', called "Activity"
    I would like to shut that off or be able to clear that view.  While I enjoy the occasionally funny pics I receive from old college friends in shared streams, I don't want that to show up in a 'cover photo' when I go to pull up pics in front of someone.

  • Difference between list.clear() and new instance

    In the below code,
    List<String> test = new ArrayList<String)();
    list.add("one");
    list.add("two");
    list.add("three");
    list.clear();
    (or)
    list = new ArrayList<String)();
    list.add("four");
    list.add("five");
    What is the difference between List.clear() and creating new instance for list?

    1. Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    2. Invoking clear() sets all the elements of the ArrayList to null and resets the size to 0.    public void clear() {
         modCount++;
         // Let gc do its work
         for (int i = 0; i < size; i++)
             elementData[i] = null;
         size = 0;
        }(modCount is used to detect concurrent modification and throw an Exception when needed)
    Constructing a new ArrayList creates a new, different, empty ArrayList.
    In many situations they might be equivalent, but not in a case where you have two or more variable references to the same ArrayList. Example (watch out for typos)ArrayList<String> stringsA = new ArrayList<String>();
    ArrayList<String> stringsB = stringsA;
    : // add elements to stringsA
    : // stringsB refers to the same populated list
    stringsA.clear(); // stringsB refers to the clear()ed list
    : // add elements to stringsA again
    stringsA = new ArrayList<String>(); // stringsB still refers to the populated listdb

  • I set up new phone (5) as a "new phone instead of backing up from icloud. How can I get back in to use the icloud backup? If I hit "delete account" does that just clear the new phone or does it get rid of my whole icloud account.

    In the set-up process I clicked "set up as new phone" when I should have clicked "back up from icloud". I can't use itunes for the back up as it is not current. Is there a way to get back into setup? If I click "delete accout" in icloud management will it clear just my phone (so I can start over) or will it actually delete my icloud?

    Settings>General, scroll to bottom of screen and tap Reset, choose to delete all data.  Then attach to itunes and choose to perform a restore.  You'll get the option to restore from icloud.

  • ApEx Development Team: tab clear cache - new feature?

    Hi ApEx Development Team!
    I searched the forum and found, that many have (had) the same problem like me:
    Why isn't it possible to clear the cache by clicking on a tab? Why is it only possible for parent tabs?
    Wouldn't it be a nice feature for the next version of ApEx? This feature exists already, only not for the standard tabs...
    Regards,
    Sofie

    taepodong wrote:
    Apologies to dig up old thread but I ran into this problem and thought I'd share my solution as well (for search engine)There is no point in doing this. There are thousands of threads in this forum that are unanswered, or contain solutions that are suboptimal or that have been superseded. They can't all be updated "for search engine"...
    1) Edit the tab property where you want your page's cached removed. In My case it I had a tab pointing to page 6 and I needed page 6's cache cleared when I clicked on it.
    2) Edit the condition for the tab deisplay --> Function returning boolean.
    3) In the function body put the following code:
    begin
    if :APP_PAGE_ID != 6 THEN
    apex_application.clear_page_cache(6);
    END IF;
    RETURN TRUE;
    end; The expression will always evaluate to true, and will clear cache from page 6 if clicked from any other page that is not page 6.
    However if you want to apply condition to the page as well. (say and admin page based on :APP_USER property) then wrap the return true in another If-statement as well.I subscribe to the old-school idea that state-changing side-effects in functions are evil. Using Condition code in this unexpected way will make an application much harder to debug and maintain. If I came across this in an application I was working on I'd refactor it.
    Scott posted the correct way to do this above (post of 26-Mar-2008 23:00&mdash;not marked as helpful/correct as this was before the forum had this feature): Clear cache using an On-Submit Application Process that is conditional on the <tt>:REQUEST</tt> value set by the relevant tab(s).

  • Fonts are not clear in New FF 4

    I am talking about the language "Sinhala"
    Previous FF version had good Sinhala Unicode built within
    [http://example.com http://i55.tinypic.com/a4nb4l.jpg]
    But in FF4 this is how it looks like
    [http://example.com http://i51.tinypic.com/2llem4w.jpg]

    The Ctrl+E shortcut has been removed in Firefox 4, you can get it back by using the Change Search Shortcut add-on - https://addons.mozilla.org/firefox/addon/change-search-shortcut/

  • HT1339 switching ipod to new user, clearing memory, new data

    I have an my moms ipod nano that she doesn't use anymore.  I need to erase it and load all my itunes on it...NOW as I leave for a marathon tomorrow morning and my ipod just died.  how can I do this???  HELP!!!

    Read the user manual for your model iPod Nano - iPod Manuals
    iPod Models

  • ArrayList help

    ok still having trouble, i redid alot of the program, i need to slim down the ArrayList to being one instance of a word per file, plus all of the lines they are on inside that one instance. Right now there are mulitple instances of each word and each one has its own line its on. I have tried for the past 3 hours trying to get this to work, anything from finding a way to sort it then compair first and last index's to moving them to arrays and manually doing it. I just cant figure this out any help would be great!
    just for refrance the arguement taken is a text file that lists other text files which have plain text in them
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    class FileParser
         static ArrayList files = new ArrayList();
         JFrame frame = new JFrame("Search Engine v1.0");
         JTextField text = new JTextField(20);
         JTextArea display = new JTextArea(20,20);
         int xPosition;
         int yPosition;
         static int testCounter = 0;
         FileObj fo;
         //ArrayList <Word>finalWord = new ArrayList<Word>();
         public static void main(String[] args)
              FileParser fp = new FileParser(args[0]);
              fp.GUI(); disabling GUI for now
         public FileParser(String s)
              String option = "";
              try
                   BufferedReader br = new BufferedReader(new FileReader(s));
                   String inLine = br.readLine();
                   while(inLine != null)
                        FileObj fo = new FileObj(inLine);
                        fo.processFile();
                        files.add(fo);
                        inLine = br.readLine();
                        System.out.println("test");
                   br.close();//the arraylist files now has each file name that containes words
                   System.out.println(files);
              catch(IOException e){}
         public void GUI()
              Container con;
              JLabel l1;
              JPanel top, middle, bottom;
              con = frame.getContentPane();
              con.setLayout(new BorderLayout());
              top = new JPanel(new GridLayout(1,3));
              middle = new JPanel(new GridLayout(2,1));
              bottom = new JPanel(new GridLayout(1,3));
              top.add(new JLabel("Search for:"));
              top.add(text);
              middle.add(new JLabel("Results: "));
              middle.add(new JScrollPane(display));
              JButton search = new JButton("Search");
              search.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
                   //System.out.println(text.getText());
                   FileObj.list(text.getText());
              JButton clear = new JButton("Clear");
              clear.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
                   text.setText("");
                   display.setText("");
              JButton exit = new JButton("Exit");
              exit.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
                   System.exit(0);
              bottom.add(search);
              bottom.add(clear);
              bottom.add(exit);
              con.add(top, BorderLayout.NORTH);
              con.add(middle, BorderLayout.CENTER);
              con.add(bottom, BorderLayout.SOUTH);
              frame.setSize(400, 250);
              frame.setVisible(true);
    import java.util.*;
    import java.io.*;
    class FileObj
         String fileName;
         int wordCount;
         int uniqueWords;
         int lineCount;
         ArrayList <Word>words = new ArrayList<Word>();
         Boolean first = true;
         FileObj(String theFiles)
              fileName = theFiles;//individual file name
              System.out.println(fileName);
         public void processFile()
              FileReader infile = null;//helps load files text for reading
              StreamTokenizer reader = null;//helps tokenizes the files text
              int testCounter = 0;
              try
                   infile = new FileReader(fileName);//finishes loading files text
                   reader = new StreamTokenizer(infile);//finishes tokenizing files text
                   reader.wordChars(65, 122);//tells it to only take letters
                   reader.nextToken();
                   while (reader.ttype != reader.TT_EOF)// while the end of the stream hasnt been reached
                        if (reader.ttype == reader.TT_WORD)//if the stream has read a token
                             String token = reader.sval;//creates a string with the token in it
                             wordCount++;
                             token = stripWord(token);//strips token of non letters
                             processWord(token, reader.lineno(), fileName);
                        reader.nextToken();
                        lineCount = reader.lineno();// gets me the line number
                   exists();
                   testCounter = words.size();
                   for(int i = 0; i<testCounter;i++)
                        System.out.println(words.get(i));
                   infile.close();
                   //try to print out a search
              catch(FileNotFoundException e){}
              catch(IOException e){}
         public String toString()
              return ("FileName: "+fileName+" WordCount: "+wordCount+" UniqueWords:"+uniqueWords+" LineCount: "+lineCount);
         public String stripWord(String w)
              w = w.replace('.',' ');
         w = w.replace(',',' ');
         w = w.replace('?',' ');
         w = w.replace(':',' ');
         return w.trim().toUpperCase();
         public void processWord(String s, int line, String f)
              Word wordObj = new Word(s, line, f);
              words.add(wordObj);
              (words);
            public void exists()// this is only to find if the word exists
              int arrayCounter= 0;
              //words
         }     public static String list(String w)
              System.out.println("do i see this?");
              return w;
    /* Word wordObj = finalWord.get(w.toUpperCase());
    if (wordObj != null)
    System.out.println(w + " found in " + fileName + " at lines " + wordObj.lineNumbers.toString());
    import java.util.*;
    class Word
         String value;
         String fileName;
         int count;
         ArrayList lineNumbers;
         public Word(Word wordCopy)
              value = wordCopy.value;
              fileName = wordCopy.fileName;
              count = wordCopy.count;
              lineNumbers = wordCopy.lineNumbers;
         public Word(String v, int l, String f)
              value =v;
              fileName = f;
              lineNumbers = new ArrayList();
              lineNumbers.add(new Integer(l));
              count++;
              //System.out.println("god i hope i see the unique words, this is one: "+value+" "+lineNumbers);
         public Word(String v)
              value = v;
         public void update(int l)
              lineNumbers.add(new Integer(l));
              count++;
         public String toString()
              return "FileName:"+fileName+" Word:"+value+" Lines found in: "+lineNumbers;
         public String getWord()
              return value;
         public int getEverything()
              int size = count;
              return size;
         public boolean compairTo(String s1)
              if(value.equals(s1))
                   return true;
              else
                   return false;
    }

    ok i put it all inside code brackets, i was told you only the part i was having trouble with. But i explained what the program does and im just trying to get the ArrayList which is filled with my Word objects to become sorted kind of. Right now it will have multiple instances of exact words, but they will be on diffrent lines, i need to shorten it down and put the lineNumbers all into the same word object if they are the same String value.import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    class FileParser
    static ArrayList files = new ArrayList();
    JFrame frame = new JFrame("Search Engine v1.0");
    JTextField text = new JTextField(20);
    JTextArea display = new JTextArea(20,20);
    int xPosition;
    int yPosition;
    static int testCounter = 0;
    FileObj fo;
    //ArrayList <Word>finalWord = new ArrayList<Word>();
    public static void main(String[] args)
    FileParser fp = new FileParser(args[0]);
    fp.GUI(); disabling GUI for now
    public FileParser(String s)
    String option = "";
    try
    BufferedReader br = new BufferedReader(new FileReader(s));
    String inLine = br.readLine();
    while(inLine != null)
    FileObj fo = new FileObj(inLine);
    fo.processFile();
    files.add(fo);
    inLine = br.readLine();
    System.out.println("test");
    br.close();//the arraylist files now has each file name that containes words
    System.out.println(files);
    catch(IOException e){}
    public void GUI()
    Container con;
    JLabel l1;
    JPanel top, middle, bottom;
    con = frame.getContentPane();
    con.setLayout(new BorderLayout());
    top = new JPanel(new GridLayout(1,3));
    middle = new JPanel(new GridLayout(2,1));
    bottom = new JPanel(new GridLayout(1,3));
    top.add(new JLabel("Search for:"));
    top.add(text);
    middle.add(new JLabel("Results: "));
    middle.add(new JScrollPane(display));
    JButton search = new JButton("Search");
    search.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    //System.out.println(text.getText());
    FileObj.list(text.getText());
    JButton clear = new JButton("Clear");
    clear.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    text.setText("");
    display.setText("");
    JButton exit = new JButton("Exit");
    exit.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    System.exit(0);
    bottom.add(search);
    bottom.add(clear);
    bottom.add(exit);
    con.add(top, BorderLayout.NORTH);
    con.add(middle, BorderLayout.CENTER);
    con.add(bottom, BorderLayout.SOUTH);
    frame.setSize(400, 250);
    frame.setVisible(true);
    import java.util.*;
    import java.io.*;
    class FileObj
    String fileName;
    int wordCount;
    int uniqueWords;
    int lineCount;
    ArrayList <Word>words = new ArrayList<Word>();
    Boolean first = true;
    FileObj(String theFiles)
    fileName = theFiles;//individual file name
    System.out.println(fileName);
    public void processFile()
    FileReader infile = null;//helps load files text for reading
    StreamTokenizer reader = null;//helps tokenizes the files text
    int testCounter = 0;
    try
    infile = new FileReader(fileName);//finishes loading files text
    reader = new StreamTokenizer(infile);//finishes tokenizing files text
    reader.wordChars(65, 122);//tells it to only take letters
    reader.nextToken();
    while (reader.ttype != reader.TT_EOF)// while the end of the stream hasnt been reached
    if (reader.ttype == reader.TT_WORD)//if the stream has read a token
    String token = reader.sval;//creates a string with the token in it
    wordCount++;
    token = stripWord(token);//strips token of non letters
    processWord(token, reader.lineno(), fileName);
    reader.nextToken();
    lineCount = reader.lineno();// gets me the line number
    exists();
    testCounter = words.size();
    for(int i = 0; i<testCounter;i++)
    System.out.println(words.get(i));
    infile.close();
    //try to print out a search
    catch(FileNotFoundException e){}
    catch(IOException e){}
    public String toString()
    return ("FileName: "+fileName+" WordCount: "+wordCount+" UniqueWords:"+uniqueWords+" LineCount: "+lineCount);
    public String stripWord(String w)
    w = w.replace('.',' ');
    w = w.replace(',',' ');
    w = w.replace('?',' ');
    w = w.replace(':',' ');
    return w.trim().toUpperCase();
    public void processWord(String s, int line, String f)
    Word wordObj = new Word(s, line, f);
    words.add(wordObj);
    (words);
         public void exists()// this is only to find if the word exists
              int arrayCounter= 0;
              //words
    public static String list(String w)
    System.out.println("do i see this?");
    return w;
    /* Word wordObj = finalWord.get(w.toUpperCase());
    if (wordObj != null)
    System.out.println(w + " found in " + fileName + " at lines " + wordObj.lineNumbers.toString());
    import java.util.*;
    class Word
    String value;
    String fileName;
    int count;
    ArrayList lineNumbers;
    public Word(Word wordCopy)
    value = wordCopy.value;
    fileName = wordCopy.fileName;
    count = wordCopy.count;
    lineNumbers = wordCopy.lineNumbers;
    public Word(String v, int l, String f)
    value =v;
    fileName = f;
    lineNumbers = new ArrayList();
    lineNumbers.add(new Integer(l));
    count++;
    //System.out.println("god i hope i see the unique words, this is one: "+value+" "+lineNumbers);
    public Word(String v)
    value = v;
    public void update(int l)
    lineNumbers.add(new Integer(l));
    count++;
    public String toString()
    return "FileName:"+fileName+" Word:"+value+" Lines found in: "+lineNumbers;
    public String getWord()
    return value;
    public int getEverything()
    int size = count;
    return size;
    public boolean compairTo(String s1)
    if(value.equals(s1))
    return true;
    else
    return false;

  • Having to open, close, open again to get the new message notifications to clear and be read, or go away.

    sometimes while having message app open from person after a new message is received I have to back out to list of messages and go back into the conversation to clear the new message notifications. Or once I receive a message on the lock screen I then go to read the message then back out to list of names i message and it will still show I have not read the new message(s). This never happened until IOS 8 came out

    Mine is doing the same thing. Anyone?
    I have a 5S, iOS 8.0.2

  • Moving methods to a new class

    I have a class with my GUI and methods, but i want to move my methods to their own class.
    import java.awt.Container;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.awt.*;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    import javax.swing.*;
    public class Login extends JDialog implements ActionListener
    ArrayList personsList;
    PersonDAO pDAO;
    JLabel userName, passWord;
    JTextField userName1;
    JPasswordField passWord1;
    JButton jbnClear, jbnSubmit, jbnCancel;
    String userName2, passWord2;
    Container cPane;
    public Login(JFrame father) {
    super(father);
    createGUI();
    userName2  = "";
    passWord2   = "";
    personsList = new ArrayList();
    pDAO = new PersonDAO();     
    public void createGUI(){
    cPane = getContentPane();
    setLayout(new GridBagLayout());
    //Arrange components on contentPane and set Action Listeners to each JButton
    arrangeComponents();
    setSize(210,170);
    setTitle("Login");
    setResizable(false);
    setVisible(true);
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    public void arrangeComponents(){
    userName = new JLabel("Username");
    passWord = new JLabel("Password");
    userName1   = new JTextField(20);
    passWord1   = new JPasswordField(20);
    jbnClear  = new JButton("Clear");
    jbnSubmit = new JButton("Submit");
    jbnCancel = new JButton("Cancel");
    GridBagConstraints gridBagConstraintsx01 = new GridBagConstraints();
    gridBagConstraintsx01.gridx = 0;
    gridBagConstraintsx01.gridy = 0;
    gridBagConstraintsx01.insets = new Insets(5,5,5,5);
    cPane.add(userName, gridBagConstraintsx01);
    GridBagConstraints gridBagConstraintsx02 = new GridBagConstraints();
    gridBagConstraintsx02.gridx = 1;
    gridBagConstraintsx02.insets = new Insets(5,5,5,5);
    gridBagConstraintsx02.gridy = 0;
    gridBagConstraintsx02.gridwidth = 2;
    gridBagConstraintsx02.fill = GridBagConstraints.BOTH;
    cPane.add(userName1, gridBagConstraintsx02);
    GridBagConstraints gridBagConstraintsx03 = new GridBagConstraints();
    gridBagConstraintsx03.gridx = 0;
    gridBagConstraintsx03.insets = new Insets(5,5,5,5);
    gridBagConstraintsx03.gridy = 1;
    cPane.add(passWord, gridBagConstraintsx03);
    GridBagConstraints gridBagConstraintsx04 = new GridBagConstraints();
    gridBagConstraintsx04.gridx = 1;
    gridBagConstraintsx04.insets = new Insets(5,5,5,5);
    gridBagConstraintsx04.gridy = 1;
    gridBagConstraintsx04.gridwidth = 2;
    gridBagConstraintsx04.fill = GridBagConstraints.BOTH;
    cPane.add(passWord1, gridBagConstraintsx04);
    GridBagConstraints gridBagConstraintsx09 = new GridBagConstraints();
    gridBagConstraintsx09.gridx = 0;
    gridBagConstraintsx09.gridy = 4;
    gridBagConstraintsx09.insets = new Insets(5,5,5,5);
    cPane.add(jbnClear, gridBagConstraintsx09);
    GridBagConstraints gridBagConstraintsx10 = new GridBagConstraints();
    gridBagConstraintsx10.gridx = 1;
    gridBagConstraintsx10.gridy = 4;
    gridBagConstraintsx10.insets = new Insets(5,5,5,5);
    cPane.add(jbnSubmit, gridBagConstraintsx10);
    GridBagConstraints gridBagConstraintsx11 = new GridBagConstraints();
    gridBagConstraintsx11.gridx = 1;
    gridBagConstraintsx11.gridy = 5;
    gridBagConstraintsx11.insets = new Insets(5,5,5,5);
    cPane.add(jbnCancel, gridBagConstraintsx11);
    jbnClear.addActionListener(this);
    jbnSubmit.addActionListener(this);
    jbnCancel.addActionListener(this);
    public void actionPerformed (ActionEvent e){
    if (e.getSource() == jbnClear){
    clear();
    else if (e.getSource() == jbnSubmit){               
    //Submit();
    else if (e.getSource() == jbnCancel){               
    cancel();
    String getUsername() {
    return userName1.getText();
    String getPassword() {
    return new String(passWord1.getPassword());
    public void clear(){
    userName1.setText("");
    passWord1.setText("");
    personsList.clear();
    public void cancel(){
    this.dispose();
    public void Submit(){
    userName2 = getUsername();
    passWord2 = getPassword();
    PersonInfo person = new PersonInfo(userName2, passWord2);
    if(userName2.equals("") || passWord2.equals("")){
    JOptionPane.showMessageDialog(null, "Please complete all fields.");
    else
    pDAO.loginPerson(person);
    }If i do move them to their own class, in the submit method, i need to get the username. If i try
    userName2 = Login.getUsername();I am told i non static method getUsername() cannot be referenced from a static context. How can i overcome this?

    nick2price wrote:
    well, DrLaszloJamf, thats answered it straight away. I always thought that to get an instance of another class, i had to do somthing like
    Login log = new Login();But it can be done just like
    private Login logI think i now understand, the top example creates a new instance of the class and passes it what is in the constructor, which would be good to use if i wanted to run the class through an event or somthing. And the second example just creates a simple instance of the class.No, that is wrong. The second line defines an instance field named log. Unless you initialize it elsewhere, this line leaves the variable with the value null. No constructor is called because of that line.
    Suggestion: you have to learn to crawl before you can learn to walk. You don't even know the fundamentals of Java -- what static means, what it means to define a field. You shouldn't be touching Swing for at least another year. You need to learn the basics, first.

  • Clearing a frame for redrawing

    I have a frame that I have been drawing on to play tic tac toe.
    I want to be able to clear the frame to redraw a new board for a second game.
    How can I clear the frame to redraw a new board?
    I have it were it draws on the frame perfectly, but what would erase some of my prior drawing.
    It is easy to redraw the board, but I need a clean frame to do this on.
    How would I do this?
    Thanks for any help.

    Erase by repainting with nothing to repaint:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import java.util.List;
    public class Points extends JPanel {
        private List pts = new ArrayList();
        public void addPoint(Point pt) {
            pts.add(new Point(pt));
            repaint();
        public void clearPoints() {
            pts.clear();
            repaint();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets(); //border insets
            int w = getWidth() - insets.left - insets.right;
            int h = getHeight()- insets.top - insets.bottom;
            Graphics2D g2 = (Graphics2D) g.create(insets.left, insets.top, w, h);
            try {
                paintInsideBorder(g2, w, h);
            } finally {
                g2.dispose();
        protected void paintInsideBorder(Graphics2D g2, int w, int h) {
            for(int i=0, ub=pts.size(); i<ub; ++i) {
                Point pt = (Point) pts.get(i);
                g2.drawRect(pt.x-4, pt.y-4, 8, 8);
        public static void main(String[] args) {
            final Points app = new Points();
            app.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent evt) {
                    app.addPoint(evt.getPoint());
            JButton clear = new JButton("clear");
            clear.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent evt) {
                    app.clearPoints();
            JPanel south = new JPanel();
            south.add(clear);
            JFrame f = new JFrame("Click on client area...");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Container cp = f.getContentPane();
            cp.add(app, BorderLayout.CENTER);
            cp.add(south, BorderLayout.SOUTH);
            f.setSize(400,300);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • NEW CELL and NEW LINE

    Hi,
    I am not clear about NEW CELL and NEW LINE in The Main window -> Table -> Footer -> Output options -> Output Table.  Could any one help in explaining exactly what is the purpose of it.
    Thanks
    Ram

    when you are placing a text element, you need to specify whether you want this text element to be displayed in the next cell of the table. If the text element is to be displayed in the next line then you will have to check that as well. So, if you are displaying a list of fields in a row format then for the first field, you check both line and cell and for the rest of the fields you check just the cell.
    Regards,
    Ravi
    Note - Please mark all the helpful answers

  • How to Clear Cache for all Items of the Current Page of a TAB

    Hi,
    I am having a TAB, when that tab is clicked..it goes to suppose Page 1, what I want to Clear the Cache of Page 1 ...as soon as Page appears...
    I don't see any option for that in the TAB Definition Properties....
    Thanks,
    Deepak

    I got the solution....
    refer by SCOTT...
    Re: ApEx Development Team: tab clear cache - new feature?
    thanks,
    Deepak

  • How can I convert my animation into a working movie clip that can be used with a new scene?

    Hello all,
    First and foremost, I AM A TOTAL FLASH NOOB. I want to preface this and make it incredibly clear how new this all is to me. I LITERALLY started using flash this morning; that is precisely how new I am.
    With that being said I am going to do my best to explain what I'd like to do.
    I have created an animation of a spider moving its legs back and forth. I want to be able to combine all of the layers into 1 simple animation that can be imported into new flash scenes with the animation exactly how it stands. I have figured out how to convert the whole animation into a symbol AND I have figured out how to import the movie clip from the library. However, herein lies my problem. When I open a new flash scene and import my animation, I play it and it does nothing at all. It's just the static image of the spider I created with no movement.
    I've spent the last couple hours trying to figure out (and doing my own research) what I have done or didn't do to get to this point. I'd be willing to bet I am just going about the entire process incorrectly and I'm simple overlooking a basic facet of the program.
    Any insight to fix my ignorance is greatly appreciated.
    (P.S. Hell, I don't even know if I am using the correct terminology so for all I know I am confusing every person who has taken the time to look at my question. If I am using incorrect terminology please correct me to avoid future hang ups. Thank you.)

    Ned! This totally worked! Thank you! I knew there was a tiny piece of this whole thing that was preventing me from making everything work. Unfortunately as my luck would have it, although I have the movieclip working the spritesheet converter I'm using now no longer recognizes the movie clip. The converter says there are 7 frames in the animation, but doesn't display any working sprites. Just a blank sheet. Frustrating to say the least.
    I'm just going to throw everything out on the table here:
    This is the video tutorial i'm using to convert my animation into a spritesheet. I've done the steps exactly as directly up until the point I actually click "Begin Conversion." When begin conversion is selected, it shows the movieclip exists on the bottom left underneath "list of movieclips" but doesn't actually show any individual sprites.
    Here's the simple sprite converter I am using.
    The irony of this whole situation is that you have successfully helped me make a working movieclip (which was the important piece), but the converter no longer recognizes it. Whereas before, it would at least show the image on the 1 frame of animation it had.
    If you wanted to to take a stab at it and see if you can successfully get it to work I'd be appreciative. If not, I totally understand as you have already been incredibly helpful and have my eternal gratitude for getting me this far. These animation programs can be quite overwhelming when they so vastly differ from one another. Don't even get me started no Anime' Studio Pro.

  • While Opening a New Window all Tool Bars and Bookmark Bar Dissapearing

    Dear Mozilla Team,
    I loved the new Firefox 4 it is fast and more space for webpages and many other a lot of good stuff. Congrats and thank you for the hard work. However something weird happening every time I opened a second new window .
    I will try to explain and be clear;
    File --> New Window;
    In the new window;
    - The biggest problem is it seems like there are two Microsoft Windows window within each other. There are two minimize, fullscreen and close icons at the top right corner.
    - Some of the google toolbar icons lost
    - My boomarks toolbar lost
    - My homepage is not loading and there is not attempt to load.
    This is happening every time I try to open 2 new window.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    * https://support.mozilla.com/kb/Safe+Mode
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")
    In Firefox 4 you can use one of these to start in <u>[[Safe mode]]</u>:
    * Help > Restart with Add-ons Disabled
    * Hold down the Shift key while double clicking the Firefox desktop shortcut (Windows)
    * [[Troubleshooting extensions and themes]]

Maybe you are looking for