1 ネットワークを通じて送信する可能性のあるコマンド文字列とその働きを書いてください。 2 26,73行目のcatchで補足される可能性のある例外と、その発生箇所と原因を書いてください。 2番は大変なので1番だけの解答でも大丈夫です。 よろしくお願いします。 1: import java.awt.event.*; 2: import java.awt.*; 3: import java.io.*; 4: import java.net.*; 5: 6: public class Test72 { 7: private MyCanvas c; 8: private BufferedWriter bw; 9: private BufferedReader br; 10: 11: public static void main( String[] args ) { 12: Test72 t72 = new Test72(); 13: t72.doEvent(); 14: } 15: 16: Test72(){ 17: Frame f = new Frame( "Test72" ); 18: f.setSize(640,480); 19: f.addWindowListener( new WindowAdapter() { 20: @Override public void windowClosing( WindowEvent e ) { 21: try { 22: bw.write( "quit" ); 44 23: bw.flush(); 24: bw.close(); 25: br.close(); 26: } catch( Exception e2 ) {} 27: System.exit( 0 ); 28: } 29: }); 30: c = new MyCanvas(); 31: c.addMouseListener( new MouseListener() { 32: @Override public void mouseClicked( MouseEvent e ) { 33: try { 34: bw.write( "setOval " + e.getX() + " " + e.getY() + "¥n" ); 35: bw.flush(); 36: c.setPoint( e.getX(), e.getY() ); 37: } catch( Exception e2 ) {} 38: } 39: @Override public void mouseEntered( MouseEvent e ) {} 40: @Override public void mouseExited( MouseEvent e ) {} 41: @Override public void mousePressed( MouseEvent e ) {} 42: @Override public void mouseReleased( MouseEvent e ) {} 43: }); 44: c.addMouseMotionListener( new MouseMotionListener() { 45: @Override public void mouseDragged( MouseEvent e ) { 46: try { 47: bw.write( "setOval " + e.getX() + " " + e.getY() + "¥n" ); 48: bw.flush(); 49: c.setPoint( e.getX(), e.getY() ); 50: } catch( Exception e2 ) {} 51: } 52: @Override public void mouseMoved( MouseEvent e ) {} 53: }); 54: f.add( c ); 55: f.setVisible( true ); 56: } 57: 58: public void doEvent() { 59: try { 60: InetSocketAddress socketAddress = 61: new InetSocketAddress( "localhost", 8000 ); 62: Socket socket = new Socket(); 63: socket.connect( socketAddress, 10000 ); 64: InetAddress inadr; 65: if( ( inadr = socket.getInetAddress() ) != null ){ 66: System.out.println( "Connect to " + inadr ); 67: } else { 68: System.out.println( "Connection failed" ); 69: System.exit( 0 ); 70: } 71: bw = new BufferedWriter( new OutputStreamWriter( socket.getOutputStream() ) ); 72: br = new BufferedReader( new InputStreamReader( socket.getInputStream() ) ); 73: } catch( Exception e ) {} 74: } 75: }
↧