//: c04:ArrayNew.java // From 'Thinking in Java, 2nd ed.' by Bruce Eckel // www.BruceEckel.com. See copyright notice in CopyRight.txt. // Creating arrays with new. // // import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.util.*; import com.bruceeckel.swing.*; import com.bruceeckel.util.*; public class ArrayNew extends JApplet { JTextArea Xout = new JTextArea(20, 50); Random rand = new Random(); public void init() { Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(new JLabel("ArrayNew!")); cp.add(new JScrollPane(Xout)); int[] a; a = new int[rand.nextInt(20)]; Xout.append( "length of a = " + a.length + "\n"); for(int i = 0; i < a.length; i++) Xout.append( "a[" + i + "] = " + a[i] + "\n"); } public static void main(String[] args) { Console.run(new ArrayNew(), 600, 400); } } ///:~