Á͘ÿŒ ÿ‚Ý…‹Ÿ‹ ÿÁ̓ ̓͂— ÔƒÁÍ ÅŠ‚‹
01 import javax.swing.*;
02 import javax.swing.text.*;
03
04 import java.awt.*;
05 import java.awt.event.*;
06
07 import com.holub.ui.User_interface;
08 import com.holub.ui.AncestorAdapter;
09 import com.holub.ui.Form;
10 import com.holub.tools.Std;
11
12 public class Employee implements User_interface
13 {
14 private static Form form = new Form();
15 static
16 { form.add_field( new JLabel ("Name:"),
17 new Rectangle ( 0, 0, 75, 20 ) );
18 // x y width height
19
20 form.add_field( "Employee", "name",
21 new Rectangle ( 75, 0, 200, 20 ) );
22
23 form.add_field( new JLabel ("Salary:"),
24 new Rectangle ( 0, 30, 75, 20 ) );
25
26 form.add_field( "Employee", "salary",
27 new Rectangle ( 75, 30, 200, 20 ) );
28 }
28 //------------------------------------------------------------
20
31 private double salary = 1000000000.0; // works for Microsoft
32 private Document name = new PlainDocument();
33
34 //------------------------------------------------------------
35 public JComponent visual_proxy( String attribute )
36 { JComponent proxy = null;
37
38 if( attribute.equals("salary") )
39 { proxy = new JLabel( "" + salary );
40 }
41 else if( attribute.equals("name") )
42 { proxy = new JTextField( name, null, 0 );
43 }
44 else
45 { Std.err().println("Illegal attribute requested");
46 }
47
48 return proxy;
49 }
50 //------------------------------------------------------------
51
52 public String toString()
53 { try
54 { String name_value = name.getLength() == 0
55 ? "n/a"
56 : name.getText(0,name.getLength())
57 ;
58
59 return "name=" + name_value + ", salary=" + salary;
60 }
61 catch( BadLocationException e ) // shouldn't happen
62 { throw new Error("Internal error, bad location in Employee name");
63 }
64 }
65
66 public Employee()
67 { form.attach(this); // attach attributes of current object to
68 // the form.
69
70 // could be a JDialog rather than a JFrame if you want it to
71 // be modal.
72
73 JComponent complete_form = create_initialization_form( form );
74
75 JFrame frame = new JFrame("New Employee");
76 frame.getContentPane().add( complete_form );
77 frame.pack();
78 frame.show();
79
80 // Wait for the form to shut down:
81
82 form.wait_for_close();
83 }
84
85 protected JComponent create_initialization_form( JComponent base_class_attributes )
86 { return base_class_attributes;
87 }
88
89 //------------------------------------------------------------
90 public static void main( String[] args ) throws Exception
91 { Employee bill = new Employee();
92 Std.out().println( bill.toString() );
93 System.exit(0);
94 }
95 }