View Single Post
  #1 (permalink)  
Old 07-16-2007, 05:54 PM
paul paul is offline
Member
 
Join Date: Jul 2007
Posts: 26
paul is on a distinguished road
Help with JTextArea, resize windows
How can I get the JTextArea to display without having to resize the window?
And is there a way I can position it?
Code:
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 ); } }
Code:
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
Reply With Quote
Sponsored Links