老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

按住說話的java代碼 按住說話的java代碼

急需一個java編程實現的簡單聊天窗口代碼

import java.awt.*;

創新互聯建站基于分布式IDC數據中心構建的平臺為眾多戶提供雅安服務器托管 四川大帶寬租用 成都機柜租用 成都服務器租用。

import java.awt.event.*;

import javax.swing.*;

import java.net.*;

import java.io.*;

public class ClientDemo01 {

public static void main(String[] args){

JFrame f=new JFrame("AA");

JPanel p1=new JPanel();

JPanel p2=new JPanel();

JTextArea ta=new JTextArea(15,30);

ta.setEditable(false); //文本域只讀

JScrollPane sp=new JScrollPane(ta); //滾動窗格

JTextField tf=new JTextField(20);

JButton b=new JButton("發送");

p1.add(sp);

p2.add(tf);

p2.add(b);

f.add(p1,"Center");

f.add(p2,"South");

f.setBounds(300,300,360,300);

f.setVisible(true);

f.setResizable(false);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Socket socket=null;

BufferedInputStream bis=null;

BufferedOutputStream bos=null;

try{

socket=new Socket("192.168.0.4",5000);

bis=new BufferedInputStream(socket.getInputStream());

bos=new BufferedOutputStream(socket.getOutputStream());

MyThread01 mt=new MyThread01(bis,ta);

mt.start();

}catch(Exception e){

e.printStackTrace();

}

b.addActionListener(new ButtonActionListener01(tf,ta,bos));

}

}

class ButtonActionListener01 implements ActionListener{

JTextField tf;

JTextArea ta;

BufferedOutputStream bos;

public ButtonActionListener01(JTextField tf,JTextArea ta,BufferedOutputStream bos){

this.tf=tf;

this.ta=ta;

this.bos=bos;

}

public void actionPerformed(ActionEvent e){

String message=tf.getText();

if(!message.equals("")){

tf.setText(""); //清空文本框

ta.append("AA:"+message+"\n"); //添加到文本域并換行

try{

bos.write(message.getBytes());

bos.flush();

}catch(Exception ex){

System.out.println("發送失敗");

}

}

}

}

class MyThread01 extends Thread{

BufferedInputStream bis;

JTextArea ta;

public MyThread01(BufferedInputStream bis,JTextArea ta){

this.bis=bis;

this.ta=ta;

}

public void run(){

try{

while(true){

byte[] b=new byte[100];

int length=bis.read(b);

String message=new String(b,0,length);

ta.append("BB:"+message+"\n");

}

}catch(Exception e){

e.printStackTrace();

}

}

} import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.net.*;

import java.io.*;

public class ServerDemo01{

public static void main(String[] args){

JFrame f=new JFrame("BB");

JPanel p1=new JPanel();

JPanel p2=new JPanel();

JTextArea ta=new JTextArea(12,30); //文本域,第一個參數為行數,第二個參數為列數

ta.setEditable(false); //文本域只讀

JScrollPane sp=new JScrollPane(ta); //滾動窗格

JTextField tf=new JTextField(20);

JButton b=new JButton("發送");

p1.add(sp);

p2.add(tf);

p2.add(b);

f.add(p1,"Center");

f.add(p2,"South");

f.setBounds(300,300,360,300);

f.setVisible(true);

f.setResizable(false);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

ServerSocket server=null;

Socket socket=null;

BufferedInputStream bis=null;

BufferedOutputStream bos=null;

try{

server=new ServerSocket(5000);

//ta.append("等待AA連接...\n");

socket=server.accept();

//ta.append("AA已連接\n");

bis=new BufferedInputStream(socket.getInputStream());

bos=new BufferedOutputStream(socket.getOutputStream());

MyThread1 mt=new MyThread1(bis,ta);

mt.start();

}catch(Exception e){

e.printStackTrace();

}

b.addActionListener(new ButtonActionListener1(tf,ta,bos));

}

}

class ButtonActionListener1 implements ActionListener{

JTextField tf;

JTextArea ta;

BufferedOutputStream bos;

public ButtonActionListener1(JTextField tf,JTextArea ta,BufferedOutputStream bos){

this.tf=tf;

this.ta=ta;

this.bos=bos;

}

public void actionPerformed(ActionEvent e){

String message=tf.getText(); //獲取文本框中的內容

if(!message.equals("")){

tf.setText(""); //清空文本框

ta.append("BB:"+message+"\n"); //添加到文本域并換行

try{

bos.write(message.getBytes());

bos.flush();

}catch(Exception ex){

System.out.println("發送失敗!");

}

}

}

}

class MyThread1 extends Thread{

BufferedInputStream bis;

JTextArea ta;

public MyThread1(BufferedInputStream bis,JTextArea ta){

this.bis=bis;

this.ta=ta;

}

public void run(){

try{

while(true){

byte[] b=new byte[100];

int length=bis.read(b);

String message=new String(b,0,length);

ta.append("AA:"+message+"\n");

}

}catch(Exception e){

e.printStackTrace();

}

}

}

Myeclipse如何打開別人的.Java源代碼

點擊菜單欄File——Import——然后再點擊General文件夾下的Existing?Projects?into?Workspace

——最后點擊Browse選擇你所需要導入的項目再finish即可。。

使用java編寫代碼如下要求

NewPhone類

package?com.baidu.question;

public?class?NewPhone?extends?Phone?{

private?boolean?mute?=?true;

@Override

public?void?call()?{

if(mute){

super.call();

}else{

System.out.println("語音已關閉");

}

}

//這里是直接設置

public?void?setMute(boolean?mute){

this.mute=mute;

}

//擔心你的題目是要求兩種方法,寫的第二種,下面兩個方法負責開關

public?void?openMute(){

this.mute=true;

/*

*?也可以這樣寫

*?setMute(true);

*?下邊的方法一樣

*?*/

}

public?void?closeMute(){

this.mute?=?false;

}

}

Phone類

package?com.baidu.question;

public?class?Phone?{

public?void?call(){

System.out.println("打電話");

}

}

測試類

package?com.baidu.question;

public?class?PhoneTest?{

public?static?void?main(String[]?args)?{

Phone?phone?=?new?Phone();

phone.call();

NewPhone?newPhone?=?new?NewPhone();

newPhone.call();

newPhone.setMute(false);

newPhone.call();

newPhone.openMute();

newPhone.call();

newPhone.closeMute();

newPhone.call();

}

}

測試結果

打電話

打電話

語音已關閉

打電話

語音已關閉

java如何實現按下一個鍵和按住一個鍵?????????

new Robot() .

keyPress(int keycode)

按下給定的鍵。

keyRelease(int keycode)

釋放給定的鍵。


本文題目:按住說話的java代碼 按住說話的java代碼
本文鏈接:http://www.xueling.net.cn/article/dojegjh.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 97涩国一产精品久久久久久久 | 柠檬福利视频导航 | 国产区在线观看成人精品 | 日本高清不卡的在线 | 成人A级视频在线播放 | 麻豆熟妇人妻XXXXXX | 四虎影音库www4hu | 亚州精品av久久久久久久影院 | 久操av在线播放 | 亚洲中文字幕乱码一区二区三区 | 在野外被三个男人躁爽白浆视频 | 日韩综合色 | 成人毛片免费看片 | 亚洲gv猛男gv无码男同短文 | 亚洲精品高清无码视频 | 黄色+视频+卡1+国产 | 爱爱视频免费播放 | 午夜看片网址 | 蜜臀忘忧草久久久久久久aⅴ | 精品区一区二 | 成人av18 | 精品无码一区二区三区亚洲桃色 | 青青草在线视频免费观看 | 亚洲国产五月综合网 | 欧美一级片在线视频 | 国产精品久国产精品 | 欧美特黄aaa | 高清国语自产拍免费视频 | 亚洲在线视频免费观看 | 靠比久久久 | 久久一区二区三区国产精品 | 视频一区亚洲 | 亚洲国产精品久久久久婷婷软件 | 亚洲国产精品视频一区 | 日韩国产在线观看 | 国产一区二区网 | 伊人影院在线视频 | 欧美一区二区三区免费在线观看 | 我和隔壁的少妇人妻HD | 噜噜噜综合亚洲 | 看片网站在线观看 |