1 package main;
2
3 import intellego.Intellego;
4 import util.*;
5 import interfaces.*;
6 import real.*;
7 import simworldobjects.*;
8
9 import java.awt.*;
10 import java.lang.*;
11 import java.awt.event.*;
12 import javax.swing.*;
13 import java.io.*;
14
15
20 public class InitRobotDialog extends JDialog implements ActionListener
21 {
22 private JTextField xField, zField, bField;
23 private JLabel xLabel, zLabel, bLabel;
24 private JButton OK, cancel;
25 private SimWorld world;
26 private Controller controller;
27 private SimDisplay display;
28
29
37 public void createRobot(SimWorld w, Controller c, SimDisplay d)
38 {
39 setTitle("Initialise Robot:");
40 setSize(200,135);
41 setLocation(400,400);
42 setVisible(true);
43
44 world=w;
45 controller=c;
46 display=d;
47
48 Container mainPanel=getContentPane();
49 mainPanel.setLayout(new BorderLayout(1,1));
50
51 Container bottomPanel=new Container();
52 bottomPanel.setLayout(new BorderLayout(1,1));
53
54 Container topPanel=new Container();
55 topPanel.setLayout(new BorderLayout(1,1));
56
57 Container Panel1=new Container();
58 Panel1.setLayout(new BorderLayout(1,1));
59
60 Container Panel2=new Container();
61 Panel2.setLayout(new BorderLayout(1,1));
62
63 Container Panel3=new Container();
64 Panel3.setLayout(new BorderLayout(1,1));
65
66 Container Panel4=new Container();
67 Panel4.setLayout(new FlowLayout());
68
69 xField=new JTextField("500",4);
70 zField=new JTextField("500",4);
71 bField=new JTextField("45",4);
72
73 xLabel=new JLabel("Enter X coordinate:");
74 zLabel=new JLabel("Enter Z coordinate:");
75 bLabel=new JLabel("Enter initial bearing");
76
77 (OK=new JButton("OK")).addActionListener(this);
78 (cancel=new JButton("Cancel")).addActionListener(this);
79
80 Panel1.add("West",xLabel);
81 Panel1.add("East",xField);
82 Panel2.add("West",zLabel);
83 Panel2.add("East",zField);
84 Panel3.add("West",bLabel);
85 Panel3.add("East",bField);
86 Panel4.add("South",OK);
87 Panel4.add("South",cancel);
88
89 topPanel.add("North",Panel1);
90 topPanel.add("South",Panel2);
91
92 bottomPanel.add("North",Panel3);
93 bottomPanel.add("South",Panel4);
94
95 mainPanel.add("North",topPanel);
96 mainPanel.add("South",bottomPanel);
97
98 this.show();
99
100 }
101
102
108 public void actionPerformed(ActionEvent e)
109 {
110 if (e.getSource()==OK)
111 {
112 int x=Integer.parseInt(xField.getText());
113 int z=Integer.parseInt(zField.getText());
114 int b=Integer.parseInt(bField.getText());
115
116 long X=(long)x;
117 long Z=(long)z;
118 long B=(long)b;
119
120 SimRCX rcx=new SimRCX(world, controller, 30.0,40.0,60.0,"robot",X,0.0,Z,0.0,B);
122
123 controller.initController(rcx);
125
126 world.addObject((SimObject)rcx);
128
129 display.repaint();
130
131 dispose();
132 }
133 else
134 {
135 dispose();
136 }
137 }
138 }
139