资源描述
ReportClass: Name: No.:CourseJava Programming LanguageExperimentNameIntegrated ProgrammingTypeVerifyDemoIntegratedDesignTeacherScore1. Goal of this experiment (1)IO usage. (2)Learning programming. (3)Independent test and debug.2. Procedures (1)IO usage: Enter the following procedures. TestHow to use an exception here. (2)One applet Enter the following procedures. Add to an html page Write the lifecycle of applet. Learn the model of awt。 (3)Use Network Enter the following procedures. Test Learn how to use the network. (4)socket programming Enter the following procedures. Test Learn how to use the network. Summary way connection network resources Learn how to use the socket to communicate.Page 2 of 103. Recording of original data or result(1)IO usagepackage test;import java.io.*;public class MakeDirectories private static void usage() System.err.println(Usage:MakeDirectories path1 .n + Creates each pathn +Usage:MakeDirectories -d path1 .n +Deletes each pathn +Usage:MakeDirectories -r path1 path2n +Renames from path1 to path2);System.exit(1);private static void fileData(File f) System.out.println(Absolute path: + f.getAbsolutePath() +n Can read: + f.canRead() +n Can write: + f.canWrite() +n getName: + f.getName() +n getParent: + f.getParent() +n getPath: + f.getPath() +n length: + f.length() +n lastModified: + f.lastModified();if(f.isFile()System.out.println(Its a file);else if (f.isDirectory()System.out.println(Its a directory);public static void main(String args) if(args.length 1) usage();if(args0.equals(-r) if(args.length != 3) usage();File old = new File(args1);File rname = new File(args2);old.renameTo(rname);fileData(old);fileData(rname);return; / Exit mainint count = 0;boolean del = false;if(args0.equals(-d) count+;del = true;count-;while(+count args.length) File f = new File(argscount);if(f.exists() System.out.println(f + exists);if(del) System.out.println(deleting. + f);f.delete(); else / Doesnt existif(!del) f.mkdirs();System.out.println(created + f);fileData(f);You can determine whether a file exists, an exception is thrown when there is no(2) One applet:package test;import java.awt.*;import java.awt.event.*;import java.applet.Applet;public class Ex4_1 extends Applet implements ActionListener Label label1 = new Label(+);Label label2 = new Label(=);TextField field1 = new TextField(6);TextField field2 = new TextField(6);TextField field3 = new TextField(6);Button button1 = new Button(add);public void init() /initializeadd(field1);add(label1);add(field2);add(label2);add(field3);add(button1);button1.addActionListener(this);public void actionPerformed(ActionEvent e) int x = Integer.parseInt(field1.getText() + Integer.parseInt(field2.getText();field3.setText(Integer.toString(x);Insert title here(3)Use Network:package test;import .*;import java.io.*;public class URLTest public static void main(String args) URL url = null;InputStream is;tryurl=new URL();is = url.openStream();int c;try while(c = is.read() != -1)System.out.print(char)c);catch(IOException e) finally is.close();catch(MalformedURLException e) e.printStackTrace();catch(IOException e) e.printStackTrace();System.out.println(file name: + url.getFile(); System.out.println(host name: + url.getHost(); System.out.println(port no.: + url.getPort(); System.out.println(protocol name: + url.getProtocol();(4)socket programming:package test;import .*;import java.io.*;public class URLReader public static void main(String args) throws Exception URL web = new URL( BufferedReader in = new BufferedReader(new InputStreamReader(web.openStream();String inputLine;while (inputLine = in.readLine() != null) System.out.println(inputLine);in.close();4. Result and analysis(1)IO usage(2) One applet:1. applet lifecycle: Initialize (corresponding init method), runs (corresponding to the start method), the end of the run (corresponding stop method), destruction (corresponding to destroy method).2. awt the model: awt using mvc oop in the classic model, that model is responsible for storing data, view responsible for the display, controller responsible for the control view of the display according to the mode. Model components include Tree Model, Button Model more.(3)Use Network:(4)socket programmingSteps: first create a URL object by a unique URL for the resource, and then get the URL from the input stream InputStream object to read.Socket programming is about a ServerSocket and Socket to connect and transfer dataSignature:Date:7
展开阅读全文