1 29 30 package nextapp.echo2.testapp.thousandmonkeys.factories; 31 32 import nextapp.echo2.app.Border; 33 import nextapp.echo2.app.Color; 34 import nextapp.echo2.app.Component; 35 import nextapp.echo2.app.Button; 36 import nextapp.echo2.app.Insets; 37 import nextapp.echo2.testapp.thousandmonkeys.ComponentFactory; 38 39 42 public class ButtonFactory 43 implements ComponentFactory{ 44 45 private static final Insets INSETS_10_5 = new Insets(10, 5); 46 47 private int count = 0; 48 49 52 public Component newInstance() { 53 Button button = new Button(); 54 switch ((int) (Math.random() * 3)) { 55 case 0: 56 button.setText("Button #" + ++count); 57 button.setBackground(new Color((int) (16777216 * Math.random()))); 58 break; 59 case 1: 60 button.setText("This is an example button."); 61 button.setForeground(new Color((int) (16777216 * Math.random()) & 0x7f7f7f)); 62 button.setBackground(new Color((int) (16777216 * Math.random()) | 0xb0b0b0)); 63 button.setBorder(new Border(1, new Color((int) (16777216 * Math.random()) | 0xb3b3b3), Border.STYLE_OUTSET)); 64 button.setInsets(INSETS_10_5); 65 break; 66 case 2: 67 button.setText("Initially Plain Button"); 68 break; 69 } 70 return button; 71 } 72 } 73 | Popular Tags |