sam sawant

Greenhorn
+ Follow
since Mar 26, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sam sawant

/*
* sam2.java
*
* Created on April 7, 2009, 5:27 PM
*/

package md;

/**
*
* @author Rashilant
*/

import java.lang.String;
import java.net.*;
import java.io.*;
import javax.swing.ComboBoxModel;

public class sam2 extends javax.swing.JFrame {
String us="";
static PrintWriter readerOut = null;
static BufferedReader readerIn = null;

static Socket socket = null;
static int port = 8080;

/** Creates new form sam2 */
public sam2() {
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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
jComboBox2 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel3 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMaximizedBounds(new java.awt.Rectangle(0, 0, 100, 100));
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ASTRA", "XTENNA", "ALIEN" }));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
a4(evt);
}
});

jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4", "192.168.0.101" }));

jButton1.setText("CONNECT");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
a1(evt);
}
});

jButton2.setText("START");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
a2(evt);
}
});

jButton3.setText("STOP");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
a3(evt);
}
});

jLabel1.setText("SELECT IP ADDRESS");

jLabel2.setText("OUTPUT");

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);

jLabel3.setText("SELECT READER");

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(35, 35, 35)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jButton1)
.add(jLabel1))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap(54, Short.MAX_VALUE)
.add(jLabel2)
.add(42, 42, 42)))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.add(jLabel3)
.add(20, 20, 20)))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(119, 119, 119)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, jComboBox1, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jComboBox2, 0, 128, Short.MAX_VALUE))
.addContainerGap(307, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 541, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(138, 138, 138)
.add(jButton2)
.add(114, 114, 114)
.add(jButton3)))
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel3))
.add(57, 57, 57)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1))
.add(63, 63, 63)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton2)
.add(jButton1)
.add(jButton3))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(75, 75, 75)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
.addContainerGap())
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel2)
.add(112, 112, 112))))
);
pack();
}// </editor-fold>

private void a3(java.awt.event.ActionEvent evt) {

try {
readerOut.flush();
readerOut.close();
readerIn.close();
socket.close();
} catch (Exception e) {
System.out.println("Exception in TMReaderAdapter.shutdown(): " + e.getMessage());
} finally {
socket = null;
}//end finally
//end shutdown method

jTextArea1.setText("");
// TODO add your handling code here:STOP
}

private void a4(java.awt.event.ActionEvent evt) {

String us1 = (String)jComboBox1.getSelectedItem();
if(us1.equals("ASTRA"))
{
//String msg1[]={"192.168.0.101","a1","a2"};
jComboBox2.removeAllItems();

jComboBox2.addItem("192.168.0.101");

jComboBox2.addItem("192.168.0.181");
jComboBox2.addItem("192.168.0.191");


}

else if(us1.equals("XTENNA"))
{
//String msg1[]={"192.168.0.101","a1","a2"};
jComboBox2.removeAllItems();

jComboBox2.addItem("19");

jComboBox2.addItem("192.");
jComboBox2.addItem("192.1");


}
else if(us1.equals("ALIEN"))
{
//String msg1[]={"192.168.0.101","a1","a2"};
jComboBox2.removeAllItems();

jComboBox2.addItem("192.168");

jComboBox2.addItem("192.168.0");
jComboBox2.addItem("192.168.");


}


// TODO add your handling code here:Combo astra
}

private void a2(java.awt.event.ActionEvent evt) {

//static void get(String us)
String ipaddr;
ipaddr = us;
String command = "";
try {
socket = new Socket(ipaddr, port);
readerOut = new PrintWriter(socket.getOutputStream(), true);
readerIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println("connected to RQL socket");

} catch (Exception e) {
System.out.println("Unable to connect to ThingMagic reader: " + e.getMessage());
try {
throw new IOException();
} catch (IOException ex) {
ex.printStackTrace();
}
}//end of catch


System.out.printf ("Connected to reader %s", ipaddr);


command = "SELECT id FROM tag_id;";

System.out.println (command);
//void tellReader(command, true);
//int i=100;

try{
while (true)
{

//command = "UPDATE saved_settings SET tx_power='" + i + "';"; //set the power
//System.out.println (command);
//tellReader(command, true);
command = "SELECT id FROM tag_id;"; //set the power
System.out.println (command);
tellReader(command, true);
Thread.sleep(100);
//i=i+100;

}//end while
}catch (Exception e){
System.out.print ("cmdBuffer Failed!!!");

}//end catch


shutdown();

return;
}//end of main



//Methods
void shutdown() {

try {
readerOut.close();
readerIn.close();
socket.close();
} catch (Exception e) {
System.out.println("Exception in TMReaderAdapter.shutdown(): " + e.getMessage());
} finally {
socket = null;
}//end finally
}//end shutdown method

/*void stopdown(String newtag) {
jTextArea1.append("Response tag is ===== "+newtag+"\n");


}*/
//Pass RQL commands to reader and wait for response
void tellReader (String cmd, boolean getResponse) throws IOException {
String data;

System.out.println("Tell reader: " + cmd);
jTextArea1.append("tell reader"+cmd+"\n");
try {
readerOut.println(cmd); // Send command to reader
} catch (Exception e) {
System.out.println("Exception sending command to ThingMagic reader: " + e.getMessage());
throw new IOException();
}

if (!getResponse)
return;
while (true) { // Loop until success or error. Ignore data
try {
data = readerIn.readLine();
} catch (Exception e) {
System.out.println("Exception reading command from ThingMagic reader: " + e.getMessage());
throw new IOException();
}

if (data.length() == 0)
return;
// success
String newtag=data.substring(2,26) ;
System.out.println("Response tag is ===== " + newtag);

jTextArea1.append("Response tag is ===== "+newtag+"\n");
if (data.length() >= 5) {
if (data.startsWith("Error")) {
System.out.println("Response= " + data);
throw new IOException();
}
}
// stopdown(newtag);

// return;
}
//TextArea1.
//}

// TODO add your handling code here:start

}

private void a1(java.awt.event.ActionEvent evt) {

us = (String)jComboBox2.getSelectedItem();


//ps=Integer.ParseInt(jTextField2.getText());
try{

Socket s=new Socket(us,8080);
System.out.println("connected");
jTextArea1.setText("connected\n");


}
catch(Exception x){
}
// TODO add your handling code here:connect
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new sam2().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JComboBox jComboBox2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration

}
12 years ago
i want to print output in textarea
my output is continuous ,when connection with particular socket is established,which is a reader, it reads continuous tags.
so what i appended the variable in which tha tag value has been stored to text area
but problem is that it is not appending as output is so continuous & variable value is changing continuously

so i am not getting anything in textarea, so what is the way to read fast & continuous output
12 years ago
if i throw io.exception then it becomes incompatible
where to add that catch? to constructor?
12 years ago
i am beginner in java
so if you please tell me in detail, how can i do it?
12 years ago
its a normal output,in my case its tag id read by reader.
12 years ago
i want to pass value of text field of 1 frame to a function which is another java class file

as we did this using constructor,we are geting error io.exception should be thrown or caught
12 years ago
how to display command prompt output of 1 frame to text area of other frame?
what exactly i have to do ?
12 years ago
whats the syntax to change combobox model?
12 years ago
i have 2 comboboxes
when i click on any item of combo box,other combobox values should change.
for eg
in 1st combobox values are(a,b,c)
if i select a
it shud display 1,2,3 in another combobox
sameways for b & c shud display something else

plzz help me
12 years ago

in my program
i want ipaddress & port number to be entered by the user in text fields. this values should passed to socket connection

what i did
ipaddress=tf1.gettext()
port_no.=tf2.gettext()

& then

Socket s=new socket(ipaddress,port_no);


but this doesn't work....so do help me out......
the prob is when i converted this code to java is not working with the hardware,
especiallt the read tag function,
so do help me to convert read tag function in java


while reading from a keyboard we use readline() method, so what will be the inbuilt method to read from a hardware.
12 years ago


this is a code in c# i want to convert it to java , specially the part where tag from the reader can be read & then printed to PC


[ EJFH: Added code tags. ]
12 years ago