The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 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:

A hint

Posted by Senthoor on February 17, 2002 at 8:51 AM

My comments {}

> 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();
>
> }

{Actually what you could do is have both button code inside a while loop (even a for loop would do) And Initialise the I and J values out side the loop and increase i and decrease j inside the loop. Which will give you the same effect.

The better method would be to use threads to do the task
}

> 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