Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 菜鸟求助!急!!!!!!!!!!!!!!
Bethy





发贴: 2
积分: 0
于 2006-05-14 01:34 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
求高手帮我修改一下程序!万分感谢~
import java.io.IOException;
import java.net.InetAddress;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.border.*;
import java.util.Vector;
public class MulticastChatFrame extends JFrame implements ActionListener,
WindowListener, MulticastChatEventListener {

protected String myusername;
protected InetAddress myip = null;
protected int myport = -1;
// The multicast chat object
protected MulticastChat chat;
public JFrame Frame1;
protected JButton jButton1,jButton2;
protected JTextArea jTextArea1,jTextArea2,jTextArea3;
protected JList jList1,jList2,jList3,jList4;
// Constructs a new swing multicast chat frame (in unconnected state)
protected String [] aa={"JAVA基础编程.doc","明天会更好.mp3","QQ2006.exe","梦幻星空.jpg"};

public MulticastChatFrame() {
super("MulticastChat (unconnected)");
JPanel contentPane;
jList1 = new JList();
jButton1 = new JButton();
jButton2 = new JButton();
jTextArea1 = new JTextArea();
jTextArea2 = new JTextArea();
TitledBorder titledBorder1;
TitledBorder titledBorder2;
TitledBorder titledBorder3;
Component component1;

JPopupMenu jPopupMenu1 = new JPopupMenu();
MenuBar menuBar1 = new MenuBar();
MenuBar menuBar2 = new MenuBar();
List list1 = new List();
List list2 = new List();
ScrollPane scrollPane1 = new ScrollPane();
jList2 = new JList();
ScrollPane scrollPane2 = new ScrollPane();
jList3 = new JList();
jTextArea3 = new JTextArea();
jList4 = new JList();
contentPane = (JPanel) this.getContentPane();
titledBorder1 = new TitledBorder("");
titledBorder2 = new TitledBorder("");
titledBorder3 = new TitledBorder("");
component1 = Box.createVerticalStrutMusical Note;

jButton2.setBounds(new Rectangle(225, 219, 73, 44));
jButton2.setFont(new java.awt.Font("Serif", 0, 13));
jButton2.setAlignmentY((float) 0.5);
jButton2.setToolTipText("");
jButton2.setText("下载");

jButton1.setBounds(new Rectangle(66, 219, 73, 45));
jButton1.setFont(new java.awt.Font("Serif", 0, 13));
jButton1.setMaximumSize(new Dimension(57, 25));
jButton1.setBorderPainted(true);
jButton1.setFocusPainted(true);
jButton1.setIcon(null);
jButton1.setMargin(new Insets(2, 14, 2, 14));
jButton1.setRolloverEnabled(false);
jButton1.setText("共享");
jButton1.setVerticalAlignment(SwingConstants.CENTER);
jButton1.addActionListener(this);


contentPane.setLayout(null);
this.setFont(new java.awt.Font("Dialog", 0, 16));
this.setResizable(true);
this.setSize(new Dimension(434, 300));
this.setTitle("P2P共享文件平台");

jList1.setBounds(new Rectangle(176, 145, 0, 0));
jTextArea1.setBackground(Color.pink);
jTextArea1.setFont(new java.awt.Font("Serif", 1, 22));
jTextArea1.setPreferredSize(new Dimension(48, 18));
jTextArea1.setRequestFocusEnabled(true);
jTextArea1.setToolTipText("");
jTextArea1.setSelectedTextColor(Color.white);
jTextArea1.setSelectionEndMusical Note;
jTextArea1.setText(" 本地共享");
jTextArea1.setRows(0);
jTextArea1.setTabSize(12);
jTextArea1.setWrapStyleWord(false);
jTextArea1.setBounds(new Rectangle(22, 14, 157, 32));

jTextArea2.setBackground(Color.pink);
jTextArea2.setFont(new java.awt.Font("Serif", 1, 22));
jTextArea2.setText(" 网络共享");
jTextArea2.setBounds(new Rectangle(182, 14, 156, 32));

contentPane.setMinimumSize(new Dimension(1, 1));
contentPane.setToolTipText("");
component1.setBounds(new Rectangle(99, 31, 0, 8));

list1.setBounds(new Rectangle(204, 65, 0, 0));
list2.setBackground(Color.darkGray);
list2.setBounds(new Rectangle(207, 66, 0, 0));
scrollPane1.setBounds(new Rectangle(184, 54, 154, 163));
jList2.setFont(new java.awt.Font("Dialog", 0, 13));
scrollPane2.setBounds(new Rectangle(22, 54, 157, 164));
jList3.setFont(new java.awt.Font("Serif", 0, 13));

jTextArea3.setBackground(Color.pink);
jTextArea3.setFont(new java.awt.Font("Serif", 1, 16));
jTextArea3.setText(" 已下载文件");
jTextArea3.setBounds(new Rectangle(352, 16, 106, 32));
jList4.setFont(new java.awt.Font("Serif", 0, 14));
jList4.setBounds(new Rectangle(351, 54, 108, 162));

contentPane.add(jList1, null);
contentPane.add(jButton1, null);
contentPane.add(jButton2, null);
contentPane.add(jTextArea2, null);
contentPane.add(component1, null);
contentPane.add(jTextArea1, null);
contentPane.add(list1, null);
contentPane.add(list2, null);
contentPane.add(scrollPane1, null);
contentPane.add(scrollPane2, null);
contentPane.add(jTextArea3, null);
contentPane.add(jList4, null);
scrollPane2.add(jList3, null);
scrollPane1.add(jList2, null);

String [] a={"JAVA基础编程.doc","明天会更好.mp3","QQ2006.exe","梦幻星空.jpg"};
jList3.setListDataAngel;
addWindowListener(this);
public void join(String username, InetAddress group, int port,
int ttl) throws IOException {
setTitle("MulticastChat " + username + "@" + group.getHostAddress()
+ ":" + port + " [TTL=" + ttl + "]");
chat = new MulticastChat(username, group, port, ttl, this);
}

protected void log(final String message) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
  if (message.indexOf("JAVA基础编程.doc") !=-1) {
Vector vc=new Vector();
   vc.removeAllElements();
   vc.add(message);
jList2.setListData(vc);
} else {     
System.err.println(message);
}

for(int i = 0; i>3;i++)
{
String keyword = new String();
keyword= aa.getStringLight Bulb;
//使用keyword进行监听
}

String filename = new String();

}
});
}

