|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object becker.robots.RobotUIComponents
public class RobotUIComponents
A factory object that provides the major user interface components, making customized user interfaces easy to create.
For example, CityFrame
has the controls on the left side
rather than the right. Other, less trivial changes, are also possible.
import becker.robots.*; import becker.robots.Robot; import javax.swing.*; import java.awt.*; public class CityFrame { private JFrame frame; private RobotUIComponents ui; public CityFrame(City model, int firstVisibleStreet, int firstVisibleAvenue, int numVisibleStreets, int numVisibleAvenues) { super(); this.frame = new JFrame("Robots: Learning to program with Java"); // this.frame.addWindowListener(new WindowCloser()); this.ui = new RobotUIComponents(model, firstVisibleStreet, firstVisibleAvenue, numVisibleStreets, numVisibleAvenues); this.frame.setJMenuBar(ui.getMenuBar()); JPanel view = new JPanel(new BorderLayout()); CityView sp = ui.getCityView(); view.add(sp, BorderLayout.CENTER); view.add(ui.getControlPanel(), BorderLayout.WEST); this.frame.setContentPane(view); this.frame.pack(); this.frame.repaint(); this.frame.setVisible(true); } public static void main(String[] args) { City.showFrame(false); // prevent City from showing its own frame City c = new City(-1, -2, 4, 5); Robot r = new Robot(c, 1, 1, Direction.EAST, 0); CityFrame cf = new CityFrame(c, -1, -2, 4, 5); r.move(); r.move(); } }
Constructor Summary | |
---|---|
RobotUIComponents(City model)
Create the components for a default view of the city using the defaults in becker.robots.ini for the visible streets and avenues and intersection size. |
|
RobotUIComponents(City model,
int leftAve,
int topStr,
int width,
int height)
Create the components to view a specified section of the city. |
|
RobotUIComponents(City model,
int leftAve,
int topStr,
int width,
int height,
int simSize)
Create the components to view a specified section of the city. |
Method Summary | |
---|---|
CityView |
getCityView()
Get a component that shows the city and the city's scrollbars. |
JPanel |
getControlPanel()
Get a panel grouping the start/stop button and speed slider together |
JMenuBar |
getMenuBar()
Get the menu bar for the user interface. |
JSlider |
getSpeedSlider()
Get a slider to control the speed of the animation. |
JButton |
getStartStopButton()
Get a button to start and stop the animation |
JPanel |
getUI()
Get a panel grouping the city's view with the traditional control panel. |
JSlider |
getZoom()
Get a component that causes the view to zoom in on the city |
void |
quitApp()
Quit the application. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RobotUIComponents(City model)
model
- the city to showpublic RobotUIComponents(City model, int leftAve, int topStr, int width, int height, int simSize)
model
- the city to showleftAve
- the leftmost avenue to showtopStr
- the topmost street to showwidth
- the number of avenues to showheight
- the number of streets to showsimSize
- the size, in pixels, of each sim (ie: the size of one intersection)public RobotUIComponents(City model, int leftAve, int topStr, int width, int height)
model
- the city to showleftAve
- the leftmost avenue to showtopStr
- the topmost street to showwidth
- the number of avenues to showheight
- the number of streets to showMethod Detail |
---|
public JSlider getSpeedSlider()
public JButton getStartStopButton()
public CityView getCityView()
public JSlider getZoom()
public JPanel getControlPanel()
public JPanel getUI()
public JMenuBar getMenuBar()
public void quitApp()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |