|
|
What have you tried and where are you stuck? "in java" is not much of a description of a problem....
|
|
|
|
|
I used JPanel leftPanel = new JPanel(new GridBagLayout); to contain "JScrollPane, JRadioButton, JCheckBox" (Like this image).
When I click on "Open..." button to add more picture, the JScrollPane will use "m_arrListImageFilePaths" to auto update its items. Controls in "JLeftPane" is still right their position. But when I click on application's "Maximum" button - the controls is repainted, "Normal" button is lay down "JScrollPane" (Like this video). Please help me solve above problem.
By the way, I attached my project which is helpful in your solving.
Thanks all !!!!!
|
|
|
|
|
How to create last 10 recently opened files list using java in netbeans?
|
|
|
|
|
Try some of these links[^]. Basically, it looks like you have to write the code yourself.
Use the best guess
|
|
|
|
|
i want my program run in swing gui and yield can displayed in jtable.
Everybody,plese help me.
import java.io.*;
public class wile {
public static void main(String[]args){
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String cthdata=("Contoh Data");
String nomber=null;
try{
System.out.print("masukan jumlah:");
nomber=br.readLine();
}
catch(IOException ioe){
System.out.println("gagal");
}
int intnumber;
intnumber=Integer.parseInt(nomber);
System.out.println("No\tIsi");
int no=1;
while(no<=intnumber){
System.out.println(no+"\t"+cthdata);
no=no+1;
}
}
}
|
|
|
|
|
You should study this tutorial[^] about swing and its controls.
Use the best guess
|
|
|
|
|
I'm working with Oracle database. I use PHP for my web service and Android as the client which will send blob data to Oracle DB. I use this code
Bitmap imageUpload = BitmapFactory.decodeFile(picturePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageUpload.compress(Bitmap.CompressFormat.JPEG, 60, baos);
byte[] image_data = baos.toByteArray();
String converted_image = Base64.encodeBytes(image_data);
to decode and send it as base64 encoding, then send it to the web service with this code
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("TITLE", title));
nameValuePairs.add(new BasicNameValuePair("IMAGES", converted_image));
json = jsonParser.makeHttpRequest(url, "POST", nameValuePairs);
This is my PHP code to insert to oracle db
if(isset($_POST["TITLE"]) && isset($_POST["IMAGES"]))
{
$title = $_POST["TITLE"];
$image = $_POST["IMAGES"];
$gambar = file_get_contents($image);
$query = "INSERT INTO images (TITLE, IMAGES) VALUES (:TITLE, EMPTY_BLOB()) RETURNING IMAGES INTO :IMAGES";
$parse = oci_parse($connect, $query);
$lob_a = oci_new_descriptor($connect, OCI_D_LOB);
oci_bind_by_name($parse, ":TITLE", $title);
oci_bind_by_name($parse, ":IMAGES", $lob_a, -1, OCI_B_BLOB);
oci_execute($parse, OCI_DEFAULT);
if($lob_a->save($gambar))
{
oci_commit($connect);
$lob_a->free();
}
else
{
oci_rollback($connect);
}
}
The PHP code successfully insert the query to the oracle db, but when I see the record the blob does not show anything because the length of the blob is 0. I will appreciate any help. Thank you.
|
|
|
|
|
Raditya Kurnianto wrote: I use PHP for my web service
This is Java forum.
Raditya Kurnianto wrote: PHP code successfully insert the query to the oracle db
Based on the code you posted I see nothing that suggests that you would know that.
As a guess, given I know nothing about php, I will note that I don't see anything at all that suggests that you actually put data in the blob. You created it, you saved it, but you didn't put any data in it.
|
|
|
|
|
|
I want some details about java Scanners.
-Toywarrior
modified 21-Nov-20 21:01pm.
|
|
|
|
|
This is a programming forum; you need Google. Or, you need to explain in better detail what problem you are trying to solve.
Use the best guess
|
|
|
|
|
How to Send Mail From Application to Other Email such as Gmail,Yahoo using VB 6.0
|
|
|
|
|
Appears to be your first post,
This is a java forum... Post question about VB in the appropriate forum[^], knowledgeable folks will be able to help.
Regrads,
Amitosh
|
|
|
|
|
I'm making a program in which I want to process two methods at the same time.
I want to receive a file and then process it,,,when I'm processing my program should be able to receive another file.
I'm getting a problem,,I'm receiving a file and controlling it but when I'm getting file again its not receiving because,,My program is working in a sequence.
How can I make it to work parallel?
Thanks!
|
|
|
|
|
|
I have a class which compares a set of times (using JodaTime Lib) to find the closest one to now:
public class TimeComparitor {
private List<LocalTime> targetTimes;
public TimeComparitor() {
targetTimes = new ArrayList<LocalTime>();
}
public void addTargetTime(LocalTime target) {
targetTimes.add(target);
}
public LocalTime getClosestFutureTarget(DateTime now) {
LocalTime result = null;
long resultOffset = Long.MAX_VALUE;
ArrayList<String> bigger = new ArrayList<String>();
for (LocalTime target : targetTimes) {
DateTime todayTarget = target.toDateTimeToday();
long differenceMillis = todayTarget.getMillis() - now.getMillis();
if (differenceMillis > 0 && differenceMillis < resultOffset) {
resultOffset = differenceMillis;
result = target;
}
}
return result;
}
As you see I could catch the closest time by getClosestFutureTarget method, But I not only want the closest one, but also an ordered list of all Times greater than now.
The question is: First, how to save them in a list? Should it be through getClosestFutureTarget ?
Second, to sort the list from closest to farthest I'm told to use something like this:
public class LocalTime implements Comparable<LocalTime> {
...
public int compareTo(LocalTime o){
}
} and then using Collections.sort . But not sure how to adapt it to my code.Just define this class in the same file for Previous class? Or creat a new class file? What should be inside class and where to call Collections.sort .
Thanks in advance
|
|
|
|
|
Hello Gandhali,
The suggestion you got for sorting is partially right. The LocalTime class in JodaTime library implements the necessary compareTo method and hence no need to have a separate Comparable class. To sort your List of LocalTime objects all you have to do is to call the sort method of Collections class with a list of LocalTime objects.
In order to find all time values greater than now you can use code similar to one shown below.
int cntr = 0;
LocalTime curTime = new LocalTime();
Collections.sort(targetTimes);
for (LocalTime target : targetTimes) {
if (target.compareTo(curTime) >= 0) break;
cntr++;
}
List<LocalTime> ret = targetTimes.subList(cntr, targetTimes.size() - 1);
Regards,
Prasad P. Khandekar
Knowledge exists, man only discovers it.
|
|
|
|
|
I am writing test code that prints an encrypted string to an underlying ByteArrayOutputStream, then code to decrypt the bytes from that stream into another string. Here is my code:
byte[] keyBytes, ivBytes;
final SecretKey key = new SecretKeySpec(keyBytes, "AES");
final IvParameterSpec iv = new IvParameterSpec(ivBytes);
final Cipher encrypt = Cipher.getInstance("AES/CBC/PKCS5Padding");
final Cipher decrypt = Cipher.getInstance("AES/CBC/PKCS5Padding");
encrypt.init(Cipher.ENCRYPT_MODE, key, iv);
decrypt.init(Cipher.DECRYPT_MODE, key, iv);
final ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
final CipherOutputStream out = new CipherOutputStream(outBytes, encrypt);
out.write("This is a test, of course.".getBytes());
out.close();
final byte[] encryptedBytes = outBytes.toByteArray();
final ByteArrayInputStream inBytes = new ByteArrayInputStream(encryptedBytes);
final CipherInputStream in = new CipherInputStream(inBytes, decrypt);
final byte[] result = new byte[100];
final int byteCount = in.read(result);
System.out.print('"');
System.out.print(new String(result, 0, byteCount));
System.out.println('"');
For the above code, I expected the output to be "This is a test, of course.". However, I am getting the string, "This is a test, " (the final block is not being read). If I continue calling in.read(), I am able to get the remaining bytes out of the input stream, one byte at a time. This indicates (I think) that CipherInputStream is not simply catching and ignoring an invalid padding exception, which is what a few other posts I have found mentioned might be happening.
When I run the above code, the following two properties hold:
1. encryptedBytes.length == 32,
2. new String(decrypt.doFinal(encryptedBytes)) creates a string with the expected value
My question is, how in the heck to I get the CipherInputStream to read these bytes, without reading them one at a time? Is this expected behavior?
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
If your application is something like the one shown in the example, like encrypting and decrypting static (previously known, as opposed to a stream) bytes, then use Cipher class instead, it's easier
|
|
|
|
|
Skippums wrote: 1. encryptedBytes.length == 32,
In PKCS5 padding used here, the block length is fixed( may be 16), since the bytes available are insufficient, the call is blocked until the full 32 bytes arrive the stream or end of stream is detected, that is -1 is returned from the parent stream (ByteArrayInputStream in this case).
A cryptanalyst will be able to explain you better about the working of the padding schemes and ciphers.
|
|
|
|
|
Sorry, I should have clarified in my post; I know that the length of the encrypted byte array was correct at 32 bytes long. When I searched for an answer to my question, the first thing people trying to help ask is, "what is the length of your encrypted stream?" Most people were getting something that was NOT a multiple of the block size, which indicates the error is earlier than the read phase. I posted that information to try and "prove" that the error was during the read phase, and NOT during the write phase (especially since I can get the information out of the stream if I use it in a unique way).
As for your other answer, the code I posted was a minimal example of how to illustrate the problem, but in no way reflects how I am actually attempting to use the CipherInputStream/CipherOutputStream classes. Essentially, I am attempting to the interface to the crypto API significantly easier by creating a factory that returns a CipherInputStream/CipherOutputStream when the client passes in enumerated values for the cipher mode and padding mode.
And yes, you are correct that for AES the block size is 16 bytes. For now, I just created a class called CipherInputStreamWrapper, and overloaded the read(byte[], int, int) method to iteratively call CipherInputStream.read(). This approach works, but I think it illustrates a flaw in the underlying implementation of CipherInputStream in Java 6 and 7 (tested in both). Thank you for taking the time to answer my post, any other ideas as to how to solve this problem are welcome!
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
For anyone else looking for an answer to this, I couldn't find one. However, I am able to perform the following workaround: Instead of returning a CipherInputStream, I return a CipherInputStreamWrapper, which I define to be the following internal class:
class CipherInputStreamWrapper extends CipherInputStream {
CipherInputStreamWrapper(final InputStream is, final Cipher cipher) {
super(is, cipher);
}
@Override
public int read(final byte[] b) {
return this.read(b, 0, b.length);
}
@Override
public int read(final byte[] b, final int off, final int len) {
for (int i = 0; i < len; ++i) {
final int nextByte = this.read();
if (nextByte < 0) return i;
b[off + i] = (byte)nextByte;
}
return len;
}
} The implementation of read(byte[]) is actually identical to that in CipherInputStream in Java 6 and 7, but if the implentation changes in the future, NOT overloading that method would result in yet another erroneous implementation. I am always open to other ideas if anyone else has a cleaner solution!
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
See javadoc for CipherInputStream[^]
This method blocks until input data is available or end of stream is reached or an exception is thrown.
Keep this in mind. The last block is not decrypted and returned, until end of stream is reached. Circumventing this approach MAY LEAD TO DATA CORRUPTION!
|
|
|
|
|
Sorry, I must be thick-headed, but I still don't understand. In my case, it seems (to me) that either:
1. Input data is available, or
2. The end of stream is reached
I am still not getting how neither of these is true, regardless of whether it is the final block or not. Can you elaborate on what exactly is happening that is making both of those conditions false? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|