谁能帮我啊!网络方面的!

xuhaoumsl 2005-10-31 09:37:38
我已经写好单机的程序了 需要变成网络版的 就是两个一模一样的单机程序连接起来执行的程序 我做的是一个单机版的drah and drop和画版的 程序 怎么把两个单机版连接起来一个server 一个是client 使的 在任何一个上面drag图片的时候能同时显示,点一边上的clear reload等button 都能在两边都反映出来 还有就是画版画画的时候也能两个上面都显示出画的内容 就好象netmeeting一样 我把单机的贴出来 谁能帮我改写成网络版的啊 自己写的总是出错! 万分感激啊!



Dnd Class:

import java.awt.dnd.*;
import java.awt.datatransfer.*;
import java.util.*;
import java.io.*;
import java.net.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import JavaProject.lib.WhiteboardPanel;
import JavaProject.lib.TabbedPanel;

public class DnD extends JFrame implements ActionListener {

private WhiteboardPanel whiteboard;
private TabbedPanel currentPanel;
private JPanel ToolBar, Panel = new JPanel( );
private JTabbedPane tabbedPane;
private JButton jback, jforward, jload, jclear, jnew;
protected ImageIcon[] imagePick = new ImageIcon[25];
public ImageIcon cimage;
// TabbedPaneWebBrowser constructor
public DnD()
{
super( "Whiteboard and Drag&Drap Window" );
// create first browser tab
tabbedPane = new JTabbedPane();
createNewTab();
//Set the default window close operation
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create the tabs
tabbedPane.setSize(800, 600);
//Create toolbar
ToolBar = new JPanel();
ToolBar.setLayout(new GridLayout(1, 5));
ToolBar.add(jback = new JButton("Back"));
ToolBar.add(jforward = new JButton("Forward"));
ToolBar.add(jload = new JButton("Reload"));
ToolBar.add(jclear = new JButton("Clear"));
ToolBar.add(jnew = new JButton("New"));

//Create instance of whiteboard
whiteboard = new WhiteboardPanel();
whiteboard.setBackground( Color.WHITE );
whiteboard.setLayout(new BorderLayout());
//Set contentPane
this.getContentPane().setLayout(new GridLayout(1, 2));
this.getContentPane().add(whiteboard);
this.getContentPane().add(tabbedPane);
whiteboard.add(ToolBar, BorderLayout.NORTH);
// Button actions
jload.addActionListener(this);
jback.addActionListener(this);
jforward.addActionListener(this);
jclear.addActionListener(this);
jnew.addActionListener(this);
// Set DropTarget on currentPanel
tabbedPane.setDropTarget( new DropTarget( currentPanel,
DnDConstants.ACTION_COPY, new DropTargetHandler() ) );
}
private void createNewTab()
{
// create JPanel to contain tabbedPane
Panel = new JPanel( );
tabbedPane.addTab( "Tab " + tabbedPane.getTabCount(), Panel);
}
// inner class to handle DropTargetEvents
private class DropTargetHandler implements DropTargetListener {
// handle drop operation
public void drop( DropTargetDropEvent event )
{
// get dropped Transferable object
Transferable transferable = event.getTransferable();
// if Transferable is a List of Files, accept drop
if ( transferable.isDataFlavorSupported(
DataFlavor.javaFileListFlavor ) ) {
// accept the drop operation to copy the object
event.acceptDrop( DnDConstants.ACTION_COPY );
// process list of files and display each in browser
try {
// get List of Files
java.util.List fileList =
( java.util.List ) transferable.getTransferData(
DataFlavor.javaFileListFlavor );
Iterator iterator = fileList.iterator();
while ( iterator.hasNext() ) {
File file = ( File ) iterator.next();
ImageIcon dragImage = new ImageIcon(file.toURL());
int selIndex = tabbedPane.getSelectedIndex();
currentPanel = new TabbedPanel();
tabbedPane.setComponentAt(selIndex, currentPanel);
imagePick[selIndex] = currentPanel.displayTabImage(dragImage);
//imagePick[selIndex]=currentPanel.displayTabImage(dragImage);
//imagePick[selIndex]=currentPanel.paint(dragImage);
}
// indicate successful drop
event.dropComplete( true );
}
// handle exception if DataFlavor not supported
catch ( UnsupportedFlavorException flavorException ) {
flavorException.printStackTrace();
event.dropComplete( false );
}
// handle exception reading Transferable data
catch ( IOException ioException ) {
ioException.printStackTrace();
event.dropComplete( false );
}
}
// if dropped object is not file list, reject drop
else
event.rejectDrop();
}
// handle drag operation entering DropTarget
public void dragEnter( DropTargetDragEvent event )
{
// if data is javaFileListFlavor, accept drag for copy
if ( event.isDataFlavorSupported(
DataFlavor.javaFileListFlavor ) )
event.acceptDrag( DnDConstants.ACTION_COPY );
// reject all other DataFlavors
else
event.rejectDrag();
}
// invoked when drag operation exits DropTarget
public void dragExit( DropTargetEvent event ) {}
// invoked when drag operation occurs over DropTarget
public void dragOver( DropTargetDragEvent event ) {}
// invoked if dropAction changes (e.g., from COPY to LINK)
public void dropActionChanged( DropTargetDragEvent event )
{}
}
public void actionPerformed(ActionEvent e) {

int selTab = tabbedPane.getSelectedIndex();
int NewTab = 0;

if (e.getSource() == jnew) {
createNewTab();
NewTab = tabbedPane.getTabCount()-1;
tabbedPane.setSelectedIndex(NewTab);
}
if (e.getSource() == jload)
whiteboard.displayImage(imagePick[selTab]);
if (e.getSource() == jback) {
selTab = selTab-1;
tabbedPane.setSelectedIndex(selTab);

}
if (e.getSource() == jforward) {
selTab = selTab+1;
tabbedPane.setSelectedIndex(selTab);

}
if (e.getSource() == jclear) {
//whiteboard.removeAll();
cimage = new ImageIcon( getClass().getResource(
"images/pixel.gif" ) );
whiteboard.clearwhiteboard(cimage);
repaint();
}
}
public static void main( String args[] )
{
DnD browser = new DnD();
browser.setDefaultCloseOperation( EXIT_ON_CLOSE );
browser.setSize( 800, 600 );
browser.setVisible( true );
}
}



