//RandomStars.java import java.awt.*; import javax.swing.*; public class RandomTriangles { //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(10,60); //optional: rows,cols starstextarea.setFont( new Font("Courier",Font.BOLD,18) ); JScrollPane starsscrollpane = new JScrollPane(starstextarea); int x1, x2, x3, y1, y2, y3; x1 = (int)(Math.random()*100); y1 = (int)(Math.random()*100); x2 = (int)(Math.random()*100); y2 = (int)(Math.random()*100); x3 = (int)(Math.random()*100); y3 = (int)(Math.random()*100); starstextarea.append("("+x1+","+y1+")\n"); starstextarea.append("("+x2+","+y2+")\n"); starstextarea.append("("+x3+","+y3+")\n"); double d12, d23, d13; d12 = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); d23 = Math.sqrt((x2-x3)*(x2-x3) + (y2-y3)*(y2-y3)); d13 = Math.sqrt((x1-x3)*(x1-x3) + (y1-y3)*(y1-y3)); starstextarea.append("d12= "+d12+"\n"); starstextarea.append("d23= "+d23+"\n"); starstextarea.append("d13= "+d13+"\n"); JOptionPane.showMessageDialog(null, starsscrollpane, "Random Stars", JOptionPane.PLAIN_MESSAGE); } }