package ui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
/**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used
* commercially (ie, by a corporation, company or business for any purpose
* whatever) then you should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class UDPDialog extends javax.swing.JDialog implements ActionListener {
{
// Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager
.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*
*/
private static final long serialVersionUID = 1L;
private JLabel jLabelIP;
private ButtonGroup buttonGroup;
private JRadioButton jRadioButtonServer;
private JRadioButton jRadioButtonClient;
private JPanel jPanel1;
private JButton jButtonCancel;
private JButton jButtonOK;
private JTextField jTextFieldSelfPort;
private JLabel jLabelSelfPortable;
private JTextField jTextFieldPort;
private JLabel jLabelPort;
private JTextField jTextFieldName;
private JLabel jLabel1;
private JComboBox jComboBoxIP;
private MainFrame mainframe;
/**
* Auto-generated main method to display this JDialog
*
* public static void main(String[] args) { SwingUtilities.invokeLater(new
* Runnable() { public void run() { JFrame frame = new JFrame(); UDPDialog
* inst = new UDPDialog(frame); inst.setVisible(true); } }); }
*/
public UDPDialog(MainFrame frame) {
super(frame);
mainframe = frame;
initGUI();
}
private void initGUI() {
try {
{
getContentPane().setLayout(null);
this.setTitle("\u7f51\u7edc\u8bbe\u7f6e");
this.setAlwaysOnTop(true);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
this.setPreferredSize(new java.awt.Dimension(360, 350));
}
{
jLabelIP = new JLabel();
getContentPane().add(jLabelIP, "Center");
jLabelIP.setText("\u76ee\u7684\u4e3b\u673a\u7684IP\uff1a");
jLabelIP.setBounds(40, 176, 97, 16);
}
{
jLabelPort = new JLabel();
getContentPane().add(jLabelPort);
jLabelPort
.setText("\u76ee\u7684\u4e3b\u673a\u7aef\u53e3\u53f7\uff1a");
jLabelPort.setBounds(40, 224, 100, 17);
}
{
jTextFieldPort = new JTextField();
getContentPane().add(jTextFieldPort);
jTextFieldPort.setBounds(147, 221, 173, 23);
}
{
jLabelSelfPortable = new JLabel();
getContentPane().add(jLabelSelfPortable);
jLabelSelfPortable
.setText("\u672c\u673a\u7aef\u53e3\u53f7\uff1a");
jLabelSelfPortable.setBounds(40, 131, 108, 17);
}
{
jTextFieldSelfPort = new JTextField();
getContentPane().add(jTextFieldSelfPort);
jTextFieldSelfPort.setBounds(147, 128, 173, 23);
}
{
jButtonOK = new JButton();
getContentPane().add(jButtonOK);
jButtonOK.setText("\u786e\u5b9a");
jButtonOK.setBounds(70, 275, 75, 25);
jButtonOK.addActionListener(this);
}
{
jButtonCancel = new JButton();
getContentPane().add(jButtonCancel);
jButtonCancel.setText("\u53d6\u6d88");
jButtonCancel.setBounds(199, 275, 75, 25);
jButtonCancel.addActionListener(this);
}
{
jPanel1 = new JPanel();
getContentPane().add(jPanel1);
getContentPane().add(getJComboBoxIPx());
getContentPane().add(getJLabel1());
getContentPane().add(getJTextFieldName());
getContentPane().add(getJComboBoxIP());
jPanel1.setBounds(18, 10, 302, 54);
jPanel1.setLayout(null);
jPanel1.setBorder(BorderFactory
.createTitledBorder("\u8bf7\u9009\u62e9"));
{
jRadioButtonClient = new JRadioButton();
jPanel1.add(jRadioButtonClient);
jRadioButtonClient
.setText("\u4f5c\u4e3a\u8bf7\u6c42\u65b9");
jRadioButtonClient.setBounds(41, 24, 85, 23);
jRadioButtonClient.addActionListener(this);
}
{
jRadioButtonServer = new JRadioButton();
jPanel1.add(jRadioButtonServer);
jRadioButtonServer
.setText("\u4f5c\u4e3a\u88ab\u8bf7\u6c42\u65b9");
jRadioButtonServer.setBounds(163, 24, 97, 23);
jRadioButtonServer.addActionListener(this);
}
getButtonGroup().add(jRadioButtonClient);
getButtonGroup().add(jRadioButtonServer);
}
pack();
this.setSize(360, 350);
this.setLocation(mainframe.getLocation().x,mainframe.getLocation().y+80);
} catch (Exception e) {
e.printStackTrace();
}
}
private ButtonGroup getButtonGroup() {
if (buttonGroup == null) {
buttonGroup = new ButtonGroup();
}
return buttonGroup;
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == jButtonOK) {
if (!jRadioButtonClient.isSelected()
&& !jRadioButtonServer.isSelected()) {
JOptionPane
.showMessageDialog(this, "请选择作为请求方还是被请求方!", "请选择", 1);
return;
}
int port;
try {// 检查端口号是否合法
port = Integer.parseInt(jTextFieldSelfPort.getText());
if (port < 1024 || port > 65535) {
throw new Exception("输入的端口号非法!");
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "请输入1024--65535之间的端口号!",
"本地端口号非法", 0);
return;
}
if(!mainframe.isServer()){
try {
int objport = Integer.parseInt(jTextFieldPort.getText());
if (objport > 65535 || objport < 1024) {
throw new Exception("输入的目标主机的端口号非法!");
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"请输入1024--65535之间的端口号!", "目标主机端口号非法", 0);
return;
}
}
this.dispose();
// 作为请求方
if (!mainframe.isServer()) {
mainframe.setPort(Integer.parseInt(jTextFieldPort.getText()));// 设置目标端口号
mainframe.setIPAddress((String) jComboBoxIP.getSelectedItem());
}
if(jTextFieldName.getText().isEmpty()){
mainframe.setTitle("客户端");
}
mainframe.setTitle(jTextFieldName.getText());
mainframe.setSelfPort(Integer
.parseInt(jTextFieldSelfPort.getText()));
// System.out.println((String)jComboBoxIP.getSelectedItem());
mainframe.initSocket(port);
mainframe.setEnabled(true);
mainframe.getjRadioButtonTCP().setEnabled(false);
mainframe.getjRadioButtonUDP().setEnabled(false);
mainframe.getUdpChatPanel().receive();
} else if (e.getSource() == jButtonCancel) {
mainframe.getjRadioButtonTCP().setSelected(false);
mainframe.getjRadioButtonUDP().setSelected(false);
this.dispose();
mainframe.setEnabled(true);
} else if (e.getSource() == jRadioButtonClient) {// 选择作为请求方
mainframe.setIsServer(false);
jTextFieldPort.setVisible(true);
jComboBoxIP.setVisible(true);
jLabelIP.setVisible(true);
jLabelPort.setVisible(true);
if(jButtonOK.getLocation().y == 175){
jButtonOK.setLocation(jButtonOK.getLocation().x, jButtonOK.getLocation().y+100);
jButtonCancel.setLocation(jButtonCancel.getLocation().x, jButtonCancel.getLocation().y+100);
setSize(getSize().width,getSize().height+100);
}
} else if (e.getSource() == jRadioButtonServer) {// 选择作为被请求方
mainframe.setIsServer(true);
jTextFieldPort.setVisible(false);
jComboBoxIP.setVisible(false);
jLabelIP.setVisible(false);
jLabelPort.setVisible(false);
if(jB
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
MyQQ.rar (32个子文件)
MyQQ
myQQ.jar 27KB
.project 380B
bin
udp
UDPChat.class 3KB
server
ServerThread.class 2KB
Server.class 2KB
client
ClientThread.class 1KB
Client.class 3KB
ui
MyThread.class 595B
UDPThread.class 982B
ServerPanel.class 3KB
UDPChatPanel$1.class 2KB
TCPDialog.class 7KB
MainFrame$1.class 628B
MainFrame.class 8KB
TCPChatPanel.class 4KB
UDPDialog.class 8KB
TCPChatPanel$1.class 1KB
UDPChatPanel.class 4KB
.settings
org.eclipse.jdt.core.prefs 629B
src
udp
UDPChat.java 3KB
server
Server.java 1KB
ServerThread.java 1KB
client
ClientThread.java 652B
Client.java 2KB
ui
MainFrame.java 9KB
UDPDialog.java 10KB
UDPChatPanel.java 6KB
ServerPanel.java 3KB
TCPDialog.java 8KB
TCPChatPanel.java 5KB
res
apple.png 21KB
.classpath 295B
共 32 条
- 1
资源评论
- wszx13152013-12-23使用之后,与我所想软件相差很多。。。
- u0111550282013-12-09本身对winsock编程不是很懂,但是下载了程序之后用起来还是很方便。
rockflying
- 粉丝: 1
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功