The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

How to do two functions at the same time ?

Posted by Avin Sinanan on February 16, 2002 at 10:06 PM

Hello I am wondering how do you do two fucntions at the same time.. The code I've included does the following -

It creates a button and the buttons moves to a locations by using a "for" loop and a "setBounds" expression.

Then it creates a second button and moves it to a diffrent location by using the same method as above. The problem is that the second button has to wait till the first button is finished moving.

How do I get both buttons to move at the same time. I need a method that will allow me to move 3 or even 10 buttons at the same time with all buttons having diffrent motion paths.

Here is the code... any help would be greatly appreciated. thanks in advance.. yours respctufully Avin Sinanan

CODE -->

import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.awt.*;

class TwoFunctions
{
public static void main(String[] args)
{
Frame frame = new JFrame();
JPanel pane = new JPanel();
pane.setLayout(null);

frame.setSize(600,600);
frame.setVisible(true);

JButton button1 = new JButton("One");
JButton button2 = new JButton("Two");

for(int i=0 ; i<400 ; i++)
{
button1.setBounds(i,50,70,70);
pane.add(button1);
frame.getContentPane().add(pane);
pane.updateUI();

}


for(int j = 0 ; j<500 ; j++)
{
button2.setBounds(200,j,70,70);
pane.add(button2);
frame.getContentPane().add(pane);
pane.updateUI();

}

}
}



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us