|
|
Hi there,
I am trying to get my swing panel to show a tooltip with the x,y coordinates of the point of the mouse location - whenever the mouse is sat at the location for 1 second or more.
Obviously this means that the tooltip invokation needs to respond to a mouse event of some sort.
THE CODE BENEATH IS THE PART OF MY PANEL CONSTRUCTOR:
//Register for mouse events on panel.
ScreenMouseListener myListener = new ScreenMouseListener();
addMouseListener(myListener);
addMouseMotionListener(myListener);
//THIS IS MY MOUSELISTENER CLASS...AND I NEED TO INVOKE THE TOOLTIP FROM HERE?
private class ScreenMouseListener extends MouseInputAdapter {
public void mousePressed(MouseEvent e) {
printOutput("Mouse Pressed", e);
isNearBlip(e);
}
private void isNearBlip(MouseEvent e) {
for (Point p1 : CurrentDisplayedAircraft) {
double x1 = p1.getX();
double y1 = p1.getY();
double x_dif=Math.abs(e.getX()-x1);
double y_dif=Math.abs(e.getY()-y1);
x_dif=Math.pow(x_dif, 2);
y_dif=Math.pow(y_dif, 2);
double sep=Math.sqrt(x_dif+y_dif);
//DISPLAY A TOOL TIP IF CLOSE TO THE POINT
if(sep<15){
//NEED TO CREATE A TOOLTIP SHOWING PROPERTIES
//OF P1 HERE...
}
}// end of for (ScreenTrajectory S : DisplayPositions) {
}
public void mouseReleased(MouseEvent e) {
printOutput("Mouse Released", e);
}
public void mouseMoved(MouseEvent e) {
printOutput("Mouse moved", e);
}
public void mouseDragged(MouseEvent e) {
printOutput("Mouse dragged", e);
}
public void mouseClicked(MouseEvent e) {
printOutput("Mouse Clicked", e);
}
void printOutput(String eventDescription, MouseEvent e) {
System.out.println(eventDescription
+ " (" + e.getX() + "," + e.getY() + ")"
+ " detected on "
+ e.getComponent().getClass().getName()
+ NL);
}
}
|
|
|
|
|
|
Sorry i cant see the example? iS it the remote control or the recording example and how do i get hold of source?
Thanks
|
|
|
|
|
All the projects have it to find source use ctrl-f source easy right?
|
|
|
|
|
Hi guys,
I have a problem in the following simple program of mine stated below. It's a simple program which enables the sending/receiving of messages(in bytes) from one PC to another. I'm sending the messages to Serial Comm ports R232 with Rxtcomm library.
There are two classes namely; serialCommMain and Comms.
serialCommMain is the GUI portion while Comms is the serial port comm portion.
I'm trying to send the messages over to another application in VB 6.0 in the other PC, as my other PC is using Windows 95 and unable to have java installed.
Although my other PC is able to verify that data is being sent through, the message isn't being displayed. The VB application I've created is working properly.
Kindly need help/assistance. thanks.
The code is as follows:
serialCommMain:
<br />
<small><br />
package SerialComm;<br />
import org.apache.commons.io.EndianUtils;<br />
<br />
public class serialCommMain extends JFrame{<br />
<br />
int indx = 9;<br />
static double number;<br />
static String Ans;<br />
private static final long serialVersionUID = 1L;<br />
static Container pane;<br />
<br />
static Insets insets;<br />
<br />
static JTabbedPane Menu = new JTabbedPane();<br />
<br />
Comms C1;<br />
<br />
<br />
<br />
public Timer timer;<br />
public int speed = 500;<br />
<br />
<br />
<br />
public byte[] BytetxtMsg;<br />
public byte[] readMsg = new byte[400];<br />
static JButton BtnTransmit;<br />
static JButton BtnPause;<br />
byte START_BYTE = (byte) 0xAA;<br />
byte Checksum;<br />
<br />
<br />
static JTextArea txtRx, txtTx;<br />
<br />
static JPanel Rx = new JPanel();<br />
static JPanel Tx = new JPanel();<br />
static TitledBorder Tx_Rx, Tx_Tx;<br />
<br />
<br />
static JLabel lblENT, lblDEC;<br />
static JFormattedTextField Entry;<br />
static JTextField Decipher;<br />
static JPanel ENT = new JPanel(new BorderLayout());<br />
static TitledBorder D_ENT;<br />
<br />
static JPanel DEC = new JPanel(new BorderLayout());<br />
static TitledBorder D_DEC;<br />
<br />
<br />
public serialCommMain() {<br />
super();<br />
BytetxtMsg = new byte[indx];<br />
<br />
}<br />
<br />
<br />
<br />
public static void main(String[] args) {<br />
showGUI();<br />
<br />
}<br />
<br />
public static void showGUI(){<br />
<br />
<br />
<br />
<br />
<br />
<br />
JFrame frame = new JFrame("Serial Comm.");<br />
frame.setSize(800, 600);<br />
frame.setLocation(150,50);<br />
<br />
<br />
pane = frame.getContentPane();<br />
insets = pane.getInsets();<br />
pane.setLayout(null);<br />
<br />
<br />
Tx_Rx = BorderFactory.createTitledBorder(Tx_Rx, "Receive Message: ", TitledBorder.LEFT, <br />
TitledBorder.CENTER, new Font("Verdana", Font.BOLD, 10));<br />
<br />
txtRx = new JTextArea(10,30);<br />
txtRx.setEditable(false);<br />
<br />
<br />
Rx.add(txtRx);<br />
Rx.setBorder(Tx_Rx);<br />
pane.add(Rx);<br />
<br />
<br />
Tx_Tx = BorderFactory.createTitledBorder(Tx_Tx, "Transmit Message: ", TitledBorder.LEFT, <br />
TitledBorder.CENTER, new Font("Verdana", Font.BOLD, 10));<br />
<br />
txtTx = new JTextArea(10,30);<br />
txtTx.setEditable(false);<br />
<br />
<br />
Tx.add(txtTx);<br />
Tx.setBorder(Tx_Tx);<br />
pane.add(Tx);<br />
<br />
<br />
<br />
lblENT = new JLabel("Transmit: ");<br />
lblENT .setFont(new Font("Verdana", Font.BOLD, 10));<br />
<br />
D_ENT = BorderFactory.createTitledBorder(D_ENT, "TX: ", TitledBorder.LEFT, <br />
TitledBorder.CENTER, new Font("Verdana", Font.BOLD, 10));<br />
<br />
<br />
Entry = new JFormattedTextField(Entry);<br />
Entry.setValue(new Double(number));<br />
Entry.setColumns(10);<br />
Entry.addPropertyChangeListener("value", new ButtonListener());<br />
<br />
<br />
<br />
<br />
ENT.add(Entry, BorderLayout.EAST);<br />
ENT.add(lblENT, BorderLayout.WEST);<br />
ENT.setBorder(D_ENT);<br />
pane.add(ENT);<br />
<br />
<br />
<br />
<br />
lblDEC = new JLabel("Received: ");<br />
lblDEC .setFont(new Font("Verdana", Font.BOLD, 10));<br />
<br />
D_DEC = BorderFactory.createTitledBorder(D_DEC, "RX: ", TitledBorder.LEFT, <br />
TitledBorder.CENTER, new Font("Verdana", Font.BOLD, 10));<br />
<br />
<br />
Decipher = new JTextField(25);<br />
Decipher.setEditable(false);<br />
<br />
DEC.add(Decipher, BorderLayout.EAST);<br />
DEC.add(lblDEC, BorderLayout.WEST);<br />
DEC.setBorder(D_DEC);<br />
pane.add(DEC);<br />
<br />
<br />
<br />
BtnTransmit = new JButton("Transmit");<br />
BtnTransmit.setFont(new Font("Verdana", Font.BOLD, 10));<br />
pane.add(BtnTransmit);<br />
BtnTransmit.addActionListener(new ButtonListener());<br />
<br />
BtnPause = new JButton("Pause");<br />
BtnPause.setFont(new Font("Verdana", Font.BOLD, 10)); <br />
pane.add(BtnPause);<br />
BtnPause.addActionListener(new ButtonListener());<br />
<br />
<br />
<br />
Rx.setBounds(insets.left+5, insets.top+5, Rx.getPreferredSize().width, Rx.getPreferredSize().height);<br />
Tx.setBounds(Rx.getX()+400, Rx.getY(), Tx.getPreferredSize().width, Tx.getPreferredSize().height);<br />
ENT.setBounds(Rx.getX(), Rx.getY()+200, ENT.getPreferredSize().width, ENT.getPreferredSize().height);<br />
DEC.setBounds(Tx.getX(), Tx.getY()+200, DEC.getPreferredSize().width, DEC.getPreferredSize().height);<br />
<br />
BtnTransmit.setBounds(ENT.getX(), ENT.getY()+ 150, BtnTransmit.getPreferredSize().width, BtnTransmit.getPreferredSize().height);<br />
BtnPause.setBounds(BtnTransmit.getX()+ 120, BtnTransmit.getY(), BtnPause.getPreferredSize().width, BtnPause.getPreferredSize().height);<br />
<br />
frame.addWindowListener(new WindowAdapter(){<br />
public void windowClosing(WindowEvent e){<br />
System.exit(0); <br />
}<br />
});<br />
<br />
frame.setVisible(true);<br />
}<br />
<br />
<br />
}<br />
<br />
class ButtonListener extends serialCommMain implements ActionListener, PropertyChangeListener{<br />
<br />
<br />
private static final long serialVersionUID = 1L;<br />
<br />
public ButtonListener(){<br />
<br />
<br />
timer = new Timer(); <br />
<br />
BytetxtMsg[0]= START_BYTE;<br />
}<br />
<br />
TimerTask Trx = new TimerTask(){<br />
<br />
<br />
public void run() {<br />
<br />
C1 = new Comms(); <br />
<br />
try{ <br />
C1.sendBytes(BytetxtMsg); <br />
} catch (Exception e) {<br />
System.err.println("ERROR: " + e.getMessage());<br />
}<br />
<br />
<br />
}<br />
};<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
public void actionPerformed(ActionEvent E) {<br />
Object Src = E.getSource();<br />
<br />
<br />
<br />
<br />
<br />
<br />
if (Src == BtnTransmit){<br />
<br />
timer.scheduleAtFixedRate(Trx, 100, speed);<br />
<br />
number = ((Number)Entry.getValue()).doubleValue();<br />
<br />
System.out.println(number);<br />
EndianUtils.writeSwappedDouble(BytetxtMsg, 2, reverse(number));<br />
} <br />
}<br />
<br />
public static double reverse(double x) {<br />
ByteBuffer bbuf = ByteBuffer.allocate(8);<br />
bbuf.order(ByteOrder.LITTLE_ENDIAN);<br />
bbuf.putDouble(x);<br />
bbuf.order(ByteOrder.BIG_ENDIAN);<br />
return bbuf.getDouble(0);<br />
}<br />
public void propertyChange(PropertyChangeEvent Evt) {<br />
<br />
<br />
} <br />
<br />
} <br />
</small>
Comms:
<br />
<small><br />
<br />
package SerialComm;<br />
<br />
public class Comms extends serialCommMain implements SerialPortEventListener {<br />
private CommPortIdentifier commPortId;<br />
private SerialPort serialPort;<br />
private OutputStream outStream;<br />
private InputStream inStream;<br />
private byte[] readBuffer = new byte[400];<br />
int SIZE; <br />
String S;<br />
int DisplayLen = 0;<br />
public Comms(){<br />
<br />
super();<br />
<br />
try{<br />
<br />
<br />
connect("COM2");<br />
}catch (Exception e) {<br />
System.err.println("ERROR: " + e.getMessage());<br />
<br />
}<br />
<br />
}<br />
<br />
public void connect(String portName) throws IOException {<br />
try {<br />
<br />
commPortId = CommPortIdentifier.getPortIdentifier(portName);<br />
<br />
<br />
serialPort = (SerialPort) commPortId.open(this.getClass().getName(), 2000);<br />
<br />
setSerialPortParameters();<br />
<br />
outStream = serialPort.getOutputStream();<br />
inStream = serialPort.getInputStream();<br />
<br />
<br />
} catch (NoSuchPortException e) {<br />
throw new IOException(e.getMessage());<br />
} catch (PortInUseException e) {<br />
throw new IOException(e.getMessage());<br />
} catch (IOException e) {<br />
serialPort.close();<br />
throw e;<br />
}<br />
<br />
<br />
}<br />
<br />
public void sendBytes (byte[] bytes)<br />
{<br />
try<br />
{<br />
<br />
SIZE = indx;<br />
for(int i = 0; i< SIZE; i++){ <br />
S = Integer.toString(ByteConversion(bytes[i]), 16) + " ";<br />
txtTx.append(S.toUpperCase());<br />
DisplayLen = txtTx.getLineCount();<br />
<br />
}<br />
<br />
<br />
txtTx.append("\n");<br />
<br />
if (DisplayLen > 8){<br />
txtTx.setText("");<br />
}<br />
<br />
<br />
outStream.write (bytes, 0, bytes.length);<br />
}<br />
<br />
catch (IOException e)<br />
{<br />
System.out.println("IOException" + e);<br />
} <br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
private void setSerialPortParameters() throws IOException {<br />
int baudRate = 9600;
<br />
try {<br />
serialPort.setSerialPortParams(<br />
baudRate,<br />
SerialPort.DATABITS_8,<br />
SerialPort.STOPBITS_1,<br />
SerialPort.PARITY_NONE);<br />
<br />
serialPort.setFlowControlMode(<br />
SerialPort.FLOWCONTROL_NONE);<br />
} catch (UnsupportedCommOperationException ex) {<br />
throw new IOException("Unsupported serial port parameter");<br />
}<br />
}<br />
<br />
public int ByteConversion(byte mySignedByte){<br />
<br />
ByteBuffer bb = ByteBuffer.allocate(4);<br />
<br />
bb.put(new byte[] {0, 0, 0, mySignedByte});<br />
<br />
bb.rewind();<br />
<br />
int unsignedByteVal = bb.getInt();<br />
<br />
return unsignedByteVal;<br />
<br />
}<br />
<br />
<br />
<br />
<br />
public void disconnect() {<br />
<br />
if (serialPort != null) {<br />
try {<br />
outStream.close();<br />
inStream.close();<br />
} catch (IOException ex) {<br />
}<br />
serialPort.close();<br />
serialPort = null;<br />
}<br />
}<br />
<br />
<br />
private void readSerial() {<br />
<br />
<br />
try {<br />
int availableBytes = inStream.available();<br />
if (availableBytes > 0) {<br />
inStream.read(readBuffer, 0, availableBytes);<br />
<br />
txtRx.append("Received :" +<br />
new String(readBuffer, 0, availableBytes));<br />
}<br />
} catch (IOException e) {<br />
}<br />
}<br />
<br />
<br />
public void serialEvent(SerialPortEvent event) {<br />
switch (event.getEventType()) {<br />
<br />
case SerialPortEvent.BI:<br />
<br />
case SerialPortEvent.OE:<br />
<br />
case SerialPortEvent.FE:<br />
<br />
case SerialPortEvent.PE:<br />
<br />
case SerialPortEvent.CD:<br />
<br />
case SerialPortEvent.CTS:<br />
<br />
case SerialPortEvent.DSR:<br />
<br />
case SerialPortEvent.RI:<br />
<br />
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:<br />
break;<br />
<br />
case SerialPortEvent.DATA_AVAILABLE:<br />
readSerial();<br />
<br />
break;<br />
}<br />
} <br />
<br />
<br />
}<br />
</small>
The errors I've got:
<small><br />
<br />
1500.0
<br />
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 9<br />
at org.apache.commons.io.EndianUtils.writeSwappedLong(EndianUtils.java:209)<br />
at org.apache.commons.io.EndianUtils.writeSwappedDouble(EndianUtils.java:263)<br />
at SerialComm.ButtonListener.actionPerformed(serialCommMain.java:303)<br />
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)<br />
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)<br />
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)<br />
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)<br />
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)<br />
at java.awt.Component.processMouseEvent(Unknown Source)<br />
at javax.swing.JComponent.processMouseEvent(Unknown Source)<br />
at java.awt.Component.processEvent(Unknown Source)<br />
at java.awt.Container.processEvent(Unknown Source)<br />
at java.awt.Component.dispatchEventImpl(Unknown Source)<br />
at java.awt.Container.dispatchEventImpl(Unknown Source)<br />
at java.awt.Component.dispatchEvent(Unknown Source)<br />
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)<br />
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)<br />
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)<br />
at java.awt.Container.dispatchEventImpl(Unknown Source)<br />
at java.awt.Window.dispatchEventImpl(Unknown Source)<br />
at java.awt.Component.dispatchEvent(Unknown Source)<br />
at java.awt.EventQueue.dispatchEvent(Unknown Source)<br />
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)<br />
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)<br />
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)<br />
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)<br />
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)<br />
at java.awt.EventDispatchThread.run(Unknown Source)<br />
Stable Library<br />
=========================================<br />
Native lib Version = RXTX-2.1-7<br />
Java lib Version = RXTX-2.1-7<br />
ERROR: SerialComm.Comms<br />
ERROR: null<br />
ERROR: SerialComm.Comms<br />
ERROR: null<br />
<br />
<br />
<br />
</small>
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
|
|
|
|
|
Too much code, not enough information.
What problem are you having? Do you get a compilation failure? Do you get an exception at runtime? Does it run but not do anything?
Just saying "I have a problem" is too vague. The more specific you can be, the more people will be able to help you.
|
|
|
|
|
Download[^]
Use winrar to get to the .jar and two .dll files
Copy the .jar to jre/lib/ext and the two .dll two jre/bin
Then I want you two run this code:
Code 1:
import gnu.io.*;
public class demo
{
public static void main(String[] args)
{
listPorts();
}
static void listPorts()
{
java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
while ( portEnum.hasMoreElements() )
{
CommPortIdentifier portIdentifier = portEnum.nextElement();
System.out.println(portIdentifier.getName() + " - " + getPortTypeName(portIdentifier.getPortType()) );
}
}
static String getPortTypeName ( int portType )
{
switch ( portType )
{
case CommPortIdentifier.PORT_I2C:
return "I2C";
case CommPortIdentifier.PORT_PARALLEL:
return "Parallel";
case CommPortIdentifier.PORT_RAW:
return "Raw";
case CommPortIdentifier.PORT_RS485:
return "RS485";
case CommPortIdentifier.PORT_SERIAL:
return "Serial";
default:
return "unknown type";
}
}
}
Code 2:
public static HashSet<CommPortIdentifier> getAvailableSerialPorts() {
HashSet<CommPortIdentifier> h = new HashSet<CommPortIdentifier>();
Enumeration thePorts = CommPortIdentifier.getPortIdentifiers();
while (thePorts.hasMoreElements()) {
CommPortIdentifier com = (CommPortIdentifier) thePorts.nextElement();
switch (com.getPortType()) {
case CommPortIdentifier.PORT_SERIAL:
try {
CommPort thePort = com.open("CommUtil", 50);
thePort.close();
h.add(com);
} catch (PortInUseException e) {
System.out.println("Port, " + com.getName() + ", is in use.");
} catch (Exception e) {
System.err.println("Failed to open port " + com.getName());
e.printStackTrace();
}
}
}
return h;
}
Post your results from both codes.
Good luck
|
|
|
|
|
Ok , fellas. Let me rephrase my question.
My problem is that I can detect my ports and the connection works over the two PCs. However, when I tried to send data over to the other PC, the message being sent over looks something like "@.pp...." in my output, which is incorrect. I wanted the output to be in hex, something like
"AA BC 25 EE AC...".
Any suggestions?
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
|
|
|
|
|
Ok , fellas. Let me rephrase my question.
My problem is that I can detect my ports and the connection works over the two PCs. However, when I tried to send data over to the other PC, the message being sent over looks something like "@.pp...." in my output, which is incorrect. I wanted the output to be in hex, something like
"AA BC 25 EE AC...". I'm quite new to java.
Any suggestions?
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
|
|
|
|
|
pohcb_sonic wrote: the message being sent over looks something like "@.pp...." in my output
Unless you convert it to Hex before you send it then this is how it will look. I suspect you just want to view it in Hex, which menas you need to capture it first and then use software to display it as hex characters.
|
|
|
|
|
import java.io.*;
import java.lang.*;
public class ByteToHexa{
public static void main(String[] args) throws IOException{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the byte number:");
byte b =(byte)6;
String str = buff.readLine();
int i =Integer.parseInt(str);
String hexString = Integer.toHexString(i);
System.out.println("Hexa is:=" + hexString);
}
}
Does this do it?
|
|
|
|
|
Member 4277480 wrote: Does this do it?
Well apart from the obvious error(s), I don't think so; but then I'm not the OP. If you read OP's previous, he/she wants to see the captured network text displayed in Hex rather than ascii characters.
|
|
|
|
|
If you read the code by poster he/she is transmitting a Byte Array, for each element in that array there is a byte which is an Integer so to get the Hex of it use the code I posted above and what obvious error are you talking about and ASCII charecters??
|
|
|
|
|
pohcb_sonic wrote: However, when I tried to send data over to the other PC, the message being sent over looks something like "@.pp...." in my output, which is incorrect. I wanted the output to be in hex, something like
"AA BC 25 EE AC...".
Member 4277480 posted this code:
public static void main(String[] args) throws IOException{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the byte number:");
byte b =(byte)6;
String str = buff.readLine();
int i =Integer.parseInt(str);
String hexString = Integer.toHexString(i);
System.out.println("Hexa is:=" + hexString);
}
}
I don't see what the following statement is for:
byte b =(byte)6;
The remaining code reads some input from the console, parses it to an integer and then displays it in Hex. This is not converting the characters of the message passing between the two PCs.
Or did I miss something obvious?
|
|
|
|
|
1. My bad for extra statement that does not make it an error though
2. Let me clarify:
In the previous code I am only saying that if I have a message suppose it is "hello" I want to transmit that message, the first thing I will do is convert it to a byte array and send it, then use the Integer.toHexString(i); to get the Hex of that message from every byte in that array. This in short is a simulation of what is to be done not the exact code to do it.
|
|
|
|
|
Member 4277480 wrote: then use the Integer.toHexString(i); to get the Hex of that message from every byte in that array. This in short is a simulation of what is to be done not the exact code to do it.
But, as I said earlier there is an error. Your Integer.toHexString(i); statement is displaying the hex value of the index rather than the byte within the array. Something of the form Integer.toHexString(byteArray[i]); would be more useful.
|
|
|
|
|
Ok fellas,
I have edited and updated my main Question in this thread. Pls refer to it. can kindly assist? thanks.
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
modified on Sunday, October 4, 2009 11:51 PM
|
|
|
|
|
int indx = 9;
EndianUtils.writeSwappedDouble(BytetxtMsg, 2, reverse(number));
ByteBuffer bbuf = ByteBuffer.allocate(8);
Byte buffer is 8 and is constant i.e does not change lets call it b, so we have two variables the indx and the 2 in the endian lets call it x. The relationship would be indx = b + x; as the minimum acceptable value.
|
|
|
|
|
the problem is that:
EndianUtils.writeSwappedDouble(BytetxtMsg, 2, reverse(number));
you just fix it:
EndianUtils.writeSwappedDouble(BytetxtMsg, 1, reverse(number));
Double has 8 bytes.bbuf has 9 bytes capacity and begins with index zero.But your offset is 2,so its capaticy will not be enough. it will throw out of bound exception.
|
|
|
|
|
Ok, I've already solved the EndianUtils problem. But the following error still exists.
<small><br />
<br />
ERROR: SerialComm.Comms<br />
ERROR: null<br />
ERROR: SerialComm.Comms<br />
ERROR: null<br />
<br />
</small>
Although I did use the try and catch method to catch the above errors in my code, I still couldn't figure out why the problems exist.
<small><br />
<br />
try{<br />
<br />
<br />
connect("COM2");<br />
}catch (Exception e) {<br />
System.err.println("ERROR: " + e.getMessage());
<br />
}<br />
<br />
}<br />
<br />
<br />
try{ <br />
C1.sendBytes(BytetxtMsg); <br />
} catch (Exception e) {<br />
System.err.println("ERROR: " + e.getMessage());
<br />
}<br />
<br />
</small>
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
|
|
|
|
|
hi guys,
i have learnt java beginners fundamentals and concepts,i want to learn j2ee can i learn it using books or it should be learnt only in training centers.please help me out.
|
|
|
|
|
Sun has a lot of information; here[^].
Install netbeans and start creating.
Buy a book. Even if you decide to take a training course, buy a book it will always be useful.
Start learning the big concepts first.
97.35% of EE work is the same as SE; so don't sweat it.
Enjoy!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
thanks for the information provided
|
|
|
|
|
i have a web application in struts. i want to use the tiles for that application.is there any possibility?
|
|
|
|
|