Reputation: 1
Can you help me how to get the value of input data that the data type is long
. I am making a queue program that has a GUI
. I am having error in getting the value of long
. This is my method.
public Queue(int s) // constructor
{
maxSize = s;
queArray = new long[maxSize];
front = 0;
rear = -1;
nItems = 0;
}
this is my button who will get the value.
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
a.Queue(jTextField2.valueOf(j) = long);
jTextField2.setText("");
refresh();
jLabel2.setText("");
// TODO add your handling code here:
}
or can you just give me a sample program of queue that has a GUI. THANKS. :)
Upvotes: 0
Views: 111
Reputation: 41220
I think you need to get the value from jTextField2
and convert into long and insert it into Queue.
String value = jTextField2.getText();
long lvalue = Long.parseLong(value);
a.Queue(lvalue);
or in one line a.Queue(Long.parseLong(jTextField2.getText()));
Long.parseLong
might throw RuntimeException
, whihc should be handled.
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try{
a.Queue(Long.parseLong(jTextField2.getText()));
...
}catch(RuntimeException rex){...}
}
Upvotes: 0
Reputation: 45070
If you want to get the long data from the jTextField2
which is an object of JTextField
, then you can do something like this.
long j = Long.parseLong(jTextField2.getText()); // get the string data and parse it to long
// use the long value `j` as you want
Upvotes: 2