...全文
228 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
nintha 2005-11-03
  • 打赏
  • 举报
回复
是要用RMI吧,代码没看~~
BeYourself 2005-11-02
  • 打赏
  • 举报
回复
用rmi比较快,
www.sunsides.com
xuhaoumsl 2005-11-02
  • 打赏
  • 举报
回复
谁能提供代码看看!谢谢啊!
bright_wish 2005-11-02
  • 打赏
  • 举报
回复
class客户端:
监视器1
建立socket 线程1启动
线程1
接受服务器传入流
监视器
发送客户端事件流到服务器

class 服务端
启动线程1
线程1 启动线程2
创建端口监听 创建socekt set集合
线程2
遍历集合 像客户端发送数据流

大概思想就这样
具体用数据流加特征代码判断还是用 对象流 自己判断!!
我也是初学者 高手请指点!!
TinyJimmy 2005-11-01
  • 打赏
  • 举报
回复
不知道是否有现成的技术.

可否讲你的动作封装成对象, 当做某一个特定的动作时, 一方面在本地做个解释, 屏幕上作出动作. 另一方面将对象转到服务端显示相应的内容...
紫炎圣骑 2005-11-01
  • 打赏
  • 举报
回复
太长了

xuhaoumsl 2005-10-31
  • 打赏
  • 举报
回复
不是吧 没人帮帮我吗? 我已经把code放在http://www.matrix.org.cn/thread.shtml?topicId=30111&forumId=1&page=1#2这个帖子下面可以直接下载 拜托啊 哪位大侠能拔刀相助!
ianok 2005-10-31
  • 打赏
  • 举报
回复
我也暈,只好頂了
xuhaoumsl 2005-10-31
  • 打赏
  • 举报
回复
http://www.matrix.org.cn/thread.shtml?topicId=30111&forumId=1&page=1#2 这个帖子的最下面可以下载到code 谢谢 谁能帮我看一下啊!
treeroot 2005-10-31
  • 打赏
  • 举报
回复
Reading such a long code will killing my brain cells!
网络精灵 2005-10-31
  • 打赏
  • 举报
回复
看着就晕,帮顶一下吧。
xuhaoumsl 2005-10-31
  • 打赏
  • 举报
回复



WhiteboardPanel Class:


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class WhiteboardPanel extends JPanel {

private Point oldPoint, newPoint;
protected ImageIcon image;
private boolean start = true;

// set up GUI and register mouse event handler
public WhiteboardPanel() {

setBackground( Color.WHITE );
image = new ImageIcon( getClass().getResource(
"images/pixel.gif" ) );

addMouseMotionListener(
new MouseMotionAdapter() { // anonymous inner class
// store drag coordinates and repaint
public void mouseDragged( MouseEvent event ) {
if ( start ) {
newPoint = event.getPoint();
start = false;
}
else {
oldPoint = newPoint;
newPoint = event.getPoint();
repaint();
}
}
public void mouseMoved( MouseEvent event ) {
start = true;
}
} // end anonymous inner class
); // end call to addMouseMotionListener
//setSize( 300, 500 );
// setVisible( true );
} // end Painter constructor
public void paintComponent(Graphics g) {
if ( start ) {
image.paintIcon( this, g, 0, 30 );
}
else
g.drawLine( oldPoint.x, oldPoint.y, newPoint.x, newPoint.y );
}
public void displayImage(ImageIcon image) {
this.image = image;
repaint();
}
public void clearwhiteboard(ImageIcon image) {
this.image = image;
repaint();
}


} // end class Painter



TabbedPanel Class:


import java.awt.*;
import javax.swing.*;

public class TabbedPanel extends JPanel {
protected ImageIcon imageT;

public TabbedPanel() {

imageT = new ImageIcon( getClass().getResource(
"pixel.gif" ) );
}
public void paintComponent( Graphics g ) {
super.paintComponent( g );
imageT.paintIcon( this, g, 0, 0 );
}
public ImageIcon displayTabImage(ImageIcon imageT) {
this.imageT = imageT;
repaint();
return imageT;
}
}
chinatelly 2005-10-31
  • 打赏
  • 举报
回复
up
yyouyou 2005-10-31
  • 打赏
  • 举报
回复
太长了
楼主还是自己去看看socket方面的编程吧,

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