/************************************************** * Andrew Woodruff woodruff@cats.ucsc.edu * * SlugDiplomacy * * cmps115 * **************************************************/ import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.*; import java.io.*; //import java.util.*; public class Diplomacy extends Applet implements ActionListener, Runnable { Image map_Image; MediaTracker image_Tracker; Thread image_Thread = null; List teams_List = new List(); Checkbox team1_Checkbox = new Checkbox(); Checkbox team2_Checkbox = new Checkbox(); Checkbox team3_Checkbox = new Checkbox(); Checkbox team4_Checkbox = new Checkbox(); Checkbox team5_Checkbox = new Checkbox(); Button selectAll_Button = new Button("Select All"); Button send_Button = new Button("Send"); TextField chat_TextField = new TextField(); TextArea messages_TextArea = new TextArea("",1,1,1); TextArea moves_TextArea = new TextArea("",1,1,1); Label action1_Label = new Label("Select an Army", 1); Choice action1_Choice = new Choice(); List action1_List = new List(); Label action2_Label = new Label("", 1); Choice action2_Choice = new Choice(); Label action3_Label = new Label("", 1); Choice action3_Choice = new Choice(); Label action4_Label = new Label("", 1); Choice action4_Choice = new Choice(); Label action5_Label = new Label("", 1); Choice action5_Choice = new Choice(); Button done_Button = new Button("Done"); Button endTurn_Button = new Button("End Turn"); public void init() { connectToServer(); createGUI(); } public void connectToServer() { } public void createGUI() { setBackground(Color.lightGray); setLayout(null); image_Tracker = new MediaTracker(this); map_Image = this.getImage(getDocumentBase(), "finalmap.jpg"); // add image to tracker, assign an ID image_Tracker.addImage(map_Image, 0); action1_Label.setBounds(10,140,120,15); action1_Choice.setBounds(10,155,120,15); action1_List.setBounds(10,155,120,45); action2_Label.setBounds(10,185,120,15); action2_Choice.setBounds(10,200,120,15); action3_Label.setBounds(10,235,120,15); action3_Choice.setBounds(10,250,120,15); action4_Label.setBounds(10,280,120,15); action4_Choice.setBounds(10,295,120,15); action1_List.setVisible(false); action2_Label.setVisible(false); action2_Choice.setVisible(false); action3_Label.setVisible(false); action3_Choice.setVisible(false); action4_Label.setVisible(false); action4_Choice.setVisible(false); action5_Label.setVisible(false); action5_Choice.setVisible(false); done_Button.setBounds(5,350,60,25); endTurn_Button.setBounds(70,350,60,25); team1_Checkbox.setBounds(13,16,15,15); team2_Checkbox.setBounds(13,32,15,15); team3_Checkbox.setBounds(13,48,15,15); team4_Checkbox.setBounds(13,64,15,15); team5_Checkbox.setBounds(13,80,15,15); team1_Checkbox.setEnabled(false); team2_Checkbox.setEnabled(false); team3_Checkbox.setEnabled(false); team4_Checkbox.setEnabled(false); team5_Checkbox.setEnabled(false); selectAll_Button.setBounds(40,105,60,25); selectAll_Button.addActionListener(this); teams_List.setBounds(35,15,80,85); teams_List.setMultipleMode(true); send_Button.setBounds(330,530,60,25); chat_TextField.setBounds(10,530,310,25); messages_TextArea.setBounds(10,425,380,100); moves_TextArea.setBounds(425,425,380,130); send_Button.addActionListener(this); moves_TextArea.setEditable(false); messages_TextArea.setEditable(false); messages_TextArea.setBackground(Color.white); moves_TextArea.setBackground(Color.white); done_Button.setEnabled(false); done_Button.addActionListener(this); endTurn_Button.setEnabled(false); endTurn_Button.addActionListener(this); add(chat_TextField); chat_TextField.requestFocus(); add(send_Button); add(done_Button); add(endTurn_Button); add(selectAll_Button); add(team1_Checkbox); add(team2_Checkbox); add(team3_Checkbox); add(team4_Checkbox); add(team5_Checkbox); add(teams_List); add(messages_TextArea); add(moves_TextArea); add(action1_Label); add(action1_Choice); add(action1_List); add(action2_Label); add(action2_Choice); add(action3_Label); add(action3_Choice); add(action4_Label); add(action4_Choice); add(action5_Label); add(action5_Choice); repaint(); } public void start() { // if(image_Thread == null) // { image_Thread = new Thread(this); image_Thread.start(); // } } public void stop() { if((image_Thread != null) && image_Thread.isAlive()) image_Thread.stop(); image_Thread = null; } public void run() { try { image_Tracker.waitForID(0); } catch(InterruptedException e) { System.out.println("Image Tracker Error: " + e); return; } repaint(); } public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); String message; if(command.equals("Send")) { System.out.println("Send"); message = chat_TextField.getText(); chat_TextField.setText(""); messages_TextArea.append(message + "\n"); } else if(command.equals("Select All")) { System.out.println("Select All"); teams_List.select(1); teams_List.select(2); teams_List.select(3); teams_List.select(4); teams_List.select(5); } else if(command.equals("Done")) { System.out.println("Done"); } else if(command.equals("End Turn")) { System.out.println("End Turn"); } else { System.out.println("Error, Unknown Command..."); } } public void paint(Graphics g) { g.setColor(Color.black); g.drawLine(10,410,800,410); g.drawLine(410,410,410,570); g.drawImage(map_Image,140,15,null); } public void update(Graphics g) { paint(g); } public void destroy() { map_Image.flush(); } }