📄 senduser.java
字号:
/*
* Created on 2003-7-15
*/
package com.liuyang.jboss.message.jms.topic;
/**
* @author 刘洋
*/
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 SendUser extends JFrame{
public static void main(String[] args) {
SendUser user = new SendUser();
user.init();
}
public SendClient client = new SendClient();
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 {
String data = client.send("发送时间:"+System.currentTimeMillis());
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) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.exit(0);
}
}
);
this.setTitle("MQ发送数据客户端");
this.show();
}
private boolean started = false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -