小蜜蜂java源代码 小蜜蜂编程使用说明
java求源代码
你是青鸟的吧 这我写过 有源码 这里怎么上传压缩包啊
成都创新互联公司是一家企业级云计算解决方案提供商,超15年IDC数据中心运营经验。主营GPU显卡服务器,站群服务器,德阳电信服务器托管,海外高防服务器,机柜大带宽、租用·托管,动态拨号VPS,海外云手机,海外云服务器,海外服务器租用托管等。
package ghhh;
import java.util.Scanner;
public class DvD {
public static void main(String[] args) {
int state[]=new int[6];
String name[]=new String[6];
int date[]=new int[6];
int count[]=new int [6];
name[0]="权利的游戏";
name[1]="命运之夜";
name[2]="傲慢与偏见";
state[0]=1;
state[1]=0;
state[2]=1;
date[0]=13;
date[1]=0;
date[2]=9;
count[0]=23;
count[1]=23;
count[2]=23;
int n;
// boolean n=false;
do{
System.out.println("欢迎使用迷你DVD管理器");
System.out.println("1.新增DVD");
System.out.println("2.查看DVD");
System.out.println("3.删除DVD");
System.out.println("4.借出DVD");
System.out.println("5.归还DVD");
System.out.println("6.退出DVD");
Scanner input =new Scanner(System.in);
System.out.println("请选择:");
n=input.nextInt();
switch(n){
case 1:
System.out.println("请输入要增加DVD的名称:");
String name1=input.next();
boolean flag=false;
for(int i=0;iname.length;i++){
if(name[i]==null){
name[i]=name1;
flag=true;
break;
}
}
if(flag){
System.out.println("新增DVD"+name1+"成功");
}else{
System.out.println("货架已满!增加失败!");
}
System.out.println("请输入0返回!");
n=input.nextInt();
break;
case 2:
System.out.println("序号\t"+"状态\t"+"名称\t\t"+"借出日期\t"+"借出次数");
for(int i=0;iname.length;i++){
if(name[i]!=null){
String state1 =((state[i]==0)?"可借":"已借");
String date1=((date[i]==0)?"":date[i]+"日");
String count1=count[i]+"次";
System.out.println((i+1)+"\t"+state1+"\t"+name[i]+"\t"+date1+"\t\t"+count1);
}
}
System.out.println("请输入0返回!");
n=input.nextInt();
break;
case 3:
System.out.println("请输入要删除的DVD名称:");
String name2=input.next();
int index=-1;
boolean a=false;
boolean flag1=false;
for(int i=0;iname.length;i++){
if(name2.equals(name[i])state[i]==1){
System.out.println("此DVD已经借出,无法删除");
a=true;
break;
}else if(name2.equals(name[i])state[i]==0){
a=true;
index=i;
flag1=true;
System.out.println("删除成功!");
break;
}
}
if(a==false){
System.out.println("没有找到相同名称的DVD!");
}
if(flag1){
for (int i=index;iname.length;i++){
if(i!=name.length-1){
name[i]=name[i+1];
state[i]=state[i+1];
date[i]=date[i+1];
count[i]=count[i+1];
}
name[name.length-1]=null;
state[name.length-1]=0;
date[name.length-1]=0;
count[name.length-1]=0;
}
}
System.out.println("请输入0返回!");
n=input.nextInt();
break;
case 4:
System.out.println("请输入要借出的DVD:");
String name3=input.next();
boolean a3=false;
boolean b3=false;
for(int i=0;iname.length;i++){
if(name3.equals(name[i]) state[i]==1){
System.out.println("该DVD已经借出");
a3=true;
}else if(name3.equals(name[i]) state[i]==0){
do{
System.out.println("请输入借出的日期:");
int m=input.nextInt();
if(m31||m1){
System.out.println("请重新输入日期:");
b3=true;
}else{
date[i]=m;
state[i]=1;
count[i]+=1;
}
}while(b3==true);
System.out.println("借出成功!");
a3=true;
}
}
if(a3==false){
System.out.println("没有该DVD");
}
System.out.println("请输入0返回!");
n=input.nextInt();
break;
case 5:
System.out.println("请输入要归还的DVD:");
String name5=input.next();
boolean b5=false;
boolean m5=false;
for(int i=0;iname.length;i++){
if(name5.equals(name[i]) state[i]==1){
b5=true;
do{
System.out.println("请输入要归还DVD的日期:(归还日期请输入当月日期 1~31)");
int a5=input.nextInt();
if(a531){
System.out.println("请重新输入日期:");
m5=true;
}else if(a5date[i]){
System.out.println("借出日期是"+date[i]+"日\t输入的日期不能小于借出的日期,请重新输入日期:");
m5=true;
}else{
state[i]=0;
System.out.println("归还成功");
System.out.println("借出日期是:"+date[i]+"归还日期是:"+a5+"日\t租金一天一元:共"+(a5-date[i])+"元");
date[i]=0;
m5=false;
}
}while(m5==true);
}else if (name5.equals(name[i]) state[i]==0){
System.out.println("该DVD未借出,不可归还!");
b5=true;
}
}
if(b5==false){
System.out.println("没有该名称的DVDV");
}
System.out.println("请输入0返回!");
n=input.nextInt();
break;
case 6:
n=1;
System.out.println("程序退出!");
break;
default:
if(n==0){
}else{
System.out.println("输入错误!请重新输入!");
n=0;
}
break;
}
}while(n==0);
System.out.println("谢谢使用!");
}
}
看看有没有问题 好久之前的了
求编写一个超级简单的Java的程序源代码
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ConstructFrame extends JFrame
{
private static final long serialVersionUID = 1L;
String value1="",result,value2="";
int flag=0,fix=0,sum=1;
Boolean happy;
JTextField text=new JTextField(30);
int flagsum=0;
Container c=getContentPane();
JButton buttonx;
ConstructFrame()
{ super("计算器");
c.setLayout(null);
c.setBackground(Color.blue);
this.setSize(400, 400);
c.add(text);
text.setHorizontalAlignment(JTextField.RIGHT);
final JButton buttonx=new JButton("BackSpace");
c.add(buttonx);
buttonx.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
int count=0;
String temp;
if(flag==0)
{
count=value1.length();
if(count!=1)
temp=value1.substring(0, count-1);
else
temp="0";
value1=temp;
}
else
{
count=value2.length();
if(count!=1)
temp=value2.substring(0, count-1);
else
temp="0";
value2=temp;
}
text.setText(temp);
}
});
final JButton buttony=new JButton("CE");
c.add(buttony);
buttony.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
value1="";
value2="";
flag=0;
text.setText("0");
}
});
final JButton button1=new JButton("1");
c.add(button1);
button1.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+1;
temp=value1;
}
else
{
value2=value2+1;
temp=value2;
}
text.setText(temp);
}
});
final JButton button2=new JButton(" 2 ");
c.add(button2);
button2.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+2;
temp=value1;
}
else
{
value2=value2+2;
temp=value2;
}
text.setText(temp);
}
});
final JButton button3=new JButton("3");
c.add(button3);
button3.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+3;
temp=value1;
}
else
{
value2=value2+3;
temp=value2;
}
text.setText(temp);
}
});
final JButton button4=new JButton("4");
c.add(button4);
button4.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+4;
temp=value1;
}
else
{
value2=value2+4;
temp=value2;
}
text.setText(temp);
}
});
final JButton button5=new JButton("5");
c.add(button5);
button5.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+5;
temp=value1;
}
else
{
value2=value2+5;
temp=value2;
}
text.setText(temp);
}
});
final JButton button6=new JButton("6");
c.add(button6);
button6.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+6;
temp=value1;
}
else
{
value2=value2+6;
temp=value2;
}
text.setText(temp);
}
});
final JButton button7=new JButton("7");
c.add(button7);
button7.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+7;
temp=value1;
}
else
{
value2=value2+7;
temp=value2;
}
text.setText(temp);
}
});
final JButton button8=new JButton("8");
c.add(button8);
button8.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+8;
temp=value1;
}
else
{
value2=value2+8;
temp=value2;
}
text.setText(temp);
}
});
final JButton button9=new JButton("9");
c.add(button9);
button9.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+9;
temp=value1;
}
else
{
value2=value2+9;
temp=value2;
}
text.setText(temp);
}
});
final JButton button0=new JButton("0");
c.add(button0);
button0.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+0;
temp=value1;
}
else
{
value2=value2+0;
temp=value2;
}
text.setText(temp);
}
});
final JButton buttonadd=new JButton(" + ");
c.add(buttonadd);
buttonadd.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
flag=1;
fix=1;
flagsum=0;
}
});
final JButton buttonsubtract=new JButton(" - ");
c.add(buttonsubtract);
buttonsubtract.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
flag=1;
fix=2;
flagsum=0;
}
});
final JButton buttoncheng=new JButton(" * ");
c.add(buttoncheng);
buttoncheng.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
flag=1;
fix=3;
flagsum=0;
}
});
final JButton buttonchu=new JButton(" / ");
c.add(buttonchu);
buttonchu.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
flag=1;
flagsum=0;
fix=4;
}
});
final JButton buttonequal=new JButton(" = ");
c.add(buttonequal);
buttonequal.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
double temp1,temp2;
double temp=0;
flagsum=0;
temp1=Double.parseDouble(value1);
temp2=Double.parseDouble(value2);
flag=0;
switch(fix)
{
case 1: temp=temp1+temp2;break;
case 2: temp=temp1-temp2;break;
case 3: temp=temp1*temp2;break;
case 4: temp=temp1/temp2;break;
}
result=Double.valueOf(temp).toString();
value1=result;
value2="";
flag=1;
text.setText(result);
}
});
final JButton buttonpoint=new JButton(".");
c.add(buttonpoint);
buttonpoint.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{ if(flagsum==0)
{
String temp;
if(flag==0 )
{
value1=value1+".";
temp=value1;
}
else
{
value2=value2+".";
temp=value2;
}
flagsum=1;
text.setText(temp);
}
}
});
JButton buttonz=new JButton("Start");
c.add(buttonz);
buttonz.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{ if(sum%2==1)
{
happy=true;
text.setText("0.");
flag=0;
}
else
{
happy=false;
value1="";
value2="";
text.setText("");
}
text.setEnabled(happy);
button1.setEnabled(happy);
button2.setEnabled(happy);
button3.setEnabled(happy);
button4.setEnabled(happy);
button5.setEnabled(happy);
button6.setEnabled(happy);
button7.setEnabled(happy);
button8.setEnabled(happy);
button9.setEnabled(happy);
button0.setEnabled(happy);
buttonx.setEnabled(happy);
buttony.setEnabled(happy);
buttonadd.setEnabled(happy);
buttonsubtract.setEnabled(happy);
buttonpoint.setEnabled(happy);
buttonequal.setEnabled(happy);
buttoncheng.setEnabled(happy);
buttonchu.setEnabled(happy);
sum++;
}
});
button1.setEnabled(false);
button2.setEnabled(false);
button3.setEnabled(false);
button4.setEnabled(false);
button5.setEnabled(false);
button6.setEnabled(false);
button7.setEnabled(false);
button8.setEnabled(false);
button9.setEnabled(false);
button0.setEnabled(false);
buttonx.setEnabled(false);
buttony.setEnabled(false);
buttonadd.setEnabled(false);
buttonsubtract.setEnabled(false);
buttonpoint.setEnabled(false);
buttonequal.setEnabled(false);
buttoncheng.setEnabled(false);
buttonchu.setEnabled(false);
text.setEnabled(false);
text.setBounds(20, 20, 200, 40);
buttonx.setBounds(20, 60,100, 40);
buttony.setBounds(140, 60,100, 40);
buttonz.setBounds(260, 60,80, 40);
button1.setBounds(20, 120,60, 40);
button2.setBounds(100, 120,60, 40);
button3.setBounds(180, 120,60, 40);
buttonadd.setBounds(260, 120,60, 40);
button4.setBounds(20, 180,60, 40);
button5.setBounds(100, 180,60, 40);
button6.setBounds(180, 180,60, 40);
buttonsubtract.setBounds(260, 180,60, 40);
button7.setBounds(20, 240,60, 40);
button8.setBounds(100, 240,60, 40);
button9.setBounds(180, 240,60, 40);
buttoncheng.setBounds(260,240,60,40);
button0.setBounds(20, 300,60, 40);
buttonpoint.setBounds(100, 300, 60, 40);
buttonequal.setBounds(180,300,60, 40);
buttonchu.setBounds(260, 300,60, 40);
setVisible(true);
}
class MYMouseEvent extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
value1=e.toString();
text.setText(value1);
}
}
}
class Calutator
{
public static void main(String[] args)
{
new ConstructFrame();
}
}
你自己慢慢的看吧!
求一个JAVA音乐播放器的源代码
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.EndOfMediaEvent;
import javax.media.PrefetchCompleteEvent;
import javax.media.RealizeCompleteEvent;
import javax.media.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MediaPlayer extends JFrame implements ActionListener,
ItemListener, ControllerListener {
String title;
Player player;
boolean first = true, loop = false;
Component vc, cc;
String currentDirectory=null;
// 构造函数,其中包括了设置响应窗口事件的监听器。
MediaPlayer(String title) {
super(title);
/* 关闭按钮的实现。。 */
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
public void windowClosed(WindowEvent e) {
if (player != null)
player.close();
System.exit(0);
}
});
// 调用程序菜单栏的方法成员完成菜单的布置
setupMenu();
setSize(400, 400);
setVisible(true);
}
// 本方法用以设置程序菜单栏
public void setupMenu() {
// 设置一个菜单
Menu f = new Menu("文件");
// 往设置的菜单添加菜单项
MenuItem mi = new MenuItem("打开");
f.add(mi);
mi.addActionListener(this);
f.addSeparator();
CheckboxMenuItem cbmi = new CheckboxMenuItem("循环", false);
cbmi.addActionListener(this);
f.add(cbmi);
f.addSeparator();
MenuItem ee = new MenuItem("退出");
ee.addActionListener(this);
f.add(ee);
f.addSeparator();
Menu l = new Menu("播放列表");
Menu c = new Menu("播放控制");
MenuItem move = new MenuItem("播放");
move.addActionListener(this);
c.add(move);
c.addSeparator();
MenuItem pause = new MenuItem("暂停");
pause.addActionListener(this);
c.add(pause);
c.addSeparator();
MenuItem stop = new MenuItem("停止");
stop.addActionListener(this);
c.add(stop);
c.addSeparator();
// 设置一个菜单栏
MenuBar mb = new MenuBar();
mb.add(f);
mb.add?;
mb.add(l);
// 将构造完成的菜单栏交给当前程序的窗口;
setMenuBar(mb);
}
// 动作时间响应成员;捕捉发送到本对象的各种事件;
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String cufile, selectfile, currentDirectory;
if (e.getActionCommand().equals("退出")) {
// 调用dispose以便执行windowClosed
dispose();
return;
}
// 此事表明拥护选择了“播放”命令;
// 如果当前有一个文件可以播放则执行播放命令;
if (e.getActionCommand().equals("播放")) {
if (player != null) {
player.start();
}
return;
}
// 如果当前正在播放某一文件,则执行暂停;
if (e.getActionCommand().equals("暂停")) {
if (player != null) {
player.stop();
}
return;
}
// 停止命令的响应;
if (e.getActionCommand().equals("停止")) {
if (player != null) {
player.stop();
player.setMediaTime(new Time(0));
}
return;
}
// 用户选择要播放的媒体文件
if (e.getActionCommand().equals("打开")) {
FileDialog fd = new FileDialog(this, "打开媒体文件", FileDialog.LOAD);
// fd.setDirectory(currentDirectory);
2008-2-6 02:46 回复
肆方茉莉
62位粉丝
6楼
fd.setVisible(true);
// 如果用户放弃选择文件,则返回
if (fd.getFile() == null) {
return;
}
// 保存了所选文件的名称及其路径名称已被稍后使用
// 同时设置当前文件夹路径
selectfile = fd.getFile();
currentDirectory = fd.getDirectory();
cufile = currentDirectory + selectfile;
// 将用户选择的文件作为一个菜单项加入播放列表,该菜单项名为该文件名;
// 被点击后给出的命令串是该文件的全路径名
MenuItem mi = new MenuItem(selectfile);
mi.setActionCommand(cufile);
MenuBar mb = getMenuBar();
Menu m = mb.getMenu(2);
mi.addActionListener(this);
m.add(mi);
} else {
// 程序逻辑运行到次表示用户选择了一个“播放列表”中的媒体文件
// 此时可以通过如下动作获得该文件的全路径名
cufile = e.getActionCommand();
selectfile = cufile;
}
// 如果存在一个播放器,则先将其关闭,稍后再重新创建
// 创建播放器时需要捕捉一些异常
if (player != null) {
player.close();
}
try {
player = Manager.createPlayer(new MediaLocator("file:" + cufile));
} catch (Exception e2) {
System.out.println(e2);
return;
}/*
* catch(NoPlayerException e2){ System.out.println("不能找到播放器");
* return ; }
*/
if (player == null) {
System.out.println("无法创建播放器");
return;
}
first = false;
setTitle(selectfile);
// 设置处理播放控制器实际的对象;
/**/
player.addControllerListener(this);
player.prefetch();
}
// 菜单状态改变事件的响应函数;
public void itemStateChanged(ItemEvent arg0) {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new MediaPlayer("播放器");
}
// 调用绘图函数进行界面的绘制 // public void update() {
// }
// 绘图函数成员 //public void paint(Graphics g) {
// }
public void controllerUpdate(ControllerEvent e) {
// TODO Auto-generated method stub
Container tainer = getContentPane();
// 调用player.close()时ControllerClosedEvent事件出现
// 如果存在视觉部件,则该部件应该拆除(为了一致起见,我们对控制面版部件也执行同样的操作,下一次需要时再构造)
if (e instanceof ControllerClosedEvent) {
if (vc != null) {
remove(vc);
vc = null;
}
if (cc != null) {
remove(cc);
cc = null;
}
}
// 播放结束时,将播放指针置于文件之首,如果设定了循环播放,则再次启动播放器;
if (e instanceof EndOfMediaEvent) {
player.setMediaTime(new Time(0));
if (loop) {
player.start();
}
return;
}
// PrefetchCompletEvent事件发生后调用start,正式启动播放
if (e instanceof PrefetchCompleteEvent) {
player.start();
return;
}
// 本事件表示由于播放的资源已经确定;此时要将媒体的图形conmopnent
// 如果有显示出来,同时将播放器player的控制显示到窗口里;
if (e instanceof RealizeCompleteEvent) {
// 如果媒体中有图像,将对应图像component载入窗体;
vc = player.getVisualComponent();
if (vc != null)
tainer.add(vc, BorderLayout.CENTER);
// 将对应控制器component载入窗体;
cc = player.getControlPanelComponent();
cc.setBackground(Color.blue);
if (cc != null)
tainer.add(cc, BorderLayout.SOUTH);
// 有一些特殊媒体在播放时提供另外的控制手段,将控制器一并加入窗口;
/*
* gc=player.getGainControl(); gcc=gc.getControlComponent();
* if(gcc!=null) tainer.add(gcc,BorderLayout.NORTH);
*/
// 根据媒体文件中是否有图像,设定相应的窗口大小
if (vc != null) {
pack();
return;
} else {
setSize(300, 75);
setVisible(true);
return;
}
}
} }
求TCP/IP client server socket的JAVA代码
我这刚好有一个,给你参考一下:(分客户端和服务器两个小程序)
//客户端程序及聊天室的图形用户界面
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
public class ChatTCPSocketJFrame extends JFrame implements ActionListener
{
private String name; //网名
private Socket socket; //TCP Socket对象
private JTextArea text_receiver; //显示对话内容的文本区
private JTextField text_sender; //输入发送内容的文本行
private JButton button_send,button_leave; //发送和离线按钮
private PrintWriter cout; //字符输出流对象
public ChatTCPSocketJFrame(String name, Socket socket) throws IOException//提供图形用户界面
{
super("聊天室 "+name+" "+InetAddress.getLocalHost()+" : "+socket.getLocalPort());
this.setBounds(320,240,400,240);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.text_receiver = new JTextArea();
this.text_receiver.setEditable(false); //文本区不可编辑
this.getContentPane().add(new JScrollPane(this.text_receiver));
JPanel panel = new JPanel();
this.getContentPane().add(panel,"South");
this.text_sender = new JTextField(16);
panel.add(this.text_sender);
button_send = new JButton("发送");
panel.add(button_send);
button_send.addActionListener(this);
button_leave = new JButton("离线");
panel.add(button_leave);
button_leave.addActionListener(this);
this.setVisible(true);
this.name = name;
this.socket = socket;
this.cout = new PrintWriter(socket.getOutputStream(),true);//获得Socket对象的输出流,立即flush
this.cout.println(name); //发送自己网名给对方
BufferedReader cin=new BufferedReader(new InputStreamReader(socket.getInputStream()));
//获得Socket对象的输入流,创建字符输入流
String aline=cin.readLine(); //接收到对方网名
text_receiver.append("连接"+aline+"成功"+"\r\n"); //显示对方发来的内容
aline= cin.readLine();
while (aline!=null !aline.equals("bye")) //从输入流接收对方发来的字符串
{ //"bye"是约定的离线信息
text_receiver.append(aline+"\r\n"); //显示对方发来的内容
aline= cin.readLine();
}
cin.close();
cout.close();
socket.close(); //关闭Socket连接
button_send.setEnabled(false);
button_leave.setEnabled(false);
}
public ChatTCPSocketJFrame(String name, String host, int port) throws IOException //客户端
{
this(name, new Socket(host, port)); //客户端向指定主机的端口发出TCP连接请求
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==button_send) //发送按钮
{
this.cout.println(name+" 说:"+text_sender.getText()); //通过流发送给对方
text_receiver.append("我说:"+text_sender.getText()+"\n");
text_sender.setText("");
}
if (e.getSource()==button_leave) //离线
{
text_receiver.append("我离线\n");
this.cout.println(name+"离线\n"+"bye"); //发送给对方离线约定
button_send.setEnabled(false);
button_leave.setEnabled(false);
}
}
public static void main(String args[]) throws IOException
{
new ChatTCPSocketJFrame("小蜜蜂", "127.0.0.1", 2001);
}
}
//服务端程序
import java.net.*;
import java.io.*;
public class ChatTCPServer
{
public ChatTCPServer(int port, String name) throws IOException //约定端口、网名
{ //本机IP地址和指定端口构成服务端的Socket
ServerSocket server = new ServerSocket(port); //ServerSocket提供TCP连接服务
Socket client = server.accept(); //等待接收客户端的连接申请
new ChatTCPSocketJFrame(name,client); //服务端的聊天室,图形用户界面同客户端
server.close();
}
public static void main(String args[]) throws IOException
{
new ChatTCPServer(2001, "花仙子"); //启动服务端,约定端口,指定网名
}
}
文章标题:小蜜蜂java源代码 小蜜蜂编程使用说明
网页URL:http://ybzwz.com/article/dooejhh.html