/** * Title: GPS Simulator * Copyright: Copyright (c) 2002 * Company: University of Oregon Computer Science Dept. * * @author Jason Prideaux * @version 1.0 * */ package chat; import transport.*; import transport.protocol.*; import java.awt.*; import java.awt.event.*; import java.util.Date; import java.io.*; public class ChatUI extends Frame implements SocketReceiverListener{ Image background; Label sen = new Label("Message to send:"); Label rcv = new Label("Received messages:"); TextField rcvfld = new TextField(); TextField sendfld = new TextField(); Button send = new Button("Send");; int port; //Constructs a UI which is used by 'widget' and displays info on 'user' public ChatUI(int port){ super("SimChat"); setSize(240,300); this.port = port; setLocation(0,0); setLayout(null); //parent = widget; this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { System.exit(0); } }); Toolkit tool = Toolkit.getDefaultToolkit(); //gotta love tool try{ byte[] b = new byte[26000]; FileInputStream fis = new FileInputStream("files/images/ipaq.jpg"); fis.read(b); background = tool.createImage(b); }catch(Exception e){} Panel panel = new Panel(null); panel.setBounds( 0, 23, 240, 280); if(true){ setSize(370,603); panel.setBounds( 63, 161, 240, 280); } send.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { send_actionPerformed(e); } }); rcvfld.setBounds( 30,75,200,20 ); rcv.setBounds( 10,50,220,20 ); sen.setBounds( 10,120,220,20 ); sendfld.setBounds( 30,145,200,20 ); send.setBounds( 140,200,80,20 ); panel.add(rcv); panel.add(rcvfld); panel.add(sen); panel.add(sendfld); panel.add(send); add(panel); SocketReceiver sr = new SocketReceiver(this, port); sr.start(); this.setVisible(true); } //Constructor /* ====================================================================== */ /** This * * @param g * */ public void paint(Graphics g) { // paint any space not covered super.paint(g); //int compWidth = getWidth(); //int compHeight = getHeight(); //int imageWidth, imageHeight; // If we have a valid width and height for the // background image, draw it. g.drawImage(background,0,23,this); } //method: paintComponent public void send_actionPerformed(ActionEvent e){ Message msg = new MulticastMessage(sendfld.getText(), port,3 ); SocketSender ss = new SocketSender(msg); ss.start(); } public void incomingMessage(Message msg){ if( msg instanceof MulticastMessage ){ rcvfld.setText( ((MulticastMessage)msg).getMessage() ); } } } //class: