import javax.swing.*; import java.awt.event.*; import java.awt.event.ActionEvent.*; import java.awt.*; import java.util.*; class ChatFrame extends JFrame implements ActionListener,CommListener,CommMPListener { protected JTextField input; protected JTextArea output; protected CommMessage com; protected Vector party; protected String args_0; protected String args_1; public ChatFrame(String args[]) { super(); args_0 = args[0]; args_1 = args[1]; party = new Vector(); input = new JTextField(20); output = new JTextArea(20,20); output.setLineWrap(true); output.setWrapStyleWord(false); input.addActionListener(this); getContentPane().setLayout(new FlowLayout()); getContentPane().add(input); getContentPane().add(output); } //本当はaddParty面倒なのでそのまま、必ず直す予定です public void setParty(CommMessage_Proxy proxy) { this.party.addElement(proxy); } public void take(CommMessage_Proxy m) { System.out.println("Get"); setParty(m); } //giveは間違い、相手のアドレスが必要 public void give(CommMessage_Proxy m) { ; } public void start(){System.out.println("start");} public void end(){System.out.println("end");} public void connect(String ad) { CommMP_Proxy mp = new CommMP_Proxy(ad+"ref"); System.out.println(ad+"ref"); mp.take(new CommMessage_Proxy("horb://localhost:"+args_1+"/"+args_0)); setParty(new CommMessage_Proxy(ad)); } public void output(Message d) { int i= 0; while(i < party.size()) { ((CommMessage_Proxy)party.get(i)).input(d); i++; } } public void input(Message d) { if(output !=null) { output.append(d.Out()); } } public void actionPerformed(ActionEvent e) { if( party.size() != 0) { output(new Message(input.getText())); } else{ connect(input.getText()); } } }