//PIpoints.java //read file of digits of PI, display as x,y points. //each coord is 3 digits of PI // drawing in JFrame import java.awt.event.*; import java.awt.*; import javax.swing.*; import java.io.*; public class PIpoints { private JFrame outputFrame; private Container container; private DrawingPanel myDrawingPanel; //***DrawingPanel is user-defined below public static void main (String[] args) { PIpoints myPIpoints = new PIpoints(); } public PIpoints() { int x, y; char c; int A[] = new int[100000]; // input = JOptionPane.showInputDialog("Max range of integers","1000000000"); // maxInt = Integer.parseInt(input); outputFrame = new JFrame(); outputFrame.setSize(1000,700); outputFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); container = outputFrame.getContentPane(); container.setLayout( new BorderLayout() ); //***create object of the customized subclass of JPanel myDrawingPanel = new DrawingPanel(); container.add( myDrawingPanel ); outputFrame.setVisible(true); File inFile; FileReader fileReader; BufferedReader bufReader; try { inFile = new File( "pi1M.txt" ); fileReader = new FileReader( inFile ); bufReader = new BufferedReader( fileReader ); for (int i=0; i'9') //skip over any newlines CRs etc c = (char)bufReader.read(); x = 10*x + (int)c-(int)'0'; } A[i] = x; for (int j=1; j<=3; j++) { c = (char)bufReader.read(); while (c<'0' || c>'9') //skip over any newlines CRs etc c = (char)bufReader.read(); y = 10*y + (int)c-(int)'0'; } A[i+1] = y; System.out.println(""+x+" "+y); } bufReader.close(); } catch (IOException e) { System.out.println( "threw an exception...deal with it..." ); } //***call of some method of the custom subclass of JPanel that calls repaint() myDrawingPanel.drawPIpoints(A); } } //*** define a subclass (of whatever name) of JPanel. class DrawingPanel extends JPanel { int A[]; //***must be this signature. //***called explicitly by the repaint method and //implicitly whenever the area is resized or uncovered. //analogous to the paint method of an applet. //all the Graphics drawing methods can be used: //drawLine, drawOval, fillOval, drawRect, fillRect, drawString, setColor, setFont... public void paintComponent( Graphics g ) { super.paintComponent( g ); //clears the drawing area. int w=getWidth(); //***width of drawing area. int h=getHeight(); //*** Try resizing the frame window. //draw some random lines for demo purposes: for (int i=0; i