JTextArea

1 resposta
S

:oops: Estou com uma grande dúvida, é possível CRIAR VÁRIAS JTextArea ALEATÓRIAS ? Achei um programa que cria vários botões, alterei algumas coisas, mas não tive muito sucesso. Será que alguém pode me ajudar… :?:

import javax.swing.<em>;

import java.awt.</em>;

import java.awt.event.*;
public class MenorCaminho extends JFrame

{

JLabel lValor1 = new JLabel(Primeiro Caminho);

JLabel lValor2 = new JLabel(Segundo Caminho);

private GridBagLayout gbLayout;
public MenorCaminho()

{

super( Menor Caminho );
String estacao;
  int i_estacao;
   
  estacao = JOptionPane.showInputDialog("Entre com a QUANTIDADE DE ESTAÇÕES");
  i_estacao = Integer.parseInt(estacao);   	
      
  final int SIZE = i_estacao;
  
  GridBagConstraints gbConstraints = new GridBagConstraints();
  Container c = getContentPane();
  gbLayout = new GridBagLayout();
  c.setLayout( gbLayout );

  JTextArea campo = new JTextArea("1",1, 5);
  JTextArea campo2 = new JTextArea("2",1, 5);
  
  gbConstraints.fill = GridBagConstraints.NONE;
    
       
  Box boxes[] = new Box[2];
  
  
  Box c1 = Box.createVerticalBox();
  Box c2 = Box.createVerticalBox();
  Box c3 = Box.createVerticalBox();
  Box c4 = Box.createVerticalBox();


  boxes[0] = Box.createVerticalBox();
  boxes[1] = Box.createVerticalBox();

  
  for (int i=0; i&lt;SIZE; i++)
  {
  	boxes[0].add(Box.createRigidArea (new Dimension(12,8)));
  	boxes[0].add(new JButton("boxes[0]: "+i));
  }	
  	
  for (int i=0; i&lt;SIZE; i++)
  {
  	boxes[1].add(Box.createRigidArea (new Dimension(12,8)));
  	boxes[1].add(new JButton("boxes[1]: "+i));
  }
  
       	
  
  c1.add(lValor1);
  c1.add(boxes[0]);
  c.add(c1);
  c2.add(campo, (new Dimension(12,8)));
  c.add(c2);
  c3.add(lValor2);
  c3.add(boxes[1]);
  c.add(c3);
  c4.add(campo2, (new Dimension(12,8)));
  c.add(c4);
  
 
  setSize( 450, 400 );
  show();

}

public static void main( String args[] )
{

MenorCaminho app = new MenorCaminho();

  app.addWindowListener(
     new WindowAdapter() {
        public void windowClosing( WindowEvent e )
        {
           System.exit( 0 );
        }
     }
  );

}
}

1 Resposta

S

faz o seguinte, coloca esse código na ação de um botao:

JTextArea textArea = new JTextArea();
frame.getContentPane.add(textArea);
Criado 27 de maio de 2004
Ultima resposta 27 de mai. de 2004
Respostas 1
Participantes 2