当前位置: 技术问答>java相关
很急的问题,怎么做两个最简单的APPLET程序。。。。。。。。。。。
来源: 互联网 发布时间:2015-07-25
本文导语: 很急的问题,怎么做两个最简单的APPLET程序,实现SOCKET通讯,就是网页中有一个输入框和一个发送按钮,输入字符后,点发送,服务器和客户就可以简单的聊天了??? 小弟不是怎么太会这种东西,可能对您来说的...
很急的问题,怎么做两个最简单的APPLET程序,实现SOCKET通讯,就是网页中有一个输入框和一个发送按钮,输入字符后,点发送,服务器和客户就可以简单的聊天了???
小弟不是怎么太会这种东西,可能对您来说的小菜,请帮帮我,很急啊,在线等待,给个代码,谢谢!!!
小弟不是怎么太会这种东西,可能对您来说的小菜,请帮帮我,很急啊,在线等待,给个代码,谢谢!!!
|
server:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
public class Frame1 extends JFrame {
static Socket servervector[]=new Socket[20];
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JButton jButton1 = new JButton();
JTextArea jTextArea1 = new JTextArea();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jButton1.setText("作成サーバー");
jButton1.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(200, 200));
this.setTitle("Frame Title");
jTextArea1.setText("");
contentPane.add(jButton1, BorderLayout.NORTH);
contentPane.add(jTextArea1, BorderLayout.CENTER);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public void jButton1_actionPerformed(ActionEvent e) {
server hh=new server();
hh.start();
jButton1.setEnabled(false);
}
/////////////////
class server extends Thread{
ServerSocket serversocket=null;
public server(){
try{
serversocket=new ServerSocket(2000);
jTextArea1.append(serversocket.toString()+"成功に作成されましたn");
}catch(Exception e)
{
jTextArea1.append(e.getMessage()+"n");
}
}///
public void run()
{
while(true)
{
try{
Socket socket=serversocket.accept();
int j=0;
for(;j
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
public class Frame1 extends JFrame {
static Socket servervector[]=new Socket[20];
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JButton jButton1 = new JButton();
JTextArea jTextArea1 = new JTextArea();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jButton1.setText("作成サーバー");
jButton1.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(200, 200));
this.setTitle("Frame Title");
jTextArea1.setText("");
contentPane.add(jButton1, BorderLayout.NORTH);
contentPane.add(jTextArea1, BorderLayout.CENTER);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public void jButton1_actionPerformed(ActionEvent e) {
server hh=new server();
hh.start();
jButton1.setEnabled(false);
}
/////////////////
class server extends Thread{
ServerSocket serversocket=null;
public server(){
try{
serversocket=new ServerSocket(2000);
jTextArea1.append(serversocket.toString()+"成功に作成されましたn");
}catch(Exception e)
{
jTextArea1.append(e.getMessage()+"n");
}
}///
public void run()
{
while(true)
{
try{
Socket socket=serversocket.accept();
int j=0;
for(;j