Need help with Threading GUI progress bar

Anyone able to help? I'm sure you've seen this a million times. I've google'd around and tried examples but still can't get a progress bar to work properly under the following situation:
1. Created a panel with several components to select directory, display directory in tree etc.
2. When a specific button (Search) is clicked, I want a secondary window to popup and report progress of searching down the directory.
As you'll probably guess, the progress window isn't being updated until the end. I'm using Threads and using InvokeLater but nothing happens. Is there any good example that does the above? I can't seem to find one to figure this out.
Thanks
Speedy.
Sample code:
main.java:
========
public class Main {
public static void main(String[] args) {
MainPanel mainPanel = new MainPanel();
mainPanel.show();
MainPanel.java:
============
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class MainPanel extends JFrame implements ActionListener {
public MainPanel() {
this.setSize(100,100);
JButton startButton = new JButton("Start");
this.getContentPane().add(startButton);
startButton.addActionListener(this);
public void actionPerformed(ActionEvent event) {
ProgressPanel pp = new ProgressPanel();
pp.show();
SimpleTask st = new SimpleTask(pp);
st.start();
while (st.isAlive()) {
System.err.println("waiting..");
try {
Thread.sleep(100);
} catch (Exception e) {};
System.err.println("finished!");
SimpleTask.java:
=============
import javax.swing.SwingUtilities;
public class SimpleTask extends Thread {
ProgressPanel pp = null;
public SimpleTask(ProgressPanel _pp) {
pp = _pp;
this.setDaemon(true);
int i = 0;
String position = "";
public void run() {
Runnable updateGUI = new Runnable() {
public void run() {
pp.setText(position);
try {
for (i=0; i<50; i++) {
position = "Now on = " + new Integer(i).toString();
System.err.println(position);
SwingUtilities.invokeLater(updateGUI);
sleep(100);
} catch (Exception e) {}
ProgressPanel.java:
===============
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ProgressPanel extends JFrame {
private JLabel label = new JLabel();
public ProgressPanel() {
this.setSize(200,200);
this.setLocation(100,100);
this.getContentPane().add(label);
setText("Start");
public void setText(String text) {
label.setText(text);
}

Ok, I'll look down that road. I should have said the Thread is being used because the current while loop will be changed to perform real work. Just an example at the moment to show what I'm trying to do. Does this make a difference? The real task will be to drill down directories, counting file types/dirs etc...

Similar Messages

  • Need help with threading in Swing GUI !!!

    I've written an app that parses and writes
    files. I'm using a Swing GUI. The app
    could potenially be used to parse hundreds or even
    thousands of files. I've included a JProgressBar
    to monitor progress. The problem is when I parse
    a large number of files the GUI freezes and only
    updates the values of the progress bar when the
    parsing and writing process is finished.
    I assume I need to start the process in a seperate thread. But, I'm new to threads and I'm not sure
    whether to start the Progressbar code in a seperate
    thread or the parsing code. As a matter of fact I really
    don't have any idea how to go about this.
    I read that Swing requires repaints be done in the
    event dispatch thread. If I start the parsing in a seperate
    thread how do I update the progressbar from the other
    thread? I'm a thread neophyte.
    I need a cigarette.

    In other words do this:
    Inside event Thread:
    handle button action
    start thread
    return from action listener
    Inside worker Thread:
    lock interface
    loop
    perform action
    update progress bar
    unlock interface
    return from worker ThreadDoesn't updating the progress bar (and locking/unlocking the interface components) from within the worker thread violate the rule that you shouldn't mess with Swing components outside the event thread? (Do I have that rule right?)
    In any case, is there any way to just post some kind of event to the progress bar to update it from within the worker thread, thereby insuring that the GUI progress bar update is being invoked from the event thread? This would also obviate the need to use a timer to poll for an update, which I think is a waste especially when the monitored progress is at a variable rate, (or for number crunching, is executing on different speed machines).
    Also, doesn't using invokeLater() or invokeAndWait() still block the event dispatching thread? I don't understand how having a chunk of code started in the event thread doesn't block the event thread unless the code's executed in a "sub-thread", which would then make it not in the event thread.
    I'm also looking to have a progress bar updated to monitor a worker thread, but also want to include a "Stop" button, etc. and need the event queue not to be blocked.
    The last thing I can think of is to implement some kind of original event-listener class that listens to events that I define, then register it with the system event queue somehow, then have the worker thread post events to this listener which then calls setValue() in the progress bar to insure that the bar is updated from the event queue and when I want it to be updated. I don't know yet if it's possible to create and register these kinds of classes (I'm guessing it is).
    Thanks,
    Derek

  • Need help with threads?.. please check my approach!!

    Hello frnds,
    I am trying to write a program.. who monitors my external tool.. please check my way of doing it.. as whenever i write programs having thread.. i end up goosy.. :(
    first let me tell.. what I want from program.. I have to start an external tool.. on separate thread.. (as it takes some time).. then it takes some arguments(3 arguments).. from file.. so i read the file.. and have to run tool.. continously.. until there are arguments left.. in file.. or.. user has stopped it by pressing STOP button..
    I have to put a marker in file too.. so that.. if program started again.. file is read from marker postion.. !!
    Hope I make clear.. what am trying to do!!
    My approach is like..
    1. Have two buttons.. START and STOP on Frame..
    START--> pressed
    2. check marker("$" sign.. placed in beginning of file during start).. on file..
         read File from marker.. got 3 arg.. pass it to tool.. and run it.. (on separate thread).. put marker.. (for next reading)
         Step 2.. continously..
    3. STOP--> pressed
         until last thread.. stops.. keep running the tool.. and when last thread stops.. stop reading any more arguments..
    Question is:
    1. Should i read file again and again.. ?.. or read it once after "$" sign.. store data in array.. and once stopped pressed.. read file again.. and put marker ("$" sign) at last read line..
    2. how should i know when my thread has stopped.. so I start tool again??.. am totally confused.. !!
    please modify my approach.. if u find anything odd..
    Thanks a lot in advance
    gervini

    Hello,
    I have no experience with threads or with having more than run "program" in a single java file. All my java files have the same structure. This master.java looks something like this:
    ---master.java---------------------------------------------------
    import java.sql.*;
    import...
    public class Master {
    public static void main(String args []) throws SQLException, IOException {
    //create connection pool here
    while (true) { // start loop here (each loop takes about five minutes)
    // set values of variables
    // select a slave process to run (from a list of slave programs)
    execute selected slave program
    // check for loop exit value
    } // end while loop
    System.out.println("Program Complete");
    } catch (Exception e) {
    System.out.println("Error: " + e);
    } finally {
    if (rSet1 != null)
    try { rSet1.close(); } catch( SQLException ignore ) { /* ignored */ }
    connection.close();
    -------end master.java--------------------------------------------------------
    This master.java program will run continuously for days or weeks, each time through the loop starting another slave process which runs for five minutes to up to an hour, which means there may be ten to twenty of these slave processes running simultaneously.
    I believe threads is the best way to do this, but I don't know where to locate these slave programs: either inside the master.java program or separate slave.java files? I will need help with either method.
    Your help is greatly appreciated. Thank you.
    Logan

  • I need help: my ios 7 progress bar doesn't move anymore ???

    hellooo,
    so after a long time i decided to update my iphone to ios 7
    now the first progress bar was done in like 10 min but then
    the second started' tis bar was completed for like 1/4 of the bar and now it
    doesn't move anymore' and it's allready 2 hours now ..
    will this ever be oke or do i need to worry ?
    allready thanks.

    Hello Djegoo,
    I would be be concerned too if I was not able to update my iPhone.  If you have not resolved the issue, I recommend following the steps in the article below for an issue like this:
    iOS: Unable to update or restore
    http://support.apple.com/kb/HT1808
    As always, it is a good idea to create a backup before hand:
    iOS: How to back up and restore your content
    http://support.apple.com/kb/HT1766
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • Help with adding a progress bar to my compare-object script

    I have a simple compare object script that I would like to add some kind of intelligent progress bar or countdown timer to.  The script takes anywhere from 1-12 hours to run depending on the folder sizes.  Here is the script:
    $internal = Get-ChildItem -Recurse -path C:\Folder1
    $external = Get-ChildItem -Recurse -path C:\Folder2
    Compare-Object -ReferenceObject $internal -DifferenceObject $external | Out-File C:\compare_list.txt
    I have a progress bar script that I found but I do not know how to implement it into my existing script.  Here it is:
    for ($i = 1; $i -le 100; $i++) {Write-Progress -Activity 'counting' -Status "
    $i percent" -PercentComplete $i ; sleep -Milliseconds 20}
    Any help is much appreciated.

    Hi Brisketx,
    In addition, to add a Progress Bar to Your PowerShell Script, this article may be helpful for you:
    Add a Progress Bar to Your PowerShell Script:
    http://blogs.technet.com/b/heyscriptingguy/archive/2011/01/29/add-a-progress-bar-to-your-powershell-script.aspx
    I hope this helps.
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • I need help with my GUI Photo Album.

    Hello! I'm still learning bits about GUI and I need some assistance to make my basic program work. I've searched the forums to look at past Photo Album projects; they didn't help much or maybe I'm overlooking some things. Every time I click the "Next" button the image doesn't change. It may be a simple task to solve, but I'm really stumped! Sorry if it's such a stupid thing to ask. Thanks in advance.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class PhotoAlbum extends JPanel {
        int i = 1;
        JFrame frame = new JFrame("Photo Album");
        JButton next = new JButton("Next");
        ImageIcon icon = new ImageIcon("../Images/" + i + ".jpg");
        JLabel picture = new JLabel(icon);
        ButtonListener buttonListener = new ButtonListener();
        public PhotoAlbum() {
            frame.setSize(700, 600);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().setLayout(new BorderLayout(5,5));
            frame.getContentPane().add(picture, BorderLayout.CENTER);
            frame.getContentPane().add(next, BorderLayout.SOUTH);
            next.addActionListener(buttonListener);
            frame.setVisible(true);
        class ButtonListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                if(e.getSource() == next){
                    ++i;
    }

    WafflesNSyrup wrote:
    int i = 1;
    ImageIcon icon = new ImageIcon("../Images/" + i + ".jpg");
    ++i;
    So I understand that you originally thought incrementing (i) would somehow update (icon) since it uses (i) in an expression. But now you hopefully know this is not a magical expression language.
    I bet you would have also thought that this:
    int x = 1;
    int y = 2;
    int z = x + y;
    x = 42;
    y = 58;would have ended up with z having the value 100? It doesn't. It did the math once, when it executed the expression (x + y) and stored it in the variable (z). So z == 3, regardless of what happens to x or y after the fact.

  • Need help with a gui

    Here's my code:
    import java.awt.Dimension;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    public class xScriptGUI extends JPanel {
         private JLabel component1;
         private JLabel component2;
         private static JTextField component3;
         private static JPasswordField component4;
         private JButton component5;
         static String authUsername;
         static String authPassword;
         public xScriptGUI() {
              // construct components
              component1 = new JLabel("Username:");
              component2 = new JLabel("Password:");
              component3 = new JTextField(5);
              component4 = new JPasswordField(5);
              component5 = new JButton("Login");
              // adjust size and set layout
              setPreferredSize(new Dimension(234, 132));
              setLayout(null);
              // add components
              add(component1);
              add(component2);
              add(component3);
              add(component4);
              add(component5);
              // set component bounds (only needed by Absolute Positioning)
              component1.setBounds(25, 20, 100, 25);
              component2.setBounds(25, 50, 100, 25);
              component3.setBounds(95, 20, 100, 25);
              component4.setBounds(95, 50, 100, 25);
              component5.setBounds(65, 85, 100, 25);
         public static void main(String[] args) {
              JFrame frame = new JFrame("xScript Auth");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.getContentPane().add(new xScriptGUI());
              frame.pack();
              frame.setVisible(true);
    }When Component5 is clicked, i would like it to do this:
              authUsername = component3.getText();
              authPassword = component4.getText();
              JOptionPane.showMessageDialog(frame, authUsername);
              JOptionPane.showMessageDialog(frame, authPassword);COuld you implement this into my script, as i'm having lots of difficulties.
    TIA,
    Chris

    Could you help me with this code, too?
    import java.awt.Dimension;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    public class xScriptGUI extends JPanel implements ActionListener {
      private JLabel component1;
      private JLabel component2;
      private static JTextField component3;
      private static JPasswordField component4;
      private JButton component5;
      static String authUsername;
      static String authPassword;
      public xScriptGUI() {
        // construct components
        component1 = new JLabel("Username:");
        component2 = new JLabel("Password:");
        component3 = new JTextField(5);
        component4 = new JPasswordField(5);
        component5 = new JButton("Login");
        component5.addActionListener(this);
        // adjust size and set layout
        setPreferredSize(new Dimension(234, 132));
        // why do people do this?
        // this is a very fragile GUI.
        setLayout(null);
        // add components
        add(component1);
        add(component2);
        add(component3);
        add(component4);
        add(component5);
        // set component bounds (only needed by Absolute Positioning)
        // (and will stuff up on the next machine, a different screen
        // resolution, a different OS, possibly the next Java version..)
        component1.setBounds(25, 20, 100, 25);
        component2.setBounds(25, 50, 100, 25);
        component3.setBounds(95, 20, 100, 25);
        component4.setBounds(95, 50, 100, 25);
        component5.setBounds(65, 85, 100, 25);
      public void actionPerformed(ActionEvent ae) {
        if (ae.getSource()==component5) {
          authUsername = component3.getText();
          // deprecated!
          // authPassword = component4.getText();
          authPassword = new String(component4.getPassword());
          // we have no convenient reference to the frame, so we
          // use the JPanel (which should be in the 'same' place)
          // instead
          JOptionPane.showMessageDialog(this, authUsername);
          JOptionPane.showMessageDialog(this, authPassword);
         URL url = new URL("http://auth.1337chris.org/xscripts/auth.php?user=" + URLEncoder.encode(authUsername, "UTF-8") + "&pass=" + URLEncoder.encode(authPassword, "UTF-8"));
         BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        url.openStream()));
         String inputLine;
         while ((inputLine = in.readLine()) != null)
              if (inputLine.equals("0")) {
                   JOptionPane.showMessageDialog(this, "Go buy an auth, kid");
              } else if (inputLine.equals("1")) {
                   JOptionPane.showMessageDialog(this, "AUTHED");
         in.close();
        } else {
          JOptionPane.showMessageDialog(this, "Unknown command!");
      public static void main(String[] args) {
        // this should use 'invokeLater'
        JFrame frame = new JFrame("xScript Auth");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new xScriptGUI());
        frame.pack();
        frame.setVisible(true);
    }

  • I need help with the GUI nad Graphic 2D....

    Hi
    i'm kind new to java and i have couple of questions... all my questions about the GUI...
    when i want to create a GUI programe , and when i want to draw a graphic with GUI, i do that way(code)
    "public class x1 extends JPanle{
         public void PaintComponent(Graphic g){
    My questions:
    1) why do i have to extend from JPanle ??
    2) Why do i use paintcomponent??? why i couldn't use directly 'Graphic g' ??
    This code i get it from the book, this is how it is done...
    Also, if i want to draw some shapes(rec, circle ..etc) and i want to put Button and organize them, how could i do that???
    i tried to organize the button after i draw the rectangle but i can't... all becaus of the stupid way'the code that i wrote it', i hope there is an alternative way.
    My last question... how can i change the font ???
    i want to use 'sans comic'...
    Thanks alot....

    kiiwii14 wrote:
    i'm kind new to java and i have couple of questions...fair enough.
    all my questions about the GUI...and that's your problem right there.
    Your questions tell me that you're missing quite a few fundamentals of programming in Java. There's nothing wrong with that, everyone starts this way. But if you try to do any GUI programming at your current level you will run head-first into many, many problems that could be easily avoided if you concentrate on learning the basics first.
    when i want to create a GUI programe , and when i want to draw a graphic with GUI, i do that way(code)
    "public class x1 extends JPanle{That code doesn't compile. It's JPanel, not JPanle. Please post only compiling code (or near it, if you've got a question about a compiler error).
         public void PaintComponent(Graphic g){"paintCompontent", not "PaintComponent".
    Oh, and in the future please use the CODE-Button when posting code (1. copy+paste code 2. select code 3. press "CODE" just above the text area).
    My questions:
    1) why do i have to extend from JPanle ??You don't have to. You can, if you want your class to be a specific type of JPanel.
    2) Why do i use paintcomponent??? why i couldn't use directly 'Graphic g' ??How would you "directly use Graphic g"?
    That's the way the framework is written. Components draw themselves using that method. If you want to change how they draw themselves you can override that method.
    Did you read the chapter that tells you this or did you simply copy out the code example? The examples are there to illustrate the points and help you understand. They are not a *substitute* to actually reading the text.
    Also, if i want to draw some shapes(rec, circle ..etc) and i want to put Button and organize them, how could i do that???Finish reading the book, write some basic programs and then work on from there.
    You're trying to learn a feature and produce a useful product at the same time. I can tell you from experience that this is a very bad idea.
    i tried to organize the button after i draw the rectangle but i can't... How did you try?
    all becaus of the stupid way'the code that i wrote it', i hope there is an alternative way.You didn't show us your attempt so we can't tell you any alternative.
    My last question... how can i change the font ???
    i want to use 'sans comic'... Hm ... "Comic Sans" is the name. And that's not a font. [It's a desease|http://bancomicsans.com/].

  • Need help with Java GUI

    I'm a bit unfamiliar with the features of the Java GUI which I'm using for an online game I'm making. Specifically, I can't move around the different components the way I want to. I want to have my game on one frame, but made up of 3 different parts. The top half will be the the actual game where the images are displayed, then below that will be a scroll pane to show all the messages the player has received, and the bottom part will be a text field so the player can send messages. I have the text field and scroll pane working, but the problem is that the scroll pane takes up the entire screen (except for the text field) and I can't find any way to resize it and move it to the bottom, just above the text screen, the way I want it to be. I'm using JTextField for the text field, and JDisplayArea and JScrollPane for the scroll pane.
    Here are two images in case you can't visualize what I am saying. This is what it looks like now:
    http://img127.imageshack.us/img127/1294/beforeob1.jpg
    And this is how it should be:
    http://img127.imageshack.us/img127/8724/aftedzu7.jpg
    Help would be greatly appreciated. Thanks in advance.

    Does the class that implement your game panel provide a meaningful return value for the method "getPreferredSize()"? I guess you use a BorderLayout, don't you? In this case the game panel isn't visible because it doesn't tell the LayoutManager what size it wants and so it gets a 0,0 size.
    Greetings
    Stefan

  • Creating breakout game. Need help with thread starting.

    Howdy. As the title says, I've got an assignment to make a breakout game. So far it's going alright, but I've run into a rather large snag...I can't get it to animate :P I've got my main applet, then I created a class heirarchy for the paddle, ball, and brick objects. For this question, lets just focus on the ball object.
    This is my applet code so far (it is not even close to being done, so don't laugh :P )
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    * Class BreakoutApplet - Plays a simple game of Breakout.
    * @author Kris Nelson
    * @version November 10, 2004
    public class BreakoutApplet extends JApplet implements Runnable
        protected Brick brick; // creates an object of class brick
        protected Ball ball; // creates an object of class ball
        protected Paddle paddle; // creates an object of class paddle
        protected boolean running; // tells the program whether or not the thread is running
        protected ArrayList brickArray = new ArrayList(); // stores all the bricks in the game
        protected Thread timer; // the thread which controls the animation for the applet
        * Called by the browser or applet viewer to inform this JApplet that it
        * has been loaded into the system. It is always called before the first
        * time that the start method is called.
        public void init()
            // this is a workaround for a security conflict with some browsers
            // including some versions of Netscape & Internet Explorer which do
            // not allow access to the AWT system event queue which JApplets do
            // on startup to check access. May not be necessary with your browser.
            JRootPane rootPane = this.getRootPane();   
            rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
            createBricks(); // creates the games array of bricks
            ball = new Ball(400, 400, 2, 2); // sets the values for the ball
            paddle = new Paddle(300, 660, 2); // sets the values for the paddle
            // !!!!!!! have tried placing ball.start() here
        * Paint method for applet.
        * @param  g   the Graphics object for this applet
        public void paint(Graphics g)
            // draws the background, border, and all the games objects
            g.setColor(Color.lightGray); // sets the drawing color to light gray
            g.fillRect(0, 0, 600, 700); // displays the game screens background
            displayBorder(g); // displays the game screens border
            displayBricks(g); // displays the array of bricks
            ball.display(g); // displays the ball
            paddle.display(g); // displays the paddle
        * Creates the games array of bricks
        public void createBricks()
            int colorNumber = 1; // starts the color of the bricks at orange
            double yPosition = 100; // starts the bricks y screen position at 100
            for(int i = 0; i < 4; i++)
                double xPosition = 12; // starts the bricks x screen position at 12
                for(int j = 0; j < 8; j++)
                    if(colorNumber == 0)
                        colorNumber = 1; // sets the color of the bricks to orange
                    else
                        colorNumber = 0; // sets the color of the bricks to green
                    brickArray.add(brick = new Brick(xPosition, yPosition, colorNumber)); // adds a brick to the current container in the brick array
                    xPosition = xPosition + brick.getWidth(); // move the bricks x screen position to the next column
                yPosition = yPosition + brick.getHeight(); // moves the bricks y screen position to the next row
                if(colorNumber == 0)
                    colorNumber = 1; // sets the color of the bricks to orange
                else
                    colorNumber = 0; // sets the color of the bricks to green
        * Displays the game screens border
        * @param  g   the Graphics object for this applet
        public void displayBorder(Graphics g)
            g.setColor(Color.black); // sets the drawing color to black
            g.fillRect(0, 0, 600, 24); // draws a border on the top of the screen
            g.fillRect(0, 0, 12, 700); // draws a border on the left of the screen
            g.fillRect(588, 0, 12, 700); // draws a border on the right of the screen
        * Displays the array of bricks on the screen
        * @param  g   the Graphics object for this applet
        public void displayBricks(Graphics g)
            Brick currentBrick; // holds the brick data from the current ArrayList container
            for(int i = 0; i < 32; i++)
                currentBrick = (Brick)(brickArray.get(i)); // grabs the brick data from the current ArrayList container
                currentBrick.display(g); // displays the current brick
        * Called by the browser or applet viewer to inform this JApplet that it
        * should start its execution. It is called after the init method and
        * each time the JApplet is revisited in a Web page.
         public void start()
             if(timer == null)
                 timer = new Thread(this); // creates a new object of type Thread
                 timer.start(); // starts the new thread
                 running = true; // tells the program that the new thread is running
        * Runs the code that controls the animation
        public void run()
            do{
                repaint(); // redraws the screen
                try{
                    timer.sleep(100); // puts the thread to sleep for 100 milliseconds
                } catch(InterruptedException e) {running = false;}
                // !!!!!!! have tried placing ball.start() here
            } while(running);
            timer = null; // destroys the timer thread
        * Called by the browser or applet viewer to inform this JApplet that
        * it should stop its execution. It is called when the Web page that
        * contains this JApplet has been replaced by another page, and also
        * just before the JApplet is to be destroyed.
        public void stop()
            running = false; // tells the program that the thread is now done
    }These are the bits of code for my class heirarchy, just to (hopefully) make it easier to follow.
    import java.awt.*;
    * The parent class of all the games objects.
    * @author Kris Nelson
    * @version November 9, 2004
    public class Sprite
        protected double screenX, screenY; // stores the x and y location of the object
        * Constructor for objects of class Sprite
        * @param  xPosition   the initial x screen position
        * @param  yPosition   the initial y screen position
        public Sprite(double xPosition, double yPosition)
            screenX = xPosition; // sets the initial x screen position
            screenY = yPosition; // sets the initial y screen position
        * Sets new x and y screen locations for an object
        * @param  newX   the new x screen location
        * @param  newY   the new y screen location
        public void setScreenXY(double newX, double newY)
            screenX = newX; // sets the new x screen location
            screenY = newY; // sets the new y screen location
        * Sends back the current x screen location
        * @return     the current x screen location
        public double getScreenX()
            return screenX; // returns the current x screen location
        * Sends back the current y screen location
        * @return     the current y screen location
        public double getScreenY()
            return screenY; // returns the current y screen location
    import java.awt.*;
    * Parent class of any game object that moves.
    * @author Kris Nelson
    * @version November 9, 2004
    public class MovingSprite extends Sprite implements Runnable
         protected double speedX, speedY; // stores the speed of an object in the x and y directions
         protected Thread timer; // the thread which controls animation for all moving objects
         protected boolean running; // tells the program whether or not the thread is running
         * Constructor for objects of class MovingSprite
         * @param  xPosition   the initial x screen position
         * @param  yPosition   the initial y screen position
         * @param  xSpeedValue   the speed in the x direction
         * @param  ySpeedValue   the speed in the y direction
         public MovingSprite(double xPosition, double yPosition, double xSpeedValue, double ySpeedValue)
              super(xPosition, yPosition); // passes the initial screen positions to Sprite
              speedX = xSpeedValue; // sets the speed in the x direction
              speedY = ySpeedValue; // sets the speed in the y direction
         * Sends back the speed in the x direction
         * @return     the speed in the x direction
         public double getSpeedX()
             return speedX; // returns the speed in the x direction
         * Sends back the speed in the y direction
         * @return     the speed in the y direction
         public double getSpeedY()
             return speedY; // returns the speed in the y direction
         * Starts the thread in order to start animation
         public void start()
             if(timer == null)
                 timer = new Thread(this); // creates a new object of type Thread
                 timer.start(); // starts the new thread
                 running = true; // tells the program that the new thread is running
         * Empty since the child objects have their own run methods
         public void run()
         * Stops the thread from running
         public void stop()
             running = false; // tells the program that the thread is now done
    import java.awt.*;
    * Creates a single ball who's purpose is to bounce around and destroy the bricks.
    * @author Kris Nelson
    * @version November 10, 2004
    public class Ball extends MovingSprite
        protected static final double BALL_WIDTH = 15; // sets the width of the ball
        protected static final double BALL_HEIGHT = 15; // sets the height of the ball
        * Constructor for objects of class Ball
        * @param  xPosition   the initial x screen position
        * @param  yPosition   the initial y screen position
        * @param  xSpeedValue   the speed in the x direction
        * @param  ySpeedValue   the speed in the y direction
        public Ball(double xPosition, double yPosition, double xSpeedValue, double ySpeedValue)
            super(xPosition, yPosition, xSpeedValue, ySpeedValue); // passes the initial screen positions and ball speeds to MovingSprite
            // !!!!!!!! have tried placing timer.start() here
        * Displays a ball onto the screen
        * @param  g   the Graphics object for this applet
        public void display(Graphics g)
            g.setColor(Color.blue); // sets the balls color
            g.fillOval((int)(screenX), (int)(screenY), (int)(BALL_WIDTH), (int)(BALL_HEIGHT)); // displays the ball
        * Runs the code that controls the balls animation
        public void run()
            do{
                try{
                    timer.sleep(100); // puts the thread to sleep for 100 milliseconds
                } catch(InterruptedException e) {running = false;}
                screenX = screenX + speedX;
                screenY = screenY + speedY;  // this is VERY SIMPLE BALL MOVEMENT FOR TESTING PURPOSES, WILL BE CHANGED LATER
            } while(running);
    }Sorry if that was too much code. I'm just trying to make this easier to follow.
    I placed a // !!!!!!!!!!!!! comment in the places where I have tried starting the ball thread.
    So basically, everything is running fine, except that I'm not at all sure of where to start the ball Thread, and thus can't start anything moving. If someone could tell me where I should be starting the thread, I would REALLY appriciate it. Thank you :D
    - Kris

    Some advice.
    1. the start method on the ball should be called from the start method on the applet and should in turn call the start method on the sprite's thread.
    2. the run method of the Moveable sprite should have been declare abstract
    3. don't implement borders manually. There's a java.awt.Border class for that.
    4. probably, you don't want to have the game invoke each sprite by name; just make a big list of all the sprites and invoke all of them every time
    5. do you really need provision for a non-circular ball? this isn't rugby.
    6. I don't think you ever had a threading problem, just a display problem.
    7. Don't write comments like this:     ball.display(g); // displays the ballHere's my (even more simplified version):import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    * Class BreakoutApplet - Plays a simple game of Breakout.
    * @author Kris Nelson, modified by Michael Lorton
    * @version November 10, 2004
    public class BreakoutApplet extends JApplet implements Runnable {  
        protected Ball ball;
        protected Paddle paddle;
        public boolean running; // tells the program whether or not the thread is running
        protected Thread timer; // the thread which controls the animation for the applet
        public void init() {
            // this is a workaround for a security conflict with some browsers
            // including some versions of Netscape & Internet Explorer which do
            // not allow access to the AWT system event queue which JApplets do
            // on startup to check access. May not be necessary with your browser.
            getRootPane().putClientProperty("defeatSystemEventQueueCheck",
                                            Boolean.TRUE);
             ball = new Ball(this, GAMEWIDTH / 2, GAMEHEIGHT / 2, 5, 5);
        public final static int GAMEWIDTH = 600;
        public final static int GAMEHEIGHT = 400;
        public void paint(Graphics g) {
            g.setColor(Color.lightGray);
            g.fillRect(0, 0,
                       GAMEWIDTH, GAMEHEIGHT);
            ball.display(g); // displays the ball
        * Called by the browser or applet viewer to inform this JApplet that it
        * should start its execution. It is called after the init method and
        * each time the JApplet is revisited in a Web page.
        public void start() {
            if(timer == null) {
                timer = new Thread(this); // creates a new object of type Thread
                timer.start(); // starts the new thread
                running = true; // tells the program that the new thread is running
            ball.start();
        * Runs the code that controls the animation
        public void run() {
            do{
                repaint(); // redraws the screen
                try{
                    Thread.sleep(100);
                } catch(InterruptedException e) {running = false;}
            } while(running);
        public void stop() {
            running = false;
    abstract class Sprite {
        protected double screenX, screenY; // stores the x and y location of the object
        protected final BreakoutApplet parent;
        * Constructor for objects of class Sprite
        * @param  xPosition   the initial x screen position
        * @param  yPosition   the initial y screen position
        public Sprite(BreakoutApplet parent, double xPosition, double yPosition) {
            this.parent = parent;
            screenX = xPosition; // sets the initial x screen position
            screenY = yPosition; // sets the initial y screen position
        * Sets new x and y screen locations for an object
        * @param  newX   the new x screen location
        * @param  newY   the new y screen location
        public void setScreenXY(double newX, double newY) {
            screenX = newX; // sets the new x screen location
            screenY = newY; // sets the new y screen location
        * Sends back the current x screen location
        * @return     the current x screen location
        public double getScreenX() {
            return screenX; // returns the current x screen location
        * Sends back the current y screen location
        * @return     the current y screen location
        public double getScreenY() {
            return screenY; // returns the current y screen location
        abstract public void display(Graphics g);
    * Parent class of any game object that moves.
    * @author Kris Nelson
    * @version November 9, 2004
    abstract class MovingSprite extends Sprite implements Runnable {
        protected double speedX, speedY; // stores the speed of an object in the x and y directions
        protected Thread timer; // the thread which controls animation for all moving objects
        protected boolean running; // tells the program whether or not the thread is running
        * Constructor for objects of class MovingSprite
        * @param  xPosition   the initial x screen position
        * @param  yPosition   the initial y screen position
        * @param  xSpeedValue   the speed in the x direction
        * @param  ySpeedValue   the speed in the y direction
        public MovingSprite(BreakoutApplet parent,
                            double xPosition, double yPosition,
                            double xSpeedValue, double ySpeedValue) {
            super(parent, xPosition, yPosition);
            speedX = xSpeedValue; // sets the speed in the x direction
            speedY = ySpeedValue; // sets the speed in the y direction
        * Starts the thread in order to start animation
        public void start() {
            if(timer == null) {
                timer = new Thread(this); // creates a new object of type Thread
                timer.start(); // starts the new thread
                running = true; // tells the program that the new thread is running
        * Runs the code that controls the balls animation
        public void run() {
            while (parent.running) {
                try{
                    Thread.sleep(100);
                } catch(InterruptedException e) {
                    System.err.println(e);
                step();
        abstract protected void step();
    * Creates a single ball whose purpose is to bounce around and destroy the bricks.
    * @author Kris Nelson
    * @version November 10, 2004
    class Ball extends MovingSprite {
        protected static final int BALL_DIAMETER = 15;
        * Constructor for objects of class Ball
        * @param  xPosition   the initial x screen position
        * @param  yPosition   the initial y screen position
        * @param  xSpeedValue   the speed in the x direction
        * @param  ySpeedValue   the speed in the y direction
        public Ball(BreakoutApplet parent,
                    double xPosition, double yPosition,
                    double xSpeedValue, double ySpeedValue) {
            super(parent, xPosition, yPosition, xSpeedValue, ySpeedValue);
        * Displays a ball onto the screen
        * @param  g   the Graphics object for this applet
        public void display(Graphics g) {
            g.setColor(Color.blue);
            g.fillOval((int)(screenX),
                       (int)(screenY),
                       BALL_DIAMETER, BALL_DIAMETER);
        protected void step() {
                screenX = screenX + speedX;
                if (screenX < 0) {
                    screenX = -screenX;
                    speedX = -speedX;
                else if ((screenX + BALL_DIAMETER)> BreakoutApplet.GAMEWIDTH) {
                    screenX = 2*(BreakoutApplet.GAMEWIDTH  - BALL_DIAMETER) - screenX;
                    speedX = -speedX;
                screenY = screenY + speedY;
                if (screenY < 0) {
                    screenY = -screenY;
                    speedY = -speedY;
                else if ((screenY  + BALL_DIAMETER) > BreakoutApplet.GAMEHEIGHT) {
                    screenY = 2*(BreakoutApplet.GAMEHEIGHT - BALL_DIAMETER) - screenY;
                    speedY = -speedY;
    }

  • ***I need help with my SPRY MENU BAR***

    Hi everyone,
    I have installed a Horizontal and Vertical Spry Menu Bar.
    It looks great, but I can not figure this out.
    When I click on any of the links on the bars,
    my text jumps to the righ
    Can someone please tell me how I can make
    the text to stop jumping.
    My test page is located at the link below:
    http://www.tonyasdynamicdesigns.com/gregs-pages/index.html
    Thank you so much for your help,
    Tonya

    I know that the problem is in my main-css.css because
    when I deleted this css code, the text jumping stopped.
    I can not figure out how to fix my main-css.css style.
    Can you please help me?
    Below is part of my css code
    that is causing the problem.
    body {
              background-color: #000000;
              background-repeat: repeat;
              background-image: url(.../gregs-images/bg.jpg);
              background-position: center;
              background-attachment: fixed;
    #container {
              width: 965px;
              fixed-width: 965px;
              background-color: #1f1f1f;
              margin-right: auto;
              margin-left: auto;
              font-size: 12px;
              color: #afafaf;
              font-family: Arial, Helvetica, sans-serif;
              font-style: normal;
              line-height: normal;
              font-weight: normal;
              font-variant: normal;
              text-transform: none;
              text-decoration: none;
              border: 2px solid #1f1f1f;
              margin-bottom: 30px;
              margin-top: 30px;
              background-image: url();
              background-repeat: repeat;
    #shadow {
              width: 968px;
              background-image: url(.../images/vertical-website-background-shadow.png);
              background-repeat: repeat-y;
              margin-right: auto;
              margin-left: auto;
    #bottomShadow {
              margin-right: auto;
              margin-left: auto;
              width: 968px;
              background-repeat: no-repeat;
              background-image: url(.../images/bottom-website-background-shadow.png);
              height: 54px;
    #header {
              height: 272px;
              background-image: url(../gregs-images/smokehouse-studios-banner.png);
              width: 965px;
    #footer {
              height: 381px;
              font-family: Arial, Helvetica, sans-serif;
              font-size: 12px;
              clear: both;
    #navigation  {
              width: 900px;
              fixed-width: 900px;
              background-color: #1f1f1f;
              display: in-line;
              position: fixed;
              overflow: hidden;
    #content  {
              font-family: Arial, Helvetica, sans-serif;
              font-size: 14px;
              color: #afafaf;
              background-repeat: repeat;
              background-image: url(.../gregs-images/grey-gradient-bg.png);
              background-color: #1f1f1f;
              text-align: left;
              width: 965px;

  • Need help with flash player / slider bar navigation

    Hello, I am having a flash player developed right now for a
    intensive video site.
    I have a few questions since I'm new to flash.
    I would like the users to be able to jump forward in the
    video at any point. However, the player my developer gave me cannot
    do this. He is telling me that I will need FMS (Flash Media Server)
    software on my server in order to do this.
    Is this correct? Can we get this option without FMS?
    Also, is this a big change in scope to add this in. Our flash
    player is already done but does not have this very important
    feature.
    Thanks in advance.

    There are two methods to having this work.
    1. Use the FMS as your developer already stated.
    2. Keyframe the heck out of the FLV. This works because the
    typical player skin allows you to skip around to a keyframe. The
    more keyframes you have, the more places you can skip around to.
    The downside is that each keyframe you add to the video adds file
    size. You may also need to set the totalTime parameter of the video
    on load.
    :: EDIT ::
    You ask about implementation and scope changes in your
    question. The first is a very big scope change, and very costly to
    implement. The second, if the player that was developed uses the
    standard classes for the player scrub bar, would likely only
    require a re-encode of every video.

  • Help with Threads

    I need help with threads. How can I break this code into teo threads without chaning the data objects at all? Producer will produce string line by line and consumer will take the line and search for the word. Help me please.
    Thank you
    public class WordFinder
    * Main program opens the file given by the user as an argument and
    * searches for the word given by the user. If the word is found,
    * the line number on which the word occurs is displayed.
    * @param args[0] Word to search for
    * @param args[1] Name of file to search
    public static void main(String[] args) throws IOException
    // To keep track of how long the program runs we'll set the startTime
    // variable to the current time in milliseconds and use that at
    // the end of the program to find out how long we ran.
    long startTime = System.currentTimeMillis();
    String wordToFind;
    String currentLine;
    int lineCount = 0; // Keep track of line numbers
    BufferedReader inputFile = null; // Needed to get compiler to quit
    // complaining about uninitialized
    // variables.
    // Make sure we have 2 arguments passed to us
    if (args.length < 2)
    // Nope. Show user how to run and then exit with an error (1)
    System.out.println("usage: java WordFinder <word> <file pathname>");
    System.exit(1);
    // So far, so good. Now try to open the file the user gave us as
    // a parameter. We'll use a BufferedReader object to read the file
    // so we can read one line at a time from the input. If opening the
    // file fails, print an error message and exit with an error (1).
    try
    inputFile = new BufferedReader(new FileReader(args[1]));
    catch (FileNotFoundException e)
    System.out.println(args[1] + ": File not found or is not readable");
    System.exit(1);
    // Set the wordToFind variable to refer to args[0]. We don't
    // really need to do this, but it makes our code more readable
    wordToFind = args[0];
    // We're going to read the file one line at a time. For each
    // line, we'll create a StringTokenizer object to break the line
    // into distinct words, checking each word to see if it's the same
    // as the given search word.
    // Read first line from the file
    currentLine = inputFile.readLine();
    while (currentLine != null) // Repeat until we reach EOF
    // Have a valid input line, increment the counter
    lineCount++;
    // Create a StringTokenizer object over the current line
    StringTokenizer tokens = new StringTokenizer(currentLine);
    // Check each word in the string by accessing each token
    while (tokens.hasMoreTokens())
    // See if the next word is the one we're looking for and
    // advance the token iterator to the next token
    if (wordToFind.equals(tokens.nextToken()))
    // Yes, display the current line number
    System.out.println(wordToFind + " found on line " + lineCount);
    // Read next line from the file
    currentLine = inputFile.readLine();
    } // while
    // Done with the input file
    inputFile.close();
    // Display the running time of this program in milliseconds by
    // subtracting the start time from the current time
    System.out.println((System.currentTimeMillis() - startTime) + " milliseconds");
    } // main
    } // WordFinder

    You may create Queue object. (I guess that you're already know QUEUE)
    Then ... use producer thread to load input file into queue. (Enqueue)
    Consumer ... dequeue
    Queue can be empty because of
    - Input file was read to EOF and Consumer had produced all queue.
    or
    - Cunsumer works too fast... So the queue is empty.
    So, you may have to use ... wait() in Consumer in case of the queue is empty.
    And use notify() in Producer to wake up consumer ...
    Is this right ?

  • Need help with BARS 4.0.12 - 4.0.13 upgrade

    Hello,
    I'm a VoIP noob and need help with a BARS upgrade. To resolve a known problem (Bug #CSCsi32637) we need to upgrade BARS from 4.0.12 to 4.0.13. This is per TAC. However, no one in our company has done this before. I've reviewed the 4.0.12 Admin Guide since I was unable to find any admin docs for 4.0.13. However, I have several questions about this upgrade that hopefully someone here can help with:
    1) The install for 4.0.12 requires a reboot of the server. Is this the same for 4.0.13?
    2) CCM version is 4.1(3)sr6; any problems known with BARS 4.0.13 and this version of CCM? I didn't see
    anything in the Rel Notes or via the Bug Toolkit (figure it never hurts to ask).
    3) Will the previously input configuration settings (i.e., Data Source Servers, Storage Location, Schedule) be preserved or will I have to reinput these settings?
    4) Any known issues with performing this upgrade while controlling the server via VNC?
    5) The 4.0.12 docs state that "To successfully back up the Cisco Unified CallManager database, the backup server and backup targets must exist in the same cluster and have the same version of BARS installed". So BARS must be installed on my publisher (the Backup Server) AND my three subscribers? I'm not finding BARS on these subscribers now.
    Many Thanks for any input,
    Brian Read

    1) Yes, any version requires reboot after install
    2) not that i'm aware of
    4) you'll need to reconfigure it
    5) no
    6) although it's recommended there is no real need to backup any other server than the PUB which contains the master DB, any SUB only needs to pull the info from PUB in case of crash and reinstall
    HTH
    java
    if this helps, please rate

  • Need help with almost completed plugin engine project

    Hi all,
    For a while now I have been working on a plugin engine. After a few iterations, the engine is similar to the Eclipse engine, in that plugins use extension points and extensions to allow contributions. Unlike the eclipse engine I have added the ability for plugins to fire events through the engine and other plugins can add listeners, all through the plugin.xml manifest. Dependencies are mostly handled automatically at plugin load time (when extensions get resolved to extension points, and listeners get resolved to events). For the case where a plugin needs to use classes from another plugin, dependencies are also allowed to be declared. Like the eclipse engine, activation of plugins occurs the first time a class is used within the plugin's classpath, OR a plugin can be activated after it is loaded.
    What I need help with is testing, working on examples to provide with the engine project, and feedback/suggestions before we release the M1 build. I am asking for those that are interested in this type of work to volunteer to help where applicable and possible. I want to provide a solid plugin engine to the java community, one that is easy to use, works well, and is pretty effecient in terms of resource usage and performance.
    Of particular interest to me right at the moment is dealing with multiple versions. As I see it, the engine will be used within an application and as such plugins would be distributed with a specific application version. The plugin version itself is more of a notification as to what version a plugin is, although I imagine it will help when updating at runtime as well.
    Just a few other details of the engine. It handles (or will soon) dynamic load, unload and reload of plugins at runtime. Plugins can be distributed in an archive file format, we call .par (Plugin ARchive), with additional plugin filename extensions configurable at runtime. The plugins can be developed and deployed in an expanded directory format as they are in Eclipse as well, or in the archive format. In the archive format they do not need to be unzipped when deployed, and they can contain embeded jar/zip libraries. The engine handles finding and creating classes directly out of the .par file at runtime.
    Multiple locations to find plugins are configurable before the engine starts, and even after it starts more could be added to allow additional locations to find plugins. URLs are supported, and soon the HTTP protocol will be supported so that plugins can be downloaded and installed at runtime.
    The project can be found at www.sourceforge.net/projects/genpluginengine. If you would like to get involved and help out, please sign up on the dev mail list and send an email to introduce yourself to the rest of the members on the list.
    I'll also add that I am working on a Swing UI Framework built entirely from plugins. It provides a ready-to-launce UI application that developers can simply add their plugins to, extending various extension points of the framework to have menu items, toolbar buttons, status bar access, help and preferences dialog additions, file i/o choosers, tons of open-source components ready to use (or extend to add on to), and like Eclipse, hopefully... draggable window frames that can be dropped on any other frame to form a tabbed frame of windows. Some of this is a ways off, some is getting there now. Presently you can add menu items that do allow plugin activation when first clicked, so plugins can be loaded but not activated until needed. The Preference dialog works but is not completed, and a plugin that adds a plugin control panel to view all loaded plugins, activate them, load/unload/reload, view extension points, extensions, dependencies, etc is partially completed. The point is, to allow a ready to run UI framework in Swing with an easy path for developers to quickly build applications with. If you are interested in this, when you join the mail list and introduce yourself, indicate that you are interested in this as well, as we need help with plugin development for it and would appreciate more help here too.
    Look forward to some replies.

    Might I suggest setting up a project at a known project-site? I've seen your progress and questions posted here from time to time, but one of the drawbacks is that you have to fill each post with the entirity of your vision to explain what you're doing. That's a lot of text to read - and most folks will skip right over it.
    On the other hand, a well-crafted, good-looking project web-site, with appropriate links and docs and vision statements, diagrams, etc. will have more likelyhood of attracting volunteers. java.net and sourceforge.net are likely spots to set up shop. In addition, you get CVS and bug-tracking systems, which can be quite valuable in such a large-scale project where there are lots of pieces.

Maybe you are looking for