JMS+ActiveMQ,实现有“用户界面”的消息 “发布/订阅”功能,寻求各位能人的帮助。最好有代码,谢谢。

Zero_Z_csdn 2016-06-03 01:10:18
运用Java,怎么实现“发布者”对用户界面里的文本发到 消息队列里,而“订阅者”能从队列里读取并显示在接收端的用户界面上? 而且可以实现不同主题的发布/订阅。

(信息发布界面代码)
public class DlgSend extends JDialog {

private final JPanel contentPanel = new JPanel();
private JTextField textField;

/**
* Launch the application.
*/
public static void main(String[] args) {
try {
DlgSend dialog = new DlgSend();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Create the dialog.
*/
public DlgSend() {
setTitle("\u53D1\u5E03\u754C\u9762");

setBounds(100, 100, 500, 355);
getContentPane().setLayout(null);
contentPanel.setBounds(0, 0, 488, 20);
contentPanel.setLayout(new FlowLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel);

JComboBox comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] {"\u8BF7\u9009\u62E9\u4E3B\u9898", "A", "B", "C", "D", "E", "F", "G"}));
//comboBox.addItem("1");
comboBox.setEditable(true);
comboBox.setBounds(112, 31, 321, 21);
getContentPane().add(comboBox);

JLabel lblNewLabel = new JLabel("\u4E3B \u9898\uFF1A");
lblNewLabel.setBounds(46, 30, 67, 22);
getContentPane().add(lblNewLabel);

JLabel lblNewLabel_1 = new JLabel("\u6807 \u9898\uFF1A");
lblNewLabel_1.setBounds(46, 82, 54, 15);
getContentPane().add(lblNewLabel_1);

textField = new JTextField();
textField.setBounds(112, 79, 321, 21);
getContentPane().add(textField);
textField.setColumns(10);

JLabel lblNewLabel_2 = new JLabel("\u6D88 \u606F\uFF1A");
lblNewLabel_2.setBounds(46, 128, 54, 15);
getContentPane().add(lblNewLabel_2);

JButton btnNewButton = new JButton("\u786E\u8BA4\u53D1\u5E03");
btnNewButton.setForeground(new Color(0, 0, 0));
btnNewButton.setBounds(337, 265, 93, 31);
getContentPane().add(btnNewButton);

TextArea textArea = new TextArea();
textArea.setBounds(112, 129, 323, 122);
getContentPane().add(textArea);
}
}


(订阅接收界面)
public class showsub extends JFrame {

private JPanel contentPane;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
showsub frame = new showsub();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public showsub() {
setTitle("\u8BA2\u9605\u754C\u9762");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 350);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lblNewLabel = new JLabel("\u4E3B \u9898\uFF1A");
lblNewLabel.setBounds(48, 37, 54, 15);
contentPane.add(lblNewLabel);

JComboBox comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] {"\u8BF7\u9009\u62E9\u4E3B\u9898", "A", "B", "C", "D", "E", "F", "G"}));
comboBox.setBounds(124, 34, 303, 21);
contentPane.add(comboBox);

JLabel lblNewLabel_1 = new JLabel("\u53D1\u5E03\u8005\uFF1A");
lblNewLabel_1.setBounds(48, 116, 54, 15);
contentPane.add(lblNewLabel_1);

JList list = new JList();
list.setModel(new AbstractListModel() {
String[] values = new String[] {"\uFF08\u663E\u793A\u63A5\u6536\u5230\u7684\u8BA2\u9605\u6D88\u606F\uFF09"};
public int getSize() {
return values.length;
}
public Object getElementAt(int index) {
return values[index];
}
});
list.setBounds(124, 115, 303, 154);
contentPane.add(list);

JButton btnNewButton = new JButton("\u786E\u8BA4\u8BA2\u9605");
btnNewButton.setBounds(334, 65, 93, 23);
contentPane.add(btnNewButton);
}
}




(显示消息内容界面)
public class ShowMsg extends JFrame {

private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ShowMsg frame = new ShowMsg();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public ShowMsg() {
setTitle("\u663E\u793A\u6D88\u606F\u5185\u5BB9");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 457, 350);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lblNewLabel = new JLabel("\u53D1\u5E03\u8005\uFF1A");
lblNewLabel.setBounds(21, 34, 54, 15);
contentPane.add(lblNewLabel);

textField = new JTextField();
textField.setBounds(85, 31, 296, 21);
contentPane.add(textField);
textField.setColumns(10);

JLabel lblNewLabel_1 = new JLabel("\u6807 \u9898\uFF1A");
lblNewLabel_1.setBounds(21, 79, 54, 15);
contentPane.add(lblNewLabel_1);

textField_1 = new JTextField();
textField_1.setBounds(85, 76, 296, 21);
contentPane.add(textField_1);
textField_1.setColumns(10);

JLabel label = new JLabel("\u5185 \u5BB9\uFF1A");
label.setBounds(21, 125, 54, 15);
contentPane.add(label);

TextArea textArea = new TextArea();
textArea.setBounds(85, 125, 296, 170);
contentPane.add(textArea);

JTextArea JTextArea = new JTextArea(4,22);
JTextArea.setLineWrap(true);
JTextArea.setWrapStyleWord(true);
}
}
...全文
239 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zero_Z_csdn 2016-06-03
  • 打赏
  • 举报
回复
JMS+ActiveMQ,实现有“用户界面”的消息 “发布/订阅”功能,寻求各位能人的帮助。最好有代码,谢谢。

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