|
| 1 | +// GUI Ex 10: TestDraw.java for inherited classes. |
| 2 | + |
| 3 | +import java.awt.BorderLayout; |
| 4 | +import javax.swing.JFrame; |
| 5 | +import javax.swing.JLabel; |
| 6 | +import javax.swing.JOptionPane; |
| 7 | + |
| 8 | +public class TestDraw |
| 9 | +{ |
| 10 | + public static void main(String[] args) |
| 11 | + { |
| 12 | + int i = Integer.parseInt( |
| 13 | + JOptionPane.showInputDialog( |
| 14 | + "How many shapes do you want?")); |
| 15 | + while (i < 1) { |
| 16 | + i = Integer.parseInt( |
| 17 | + JOptionPane.showInputDialog( |
| 18 | + "Number must be 1 or greater.")); |
| 19 | + } |
| 20 | + |
| 21 | + DrawPanel panel = new DrawPanel(i); |
| 22 | + JFrame app = new JFrame(); |
| 23 | + JLabel count = new JLabel( |
| 24 | + String.format("Lines: %d, Rectangles: %d, Ovals: %d", |
| 25 | + panel.getLinesNum(), panel.getRectsNum(), panel.getOvalsNum())); |
| 26 | + |
| 27 | + app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 28 | + app.add(panel); |
| 29 | + app.add(count, BorderLayout.SOUTH); |
| 30 | + app.setSize(300, 300); |
| 31 | + app.setVisible(true); |
| 32 | + } |
| 33 | +} // end class TestDraw |
| 34 | + |
| 35 | + |
| 36 | +/************************************************************************** |
| 37 | + * (C) Copyright 1992-2014 by Deitel & Associates, Inc. and * |
| 38 | + * Pearson Education, Inc. All Rights Reserved. * |
| 39 | + * * |
| 40 | + * DISCLAIMER: The authors and publisher of this book have used their * |
| 41 | + * best efforts in preparing the book. These efforts include the * |
| 42 | + * development, research, and testing of the theories and programs * |
| 43 | + * to determine their effectiveness. The authors and publisher make * |
| 44 | + * no warranty of any kind, expressed or implied, with regard to these * |
| 45 | + * programs or to the documentation contained in these books. The authors * |
| 46 | + * and publisher shall not be liable in any event for incidental or * |
| 47 | + * consequential damages in connection with, or arising out of, the * |
| 48 | + * furnishing, performance, or use of these programs. * |
| 49 | + *************************************************************************/ |
0 commit comments