|
<FONT size=+0><!-- 固定文字颜色 -->/*
* @(#)NetSend.java 0.1 05/12/2003
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*Sample application using "net send" to send message
*
*@author WFoxd
*@version 0.1 05/12/2003
*/
public class NetSend{
public NetSend(){
NetSendWander wander = new NetSendWander(null,null,null);
NetSendGUI gui = new NetSendGUI(wander);
}
public static void main(String[] s){
new NetSend();
}
}
///////////////////////////////////////////
/*
*@(#) NetSendGUI.java 0.1 05.12.2003
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*Create GUI
*/
class NetSendGUI implements ActionListener{
final NetSendWander wander;
JTextArea area;
JComboBox combo;
JFrame frame;
private static ResourceBundle resources;
static{
try{
resources = ResourceBundle.getBundle("resources.NetSendGUI",
Locale.getDefault());
}catch(MissingResourceException mre){
System.err.println("resources.NetSendGUI.properties 没有找到!");
System.exit(1);
}
}
public NetSendGUI(NetSendWander wand){
this.wander = wand;
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e){}
frame = new JFrame();
Container contentpane = frame.getContentPane();
contentpane.setLayout(null);
contentpane.setBackground(Color.white);
frame.setJMenuBar(buildMenu());
buildView(contentpane);
frame.setTitle(resources.getString("Title"));
frame.setBounds(300,200,300,400);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
wander.exitToWindows();
}
});
}
private JMenuBar buildMenu(){
JMenuBar mbar = new JMenuBar();
mbar.setOpaque(true);
JMenu file = new JMenu("文件(F)");
file.setMnemonic('F');
mbar.add(file);
JMenuItem quit = new JMenuItem("退出(X)");
file.setMnemonic('X');
file.add(quit);
quit.addActionListener(this);
JMenu about = new JMenu("帮助(H)");
about.setMnemonic('H');
mbar.add(about);
JMenuItem aboutthis = new JMenuItem("关于 " + resources.getString("Title") + "....");
aboutthis.addActionListener(this);
about.add(aboutthis);
return mbar;
}
public void buildView(Container contentpane){
combo = new JComboBox();
combo.setBorder(BorderFactory.createTitledBorder("请选择接收者"));
combo.setEditable(true);
// ComboBoxEditor editor = combo.getEditor();
contentpane.add(combo);
combo.setBounds(5,10,280,40);
area = new JTextArea();
area.setBorder(BorderFactory.createTitledBorder("请输入内容"));
area.setLineWrap(true);
JScrollPane sp = new JScrollPane(area,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
contentpane.add(area);
area.setBounds(5,60,280,200);
JButton button = new JButton("发送(S)");
button.setMnemonic('S');
contentpane.add(button);
button.setBounds(100,300,80,20);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
String event = e.getActionCommand();
if(event.equals("退出(X)")){
wander.exitToWindows();
}else if(event.equals("关于 " + resources.getString("Title") + "....")){
wander.aboutThis();
}else if(event.equals("发送(S)")){
String str1 = (String)combo.getSelectedItem();
String str2 = area.getText();
if(str1.equals("")){
JOptionPane.showMessageDialog(frame,"接收者必须填写!","错误",JOptionPane.ERROR_MESSAGE);
}
wander.sendMes(str1,str2,frame);
}
}
}//////////////////////////////
/*
*@(#) NetSendWander.java 0.1 05/12/2003
*/
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*method to do
*/
class NetSendWander extends Thread{
String[] str = new String[2];
JFrame frame;
public NetSendWander(String str1,String str2,JFrame frame){
this.str[0] = str1;
this.str[1] = str2;
this.frame = frame;
}
public void exitToWindows(){
System.exit(1);
}
public void aboutThis(){
JOptionPane.showMessageDialog(frame,"消息发送机 \n版本:0.1 \n作者:风狐 \n时间:2003年5月","关于 NetSend",JOptionPane.INFORMATION_MESSAGE);
}
public void sendMes(String str1,String str2,JFrame frame){
new NetSendWander(str1,str2,frame).start();
// this.start();
}
public void run(){
String[] exec = {"net","send",str[0],str[1]};
try{
Process pro = Runtime.getRuntime().exec(exec);
try{
pro.waitFor();
switch(pro.exitValue()){
case 0:JOptionPane.showMessageDialog(frame,"消息发送成功!","恭喜",JOptionPane.INFORMATION_MESSAGE);break;
case 2:JOptionPane.showMessageDialog(frame,"消息没有发送成功!","错误",JOptionPane.ERROR_MESSAGE);break;
default :JOptionPane.showMessageDialog(frame,"不知名的错误!!","错误",JOptionPane.ERROR_MESSAGE);
}
}catch(InterruptedException e){}
}catch(IOException e){}
}
}
建议在自己机器上做实验啊,不要影响别人,
或者改成多线程,去掉JUI界面,哈哈,大发特发,
发死自己的机器
</FONT> |
|