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

📄 recvuser.java

📁 精通Jboss——Ejb和Web Services开发精解的随书源代码
💻 JAVA
字号:
/*
 * Created on 2003-7-15
 */
package com.liuyang.jboss.message.jms.topic;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.jms.JMSException;
import javax.naming.NamingException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;


/**
 * @author 刘洋
 */
public class RecvUser extends JFrame{

	public static void main(String[] args) {
		RecvUser user = new RecvUser();
		user.init();
	}
	public RecvClient client = new RecvClient();
	public JTextArea textarea = new JTextArea("数据监视窗口");
	public void init(){
		JButton startbtn = new JButton("开始");
			ActionListener start = new ActionListener(){
				public void actionPerformed(ActionEvent arg0) {
					if(!started){
						try {
							client.setup();
							started = true;
						} catch (NamingException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (JMSException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}
			};
		startbtn.addActionListener(start);
		this.getContentPane().add(BorderLayout.WEST,startbtn);

		JButton recvbtn = new JButton("接收");
			ActionListener recv = new ActionListener(){
				public void actionPerformed(ActionEvent arg0) {
					if(started){
						try {
							Object data = client.recv();
							if(data instanceof String){
								textarea.setText((String)data);
							}
							
						} catch (JMSException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}
			};
		recvbtn.addActionListener(recv);
		this.getContentPane().add(BorderLayout.NORTH,recvbtn);	
					
		JButton stopbtn = new JButton("停止");
			ActionListener stop = new ActionListener(){
				public void actionPerformed(ActionEvent arg0) {
					if(started){
						try {
							client.stop();
							started = false;
						} catch (JMSException e) {
							e.printStackTrace();
						}
					}
				}
			};
		stopbtn.addActionListener(stop);
		this.getContentPane().add(BorderLayout.EAST,stopbtn);
		this.getContentPane().add(BorderLayout.CENTER,textarea);
		this.setSize(100,200);
		this.setLocation(200,200);
		textarea.setSize(60,80);
		this.pack();
		this.addWindowListener(
			new WindowAdapter(){
				public void windowClosing(WindowEvent event) {
					if(started){
						try {
							client.stop();
						} catch (JMSException e) {
							e.printStackTrace();
						}
					}
					System.exit(0);
				}
			}
		);			
		this.setTitle("MQ接收数据客户端");	
		this.show();
	}
	private boolean started = false;
	
}

⌨️ 快捷键说明

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