首页 技术 正文
技术 2022年11月23日
0 收藏 673 点赞 4,731 浏览 3967 个字

黑马程序员:Java基础总结



GUI&网络&IO综合开发
 
ASP.Net+Android+IO开发

.Net培训
、期待与您交流!


网络架构
C/S:Client/Server

客户端,服务端。

特点:

1,需要在客户端和服务端都需要按照编写的软件。

2,维护较麻烦。

好处:可以减轻服务端的压力,如网络游戏。

B/S:Browser/Server

浏览器 ,服务端。

1,客户端不用单独编写软件。

     因为客户端用的就是浏览器。

2,对于软件升级,只要考虑服务端即可。

弊端:所有的程序都运行在服务端,客户端的浏览器毕竟解析能力较弱。对游戏等

类 URL

类 URL 代表一个统一资源定位符,它是指向互联网“资源”的指针。 构造:  URL url = new URL(“http://192.168.1.254/myweb/demo.html?name=haha&age=30”) 方法:  String getFile()

          获取此 URL 的文件名。

String getHost()

          获取此 URL 的主机名(如果适用)。

String getPath()

          获取此 URL 的路径部分。

int getPort()

          获取此 URL 的端口号。

String getProtocol()

          获取此 URL 的协议名称。

String getQuery()

          获取此 URL 的查询部

类 URLConnection

抽象类 
URLConnection 是所有类的超类,它代表应用程序和 URL 之间的通信链接。此类的实例可用于读取和写入此 URL 引用的资源。

URLConnection openConnection()
          返回一个 URLConnection 对象,它表示到 URL 所引用的远程对象的连接。

     URL url = new URL(“http://192.168.1.254:8080/myweb/demo.html”);

URLConnection conn = url.openConnection();

          System.out.println(conn);

     

 InputStream getInputStream()
          返回从此打开的连接读取的输入流。

    

          InputStream in = conn.getInputStream();

          byte[] buf = new byte[1024];

          int len = in.read(buf);

          System.out.println(new String(buf,0,len));

演示客户端和服务端。

1,

客户端:浏览器 (telnet)

服务端:自定义。

2,

客户端:浏览器。

服务端:Tomcat服务器。

3,

客户端:自定义。(图形界面)

服务端:Tomcat服务器
import 
java.awt.*; import 
java.awt.event.*; import 
java.io.*; import 
java.net.*;
public 
class 
Ts {        
private 
Frame 

;        
private 
TextField 
tf 
;        
private 
Button 
but 
;        
private 
TextArea 
ta 
;
       
private 
Dialog 

;        
private 
Label 
lab 
;        
private 
Button 
okBut 
;
      Ts() {             init();       }
       
public 
void 
init() {              


new 
Frame(
“my window” 
);              
f
.setBounds(300, 100, 600, 500);              
f
.setLayout( 
new 
FlowLayout());
             
tf 

new 
TextField(60);
             
but 

new 
Button(
“转到”
);
             
ta 

new 
TextArea(25, 70);
             


new 
Dialog(


“提示信息-self” 

true
);              
d
.setBounds(400, 200, 240, 150);              
d
.setLayout( 
new 
FlowLayout());              
lab 

new 
Label();              
okBut 

new 
Button(
“确定”
);
             
d
.add( 
lab
);              
d
.add( 
okBut
);
             
f
.add( 
tf
);              
f
.add( 
but
);              
f
.add( 
ta
);
            myEvent();              
f
.setVisible( 
true
);       }
       
private 
void 
myEvent() {
             
okBut
.addActionListener(
new 
ActionListener() {                    
public 
void 
actionPerformed(ActionEvent e) {                          
d
.setVisible( 
false
);                   }             });              
d
.addWindowListener( 
new 
WindowAdapter() {                    
public 
void 
windowClosing(WindowEvent e) {                          
d
.setVisible( 
false
);                   }             });
             
tf
.addKeyListener( 
new 
KeyAdapter() {                    
public 
void 
keyPressed(KeyEvent e) {                          
try 
{                                
if 
(e.getKeyCode() == KeyEvent.
VK_ENTER
)                                     showDir();                         } 
catch 
(Exception ex) {                         }
                  }             });
             
but
.addActionListener(
new 
ActionListener() {                    
public 
void 
actionPerformed(ActionEvent e) {                          
try 
{                               showDir();                         } 
catch 
(Exception ex) {                         }
                  }             });
             
f
.addWindowListener( 
new 
WindowAdapter() {                    
public 
void 
windowClosing(WindowEvent e) {                         System. exit(0);                   }             });       }
       
private 
void 
showDir() 
throws 
Exception {
             
ta
.setText( 
“”
);             String urlPath = 
tf
.getText(); 
// http://192.168.1.254:8080/myweb/demo.html
            URL url = 
new 
URL(urlPath);
            URLConnection conn = url.openConnection();
            InputStream in = conn.getInputStream();
             
byte
[] buf = 
new 
byte
[1024];
             
int 
len = in.read(buf);
             
ta
.setText( 
new 
String(buf, 0, len));
      }
       
public 
static 
void 
main(String[] args) {              
new 
Ts();       } }


 
ASP.Net+Android+IO开发

.Net培训
、期待与您交流!

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,893
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,422
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,240
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,054
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,683
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,720