⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectframe.java

📁 rmi C/S 客 户 端 与 服 务 端 连 接
💻 JAVA
字号:
package com.topking.rt.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import com.topking.rt.data.ConnectData;

/*
 * ConnectFrame.java
 *
 * Created on 2009年2月9日, 下午6:03
 */



/**
 *
 * @author  lzkj
 */
public class ConnectFrame extends Observable implements ActionListener{

    /** Creates new form ConnectFrame */
    public ConnectFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    	frame = new JFrame("Connection args");
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txt_host = new javax.swing.JTextField();
        txt_port = new javax.swing.JTextField();
        bt_conn = new javax.swing.JButton();
        bt_cancel = new javax.swing.JButton();
        
//        frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Host");

        jLabel2.setText("Port");

        bt_conn.setText("Connect");
        
        txt_host.setText("192.168.1.100");
        txt_port.setText("9999");

        bt_cancel.setText("Cancel");

        bt_conn.addActionListener(this);
        bt_cancel.addActionListener(this);
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(frame.getContentPane());
        frame.getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txt_port)
                            .addComponent(txt_host, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(bt_conn, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(bt_cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txt_host, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txt_port, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_cancel)
                    .addComponent(bt_conn))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        frame.pack();
        frame.setVisible(true);
    }// </editor-fold>


    public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource()==bt_conn){
			String host = txt_host.getText().trim();
			String sport = txt_port.getText().trim();
			if(validateData(host)&&validateData(sport)){								
				try{
					ConnectData arg = new ConnectData();
					int port = Integer.parseInt(sport);
					arg.setHost(host);
					arg.setPort(port);
					this.setConnArg(arg);					
					frame.dispose();
				}catch(Exception ex){
					JOptionPane.showMessageDialog(frame, "Exception:"+ex.getMessage(),"ERROR",JOptionPane.ERROR_MESSAGE);
				}				
			}
		}
		if(e.getSource()==bt_cancel){
			frame.dispose();
		}
	}

	public boolean validateData(String input){
		boolean flag = false;
		if(input!=null&&!"".equals(input)){
			flag = true;
		}else{
			JOptionPane.showMessageDialog(frame, "ERROR INPUT","ERROR",JOptionPane.ERROR_MESSAGE);
		}
		return flag;
	}
    
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ConnectFrame();
            }
        });
    }

    // Variables declaration - do not modify
    private JFrame  frame;
    private javax.swing.JButton bt_cancel;
    private javax.swing.JButton bt_conn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField txt_host;
    private javax.swing.JTextField txt_port;
    
    private ConnectData connArg;
    // End of variables declaration	

	public ConnectData getConnArg() {
		return connArg;
	}

	public void setConnArg(ConnectData connArg) {
		this.connArg = connArg;
		System.out.println(connArg.getHost()+":"+connArg.getPort());
		this.setChanged();
		System.err.println("ConnectFrame's connArg Changed......");
		this.notifyObservers(connArg);		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -