How can I get the
JTextArea to display without having to resize the window?
And is there a way I can position it?
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class Oval extends JPanel {
public void paintComponent( Graphics g ) {
super.paintComponent( g );
Random randomNumbers = new Random();
int width = 1 + randomNumbers.nextInt( 200 );
int height = 1 + randomNumbers.nextInt( 200 );
double area = Math.PI * (width/2) * (height/2);
String text = "Area = " + area + "\n";
JTextArea textArea1 = new JTextArea( text, 10, 10 );
add (textArea1);
//( int x, int y, int width, int height )
g.drawOval( 10, 10, width, height );
}
}
import javax.swing.JFrame;
public class OvalTest {
public static void main(String args[]) {
JFrame frame = new JFrame( "Oval of random size" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setSize( 600, 210 );
Oval oval = new Oval();
frame.add(oval);
frame.setVisible( true );
}
}
Thanks