2. getContentPane().add(drawingToolToolBar, BorderLayout.EAST);
getContentPane().add(new DrawPanel(this),
BorderLayout.CENTER);
}
// creating drawing tool menu
private JMenu createDrawingToolMenu() {
JMenu drawingToolMenu = new JMenu("Drawing Tool");
for (int i = 0; i < theFigKinds.length; i++) {
// create a menu item for this figure kind
JMenuItem item = new JMenuItem(theFigKinds[i].getName());
// set the action listener
item.addActionListener(new ToolSelector(theFigKinds[i]));
// add the item to the menu
drawingToolMenu.add(item);
}
return drawingToolMenu;
}
// creating menu tool bar
JToolBar createDrawingToolToolBar() {
JToolBar drawingToolToolBar = new JToolBar(JToolBar.VERTICAL);
for (int i = 0; i < theFigKinds.length; i++) {
JButton aButton = new JButton(theFigKinds[i].getIcon(16));
aButton.addActionListener(new ToolSelector(theFigKinds[i]));
drawingToolToolBar.add(aButton);
}
return drawingToolToolBar;
}
//creating color menu
private JMenu createColorMenu() {
JMenu colorMenu = new JMenu("Colors");
JMenuItem setInteriorColor
= new JMenuItem("Set Interior Color");
setInteriorColor.addActionListener(new SetInteriorColor());
colorMenu.add(setInteriorColor);
JMenuItem setBorderColor = new JMenuItem("Set Border Color");
setBorderColor.addActionListener(new SetBorderColor());
3. colorMenu.add(setBorderColor);
return colorMenu;
}
public Drawable getSelectedFig() {
return selectedFig;
}
public static void main(String args[]) {
DrawApp drawApp = new DrawApp(args);
drawApp.setVisible(true);
}
// Inner Classes
private class ToolSelector implements ActionListener {
// Data Fields
private Drawable desiredFig;
// Constructor
public ToolSelector(Drawable desiredFig) {
this.desiredFig = desiredFig;
}
// Methods
@Override
public void actionPerformed(ActionEvent e) {
selectedFig = desiredFig;
}
}
private class SetInteriorColor implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
presentInteriorrColor
= JColorChooser.showDialog(
DrawApp.this,
"Select Interior Color",
presentInteriorrColor);
for (int i = 0; i < theFigKinds.length; i++) {
theFigKinds[i].setInteriorColor(presentInteriorrColor);
}
repaint();
5. JMenu colorMenu = createColorMenu();
JMenuBar menuBar = new JMenuBar();
menuBar.add(colorMenu);
menuBar.add(drawingToolMenu);
setJMenuBar(menuBar);
getContentPane().add(drawingToolToolBar, BorderLayout.EAST);
getContentPane().add(new DrawPanel(this),
BorderLayout.CENTER);
}
// creating drawing tool menu
private JMenu createDrawingToolMenu() {
JMenu drawingToolMenu = new JMenu("Drawing Tool");
for (int i = 0; i < theFigKinds.length; i++) {
// create a menu item for this figure kind
JMenuItem item = new JMenuItem(theFigKinds[i].getName());
// set the action listener
item.addActionListener(new ToolSelector(theFigKinds[i]));
// add the item to the menu
drawingToolMenu.add(item);
}
return drawingToolMenu;
}
// creating menu tool bar
JToolBar createDrawingToolToolBar() {
JToolBar drawingToolToolBar = new JToolBar(JToolBar.VERTICAL);
for (int i = 0; i < theFigKinds.length; i++) {
JButton aButton = new JButton(theFigKinds[i].getIcon(16));
aButton.addActionListener(new ToolSelector(theFigKinds[i]));
drawingToolToolBar.add(aButton);
}
return drawingToolToolBar;
}
//creating color menu
private JMenu createColorMenu() {
JMenu colorMenu = new JMenu("Colors");
JMenuItem setInteriorColor
6. = new JMenuItem("Set Interior Color");
setInteriorColor.addActionListener(new SetInteriorColor());
colorMenu.add(setInteriorColor);
JMenuItem setBorderColor = new JMenuItem("Set Border Color");
setBorderColor.addActionListener(new SetBorderColor());
colorMenu.add(setBorderColor);
return colorMenu;
}
public Drawable getSelectedFig() {
return selectedFig;
}
public static void main(String args[]) {
DrawApp drawApp = new DrawApp(args);
drawApp.setVisible(true);
}
// Inner Classes
private class ToolSelector implements ActionListener {
// Data Fields
private Drawable desiredFig;
// Constructor
public ToolSelector(Drawable desiredFig) {
this.desiredFig = desiredFig;
}
// Methods
@Override
public void actionPerformed(ActionEvent e) {
selectedFig = desiredFig;
}
}
private class SetInteriorColor implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
presentInteriorrColor
= JColorChooser.showDialog(
DrawApp.this,
"Select Interior Color",
7. presentInteriorrColor);
for (int i = 0; i < theFigKinds.length; i++) {
theFigKinds[i].setInteriorColor(presentInteriorrColor);
}
repaint();
}
}
}