|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Swing to MQSeirs |
« View previous topic :: View next topic » |
Author |
Message
|
yatheen |
Posted: Thu Mar 28, 2002 12:43 am Post subject: |
|
|
Newbie
Joined: 27 Mar 2002 Posts: 2 Location: INDIA
|
//Swing Demo
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.TextListener.*;
import com.ibm.mq.*;
/*
<html>
<applet code="swingDemo" width=450 height=200>
</applet>*/
public class swingDemo extends JApplet implements ActionListener{
Container c;
JLabel lport,lchannel,lqueue,ltitle;
JTextField tport,tchannel,tqueue,tsend,tres;
JButton bsend,bres,bcqueue,bclear;
Image i;
//defining the Queue Manager Name
String qManager = " YADAV";
//define the Queue Manager
MQQueueManager qMgr;
//settuing the Queue Name
MQQueue qName;
String squeue;
MQMessage sendMessage;
public void init(){
//declaring the label names
lport = new JLabel("IP ADDRESS");
lchannel = new JLabel("CHANNEL NAME");
lqueue = new JLabel("QUEUE NAME");
ltitle = new JLabel("eComServer India Pvt Ltd., Hyderabad");
//declaring the text fields
tport = new JTextField("90.0.0.218");
tchannel = new JTextField("CHANNEL1");
tqueue = new JTextField("QUEUE2");
tsend = new JTextField(50);
tres = new JTextField(50);
//declaring buttons
bsend = new JButton("SEND MESG");
bres = new JButton("REC MSG");
bcqueue = new JButton("CreateQueue");
bclear = new JButton("Clear");
//adding the components to applet
c=this.getContentPane();
c.setLayout(null);
Font f=new Font("Aerial",Font.BOLD,20);
ltitle.setFont(f);
Font ff=new Font("Aerial",Font.BOLD,10);
bsend.setFont(ff);
bres.setFont(ff);
bcqueue.setFont(ff);
bclear .setFont(ff);
ltitle.setForeground(Color.darkGray);
c.add(ltitle).setBounds(20,10,400,30);
c.add(lport).setBounds(20,40,80,30);
c.add(lchannel).setBounds(20,70,120,30);
c.add(lqueue).setBounds(20,100,130,30);
c.add(tport).setBounds(150,40,200,20);
c.add(tchannel).setBounds(150,70,200,20);
c.add(tqueue).setBounds(150,100,200,20);
c.add(bsend).setBounds(20,140,100,20);
c.add(bres).setBounds(20,170,100,20);
c.add(tsend).setBounds(150,140,200,20);
c.add(tres).setBounds(150,170,200,20);
c.add(bcqueue).setBounds(350,40,100,80);
c.add(bclear).setBounds(350,140,100,50);
//adding to the actionListeners
bclear.addActionListener(this);
bres.addActionListener(this);
bcqueue.addActionListener(this);
bsend.addActionListener(this);
//Setting the tooltiptext
bsend.setToolTipText("Message Sender");
bres.setToolTipText("Message Receiver");
bclear.setToolTipText("Clear");
bcqueue.setToolTipText("Create Queue");
//setting the Environment variables
String sport=tport.getText();
System.out.print(sport);
String schannel=tchannel.getText();
System.out.print(schannel);
MQEnvironment.hostname=sport;
MQEnvironment.channel=schannel;
}//end of init method
//start method to set the Queue Manager and other connection
public void start(){
try{
//creating the Queue Manager
qMgr=new MQQueueManager(qManager);
//setting the options
int openOperation=MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
//setting the Queue Name
String squeue=tqueue.getText();
qName=qMgr.accessQueue(squeue,openOperation,null,null,null);
}//End of Try block
catch(MQException exp){
exp.printStackTrace();
}//end of MQException Catch
}//end of the Start method
//action Performd method for Button
public void actionPerformed(ActionEvent evt){
try{
if(evt.getSource() == bsend){
tres.setText(" ");
System.out.print("U R IN bsend");
sendMessage=new MQMessage();
String sendText=tsend.getText();
sendMessage.writeUTF(sendText);
MQPutMessageOptions pmo=new MQPutMessageOptions();
qName.put(sendMessage);
tsend.setText(" ");
System.out.print("The Message has put Successfully");
}//end of bsend if
}//end of try
catch(MQException ex){
ex.printStackTrace();
}//end of the catch
catch(java.io.IOException e){
e.printStackTrace();
}//end of the catch
if(evt.getSource() == bres){
System.out.print("U R IN bres");
try{
//creating the buffer
MQMessage retrivedMessage=new MQMessage();
//retrivedMessage.messageId=sendMessage.messageId;
MQGetMessageOptions gmo=new MQGetMessageOptions();
qName.get(retrivedMessage,gmo);
String srec=retrivedMessage.readUTF();
if(srec!=null){
tres.setText(srec);
}
else{
tres.setText("X");
}
}//end of try
catch(MQException exp){
exp.printStackTrace();
}//end of the catch
catch(Exception e){
e.printStackTrace();
}//end of catch
}//end of bres if
if(evt.getSource() == bcqueue){
System.out.print("U R IN Cqueue");
try{
//setting the options
int openOperation=MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
//setting the Queue Name
squeue=tqueue.getText();
System.out.print(squeue);
qName=qMgr.accessQueue("MODQUEUE",openOperation,null,squeue,null);
System.out.print("Q Created");
}
catch(MQException ex){
ex.printStackTrace();
}//end of the catch
}//end of cqueueu if
if(evt.getSource()==bclear){
tsend.setText(" ");
tres.setText(" ");
System.out.println("u r in BClear");
}//end of clear button
}//end of action method
}//End of the class
_________________ A Y N YADAV |
|
Back to top |
|
 |
bduncan |
Posted: Thu Mar 28, 2002 12:43 pm Post subject: |
|
|
Padawan
Joined: 11 Apr 2001 Posts: 1554 Location: Silicon Valley
|
Are you asking for help with regards to this code, or are you just posting a sample program?
_________________ Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|