// Processed by NMI's Java Code Viewer 4.8.2 © 1997-2000 B. Lemaire // Website: http://njcv.htmlplanet.com E-mail: info@njcv.htmlplanet.com // Copy registered to Evaluation Copy // Source File Name: ToolBarPanel.java import java.awt.*; import java.io.File; class ToolBarPanel extends Panel { Frame target; private Toolkit toolkit; private MediaTracker tracker; private ImageButton toolBarImageButtons[]; private Graphics tempGraphics[][]; private Image toolBarImages[][]; private Image strip; private Font font; private String message[] = { "Connect", "Disconnect", "Start Game", "Stop Game", "Clear Playboard", "Save Game", "Load Game", "Kick Player", "Save Messages", "Clear Messages", "Help" }; private ButtonDescription details; private boolean panelCreated; void ToolBarPanel_GotFocus(Event event) { } public ToolBarPanel(Frame frame) { toolkit = getToolkit(); toolBarImageButtons = new ImageButton[11]; tempGraphics = new Graphics[11][2]; toolBarImages = new Image[11][2]; font = new Font("Dialog", 0, 8); details = new ButtonDescription(); panelCreated = false; setLayout(null); resize(500, 32); target = frame; setBackground(Color.lightGray); add(details); } public void disableButton(int i) { toolBarImageButtons[i].disableButton(); } public void enableButton(int i) { toolBarImageButtons[i].enableButton(); } public void paint(Graphics g) { if(!panelCreated) { panelCreated = true; for(int i = 0; i < 11; i++) { tempGraphics[i][0] = null; toolBarImages[i][0] = createImage(20, 19); tempGraphics[i][1] = null; toolBarImages[i][1] = createImage(20, 19); } loadImages(); createButtons(); } g.setColor(Color.lightGray); g.draw3DRect(-1, 0, size().width + 1, 31, true); } public void update(Graphics g) { paint(g); } public void loadImages() { tracker = new MediaTracker(this); strip = toolkit.getImage("images" + File.separator + "toolbar.jpg"); tracker.addImage(strip, 0); try { tracker.waitForAll(); } catch(InterruptedException _ex) { } toolkit = null; } public void createButtons() { for(int i = 0; i < 11; i++) { tempGraphics[i][0] = toolBarImages[i][0].getGraphics(); tempGraphics[i][0].clipRect(0, 0, 20, 19); tempGraphics[i][0].drawImage(strip, -i * 20, 0, this); tempGraphics[i][1] = toolBarImages[i][1].getGraphics(); tempGraphics[i][1].clipRect(0, 0, 20, 19); tempGraphics[i][1].drawImage(strip, -i * 20, -19, this); } toolBarImageButtons[0] = new ImageButton(toolBarImages[0][0], toolBarImages[0][1], 5, 5, Color.gray, this); toolBarImageButtons[1] = new ImageButton(toolBarImages[1][0], toolBarImages[1][1], 28, 5, Color.gray, this); toolBarImageButtons[1].disableButton(); toolBarImageButtons[2] = new ImageButton(toolBarImages[2][0], toolBarImages[2][1], 58, 5, Color.gray, this); toolBarImageButtons[2].disableButton(); toolBarImageButtons[3] = new ImageButton(toolBarImages[3][0], toolBarImages[3][1], 81, 5, Color.gray, this); toolBarImageButtons[3].disableButton(); toolBarImageButtons[4] = new ImageButton(toolBarImages[4][0], toolBarImages[4][1], 104, 5, Color.gray, this); toolBarImageButtons[5] = new ImageButton(toolBarImages[5][0], toolBarImages[5][1], 134, 5, Color.gray, this); toolBarImageButtons[5].disableButton(); toolBarImageButtons[6] = new ImageButton(toolBarImages[6][0], toolBarImages[6][1], 157, 5, Color.gray, this); toolBarImageButtons[6].disableButton(); toolBarImageButtons[7] = new ImageButton(toolBarImages[7][0], toolBarImages[7][1], 187, 5, Color.gray, this); toolBarImageButtons[7].disableButton(); toolBarImageButtons[8] = new ImageButton(toolBarImages[8][0], toolBarImages[8][1], 217, 5, Color.gray, this); toolBarImageButtons[9] = new ImageButton(toolBarImages[9][0], toolBarImages[9][1], 240, 5, Color.gray, this); toolBarImageButtons[10] = new ImageButton(toolBarImages[10][0], toolBarImages[10][1], 270, 5, Color.gray, this); strip = null; for(int j = 0; j < 11; j++) { add(toolBarImageButtons[j]); toolBarImages[j][0] = null; tempGraphics[j][0] = null; toolBarImages[j][1] = null; tempGraphics[j][1] = null; } } public boolean handleEvent(Event event) { if(event.target instanceof ImageButton) { if(event.id == 504) { for(int i = 0; i < 11; i++) { if(event.target != toolBarImageButtons[i]) continue; details.move(toolBarImageButtons[i].location().x + 30, 8); details.show(message[i]); break; } return true; } if(event.id == 505) { details.hide(); return true; } if(event.id == 1001) { details.hide(); for(int j = 0; j < 11; j++) { if(event.target != toolBarImageButtons[j]) continue; switch(j) { case 0: // '\0' (new ClientOrServer(target, true)).show(); break; case 1: // '\001' target.handleEvent(new Event(new MenuItem(""), 1001, "Disconnect")); break; case 2: // '\002' target.handleEvent(new Event(new MenuItem(""), 1001, "Start Game")); break; case 3: // '\003' target.handleEvent(new Event(new MenuItem(""), 1001, "Stop Game")); break; case 4: // '\004' target.handleEvent(new Event(new MenuItem(""), 1001, "Clear Playboard")); break; case 5: // '\005' target.handleEvent(new Event(new MenuItem(""), 1001, "Save Game")); break; case 6: // '\006' target.handleEvent(new Event(new MenuItem(""), 1001, "Load Game")); break; case 7: // '\007' target.handleEvent(new Event(new MenuItem(""), 1001, "Kick Player")); break; case 8: // '\b' target.handleEvent(new Event(new MenuItem(""), 1001, "Save Messages")); break; case 9: // '\t' target.handleEvent(new Event(new MenuItem(""), 1001, "Clear Messages")); break; case 10: // '\n' target.handleEvent(new Event(new MenuItem(""), 1001, "Help")); break; } break; } return true; } } if(event.target == this && event.id == 1004) { ToolBarPanel_GotFocus(event); return true; } else { return false; } } public synchronized void resize(int i, int j) { super.resize(i, 32); } public synchronized void reshape(int i, int j, int k, int l) { super.reshape(i, j, k, 32); } }