//RandomStars.java import java.awt.*; import javax.swing.*; public class RandomStars { //public void init() { public static void main(String[] argv) { String input; int rows, cols; int percent; input = JOptionPane.showInputDialog("Enter #rows (height)"); rows = Integer.parseInt(input); input = JOptionPane.showInputDialog("Enter #columns (width)"); cols = Integer.parseInt(input); input = JOptionPane.showInputDialog("Enter percentage"); percent = Integer.parseInt(input); JTextArea starstextarea = new JTextArea(rows,cols+1); //optional: rows,cols starstextarea.setFont( new Font("Courier",Font.BOLD,18) ); JScrollPane starsscrollpane = new JScrollPane(starstextarea); for (int row=1; row<=rows; row++) { for (int col=1; col<=cols; col++) if (Math.random() < percent/100.0) starstextarea.append(""+(char)2588); else starstextarea.append(" "); starstextarea.append("\n"); } JOptionPane.showMessageDialog(null, starsscrollpane, "Random Stars", JOptionPane.PLAIN_MESSAGE); } }