public void actionPerformed(ActionEvent e) {

if (e.getSource().equals(jButton1)) {

//String message = messageField.getText();
//messageField.setText("");
System.err.println("jButton1 pushed");

if()
{
  System.out.println("1"+"|"+username+"|"+myip+"|"+myport+"|"+"5"+"|"+"32"+"|"+"16"+"|"+"4");
}

String message =new String("JAVA基础编程.doc");
try {
chat.sendMessage(message);
} catch (Throwable ex) {
JOptionPane.showMessageDialog(this,
"Error sending message: "
+ ex.getMessage(), "Chat Error",
JOptionPane.ERROR_MESSAGE);
}
}
}
public void windowOpened(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
try {
if (chat != null) {
chat.terminate();
}
} catch (Throwable ex) {
JOptionPane.showMessageDialog(this,
"Error leaving chat: "
+ ex.getMessage(), "Chat Error",
JOptionPane.ERROR_MESSAGE);
}
dispose();
}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}

// Invoked by the MulticastChat receive thread when a message has arrived
public void chatMessageReceived(String username, InetAddress address,
int port, String message) {
log(message);
}

// Invoked by the MulticastChat receive thread when a user has joined
public void chatParticipantJoined(String username, InetAddress address,
int port) {
log("+++ " + username + " has joined from " + address.getHostName()
+ ":" + port);
}

// Invoked by the MulticastChat receive thread when a user has left
public void chatParticipantLeft(String username, InetAddress address,
int port) {
log("--- " + username + " has left from " + address.getHostName() + ":"
+ port);
}

// Command-line invocation expecting three arguments
public static void main(String[] args) {
if ((args.length != 5) && (args.length != 6)) {
System.err.println("Usage: MulticastChatFrame "
+ "<username> <group> <port1> <ip> <port2> { <ttl> }");
System.err.println(" - default time-to-live value is 1");
System.exit(1);
}

String username = args[0];
InetAddress group = null;
int port1 = -1;
int ttl = 1;

try {
group = InetAddress.getByName(args[1]);
} catch (Throwable e) {
System.err.println("Invalid multicast group address: "
+ e.getMessage());
System.exit(1);
}

if (!group.isMulticastAddress()) {
System.err.println("Group argument '" + args[1]
+ "' is not a multicast address");
System.exit(1);
}

try {
port1 = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
System.err.println("Invalid port number argument: " + args[2]);
System.exit(1);
}

if (args.length >= 6) {
try {
ttl = Integer.parseInt(args[5]);
} catch (NumberFormatException e) {
System.err.println("Invalid TTL number argument: " + args[3]);
System.exit(1);
}
}

try {
MulticastChatFrame frame = new MulticastChatFrame();
frame.setSize(480, 400);

frame.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});

frame.show();

frame.join(username, group, port1, ttl);
} catch (Throwable e) {
System.err.println("Error starting frame: " + e.getClass().getName()
+ ": " + e.getMessage());
System.exit(1);
}
}
}



作者 Re:菜鸟求助!急!!!!!!!!!!!!!! [Re:Bethy]
JavaandC





发贴: 230
积分: 15
于 2006-05-14 08:41 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你可不可以把想问的问题提出来啊,你的程序很乱,你最好把想问的问题说出来,让大家帮你解决一下。



作者 Re:菜鸟求助!急!!!!!!!!!!!!!! [Re:Bethy]
Bethy





发贴: 2
积分: 0
于 2006-05-14 11:22 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
做一个基于P2P的共享文件系统,分为三块:本地共享,网络共享和下载文件;有两个按钮:共享和下载。本地共享是自己的资源,网络共享是其他用户可以看见的。点击共享按钮可以将本地共享里面的东西上传至网络共享中,点击下载则可以把网络共享里的东西下载下来!基本要实现的功能是这样的。现在我的问题是我只能上传一个目录,本地共享里面的其他目录上传不了,我需要做一个循环,点击“共享”时可以把我本地共享里的目录一个一个的上传至网络共享。还有把用户名,IP地址,端口号,文件名做一个定长的设置,用“|”隔开,并显示出来。

承蒙各位帮助,不胜感激~~




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923