Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

Daniel Layher

Greenhorn
+ Follow
since Jul 14, 2006
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 Daniel Layher

I want to make a forum for a website using JSPs. Is there any good resources anybody can refer me to? thanks ahead of time.
Worked like a charm. Thank you. I was just using .getParameter(). that made all the difference. Thanks again.
15 years ago
JSP
I know this sounds super easy but i can't figure it out. I have a select box that is populated on the fly through a database. The select box is also has multiple set to true so you can choose more than one option. However, every time i try to pass it to the servlet it, only the first selection is passed. I'm pretty sure that it is set up as an array, but I'm not sure how to pass the array, which doesn't have a set size, to the servlet. Any suggestions??? Thanks ahead of time.
15 years ago
JSP
is there anyway someone could explain to me how to send a file (in this case a .txt file) to the printer so if i were to click a button that says "print" it would print up a file that is already on the computer...
15 years ago
in case the question was unclear, when i run the program, the main window pops up, but when i make a selection the next window i created won't appear... how do i make the second window appear???
15 years ago
i'm using netbeans 5.0 to make a GUI application. For some reason, and i'm sure the solution is simple, i can't figure out how to call a second GUI class from the first one. Example, a screen pops up with multiple selections. If i click on one, I want a different GUI window that i made to pop up and later pull variables from that window. I know how to pull the variable but can't seem to make the window appear to begin with. Any suggestions?
15 years ago
Hi. I'm trying to create a program for work that has a timer. I've tried it as many ways as i could think of, and the timer itself works great, but i wanted the timer to change a label on a GUI form. However, it won't change the text property of a label in the middle of a function. Is there any way around this. Here is how my code is currently laid out:

When the button is clicked:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String label = new String("jLabel2.text");
jLabel1.setText("Taken");
SeatTimer timer1 = new SeatTimer();
jLabel2.setText("60:00");
while(jLabel2.getText().compareTo("00:00")!=0)
{
jLabel2.setText(timer1.decTime());
}
jLabel1.setText("Open");
}

The logic:
import javax.swing.Timer;
import java.awt.event.*;
import javax.swing.*;
import Logic.*;

public class SeatTimer
{
private final int DELAY = 1;
private int minF = 0;
private int minS = 0;
private int secF = 0;
private int secS = 0;
private String result = new String();


public SeatTimer() {
minF=6;
minS=0;
secF=0;
secS=0;
}

public String decTime()
{
int delay = 100;//milliseconds
result = minF+minS+":"+secF+secS;
result = dec();
StopWatch s = new StopWatch();
s.start();
while(s.getElapsedTimeSecs()<1){}
s.stop();
System.out.println(result);
return result;
}
public String dec()
{
if(secS>0)
{
secS--;
}
else
{
if(secF>0)
{
secF--;
secS=9;
}
else
{
if(minS>0)
{
minS--;
secF=5;
secS=9;
}
else
{
if(minF>0)
{
minF--;
minS=9;
secF=5;
secS=9;
}
else
{
return "Expired";
}
}
}
}
String result = minF+""+minS+":"+secF+""+secS;
return result;
}
}


StopWatch Class:
public class StopWatch
{
private long startTime = 0;
private long stopTime = 0;
private boolean running = false;

public void start() {
this.startTime = System.currentTimeMillis();
this.running = true;
}

public void stop() {
this.stopTime = System.currentTimeMillis();
this.running = false;
}

public long getElapsedTime() {
long elapsed;
if (running) {
elapsed = (System.currentTimeMillis() - startTime);
}
else {
elapsed = (stopTime - startTime);
}
return elapsed;
}

public long getElapsedTimeSecs() {
long elapsed;
if (running) {
elapsed = ((System.currentTimeMillis() - startTime) / 1000);
}
else {
elapsed = ((stopTime - startTime) / 1000);
}
return elapsed;
}
}



There it is. Any help you guys can offer would be great. Thanks in advance.
15 years ago
thanks for your help though...
15 years ago
i just decided to make a function that basically did it... i think it was maybe 6 lines of code...
15 years ago
is there an equivalent in Java to C++'s printw???
15 years ago
in case anybody has the same problem i did, i found code that made shortcuts for me... i seem to only have problems setting the icons, but i can live with it... either way, this is it...

import java.io.*;
import java.util.ArrayList;

public class shortcut extends iconSelect {

private byte answer[];
private int offset;
private byte buf[];
private ByteArrayOutputStream bytestream;
/** Creates a new instance of pscc */
public shortcut() {
}

public void WindowsShortcut(String fulllinkpath, String fulltargetpath, String arguments, String workingdirectory, String iconfile)
throws IOException
{
answer = new byte[1024];
offset = 1024;
buf = new byte[8];
bytestream = new ByteArrayOutputStream(125);
buildLink(fulltargetpath, arguments, workingdirectory, fulllinkpath, setIcon(fulltargetpath));
File linkfile = new File(fulllinkpath);
mkpath(linkfile);
writeFile(linkfile);
}

private final void buildLink(String fulltargetpath, String arguments, String workingdirectory, String fulllinkpath, String iconfile)
throws IOException
{
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
if(iconfile != null)
{
int iconfilelen = write(iconfile);
writeBackward(iconfilelen, 2);
}
if(arguments != null)
{
int argumentslength = write(arguments);
writeBackward(argumentslength, 2);
}
if(workingdirectory != null)
{
int tplength = write(workingdirectory);
writeBackward(tplength, 2);
}
File destf = new File(fulltargetpath);
File linkf = new File(fulllinkpath);
String rp = getRelativePath(linkf.getParent(), destf.getParent());
if(rp != null)
{
if(rp.length() > 0)
{
rp = rp + File.separator + destf.getName();
}
else
{
rp = destf.getName();
}
int rplen = write(rp);
writeBackward(rplen, 2);
}
int postfileoff = offset;
buf[0] = 0;
write(buf, 0, 1);
int finalpathoff = offset;
buf[0] = 0;
write(buf, 0, 1);
write(fulltargetpath);
int localpathoff = offset;
buf[0] = 0;
write(buf, 0, 1);
buf[0] = 16;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 3;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
int voltablen = (localpathoff - offset) + 4;
writeBackward(voltablen, 4);
int fileinfooff = offset - 28;
int tmp = finalpathoff - fileinfooff;
writeBackward(tmp, 4);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
tmp = localpathoff - fileinfooff;
writeBackward(tmp, 4);
buf[0] = 28;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 1;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 28;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
tmp = postfileoff - fileinfooff;
writeBackward(tmp, 4);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
write(buf, 0, 8);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 1;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
int filelen = (int)destf.length();
writeBackward(filelen, 4);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
write(buf, 0, 8);
write(buf, 0, 8);
write(buf, 0, 8);
buf[0] = 32;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
int flags = 2;
if(rp != null)
{
flags += 8;
}
if(workingdirectory != null)
{
flags += 16;
}
if(arguments != null)
{
flags += 32;
}
if(iconfile != null)
{
flags += 64;
}
writeBackward(flags, 4);
buf[0] = -64;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 70;
write(buf, 0, 8);
buf[0] = 1;
buf[1] = 20;
buf[2] = 2;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
write(buf, 0, 8);
buf[0] = 76;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
bytestream.close();
}

private final int write(byte source[], int srcoffset, int length)
{
int newoffset = offset - length;
if(newoffset < 0)
{
length += newoffset;
srcoffset -= newoffset;
newoffset = 0;
}
int atbuff = newoffset;
int atsrc = srcoffset;
for(int i = 0; i < length; i++)
{
answer[atbuff] = source[atsrc];
atbuff++;
atsrc++;
}

offset = newoffset;
return length;
}

private final int write(String text)
throws IOException
{
OutputStreamWriter writeout = new OutputStreamWriter(bytestream);
writeout.write(text, 0, text.length());
writeout.close();
byte bytes[] = bytestream.toByteArray();
bytestream.reset();
return write(bytes, 0, bytes.length);
}

private final int write(byte abyte)
{
int rc = 0;
if(offset > 0)
{
offset--;
answer[offset] = abyte;
rc = 1;
}
return rc;
}

private final int writeForward(int value, int length)
{
int i = 0;
int rc = 0;
for(; i < length && i < 4; i++)
{
byte abyte = (byte)value;
rc += write(abyte);
value >>>= 8;
}

return rc;
}

private final int writeBackward(int value, int count)
{
int rc = 0;
byte tmp[] = new byte[count];
int i;
for(i = 0; i < count && i < 4; i++)
{
tmp[i] = (byte)value;
value >>>= 8;
}

return write(tmp, 0, i);
}

private final String getRelativePath(String from, String to)
{
int flen = from.length();
int tlen = to.length();
char sep = File.separatorChar;
int prevsep = -1;
int sepcount = 0;
StringBuffer fromb = new StringBuffer(from);
StringBuffer tob = new StringBuffer(to);
int i = flen - 1;
if(fromb.charAt(i) != sep)
{
fromb.append(sep);
flen++;
}
i = tlen - 1;
if(tob.charAt(i) != sep)
{
tob.append(sep);
tlen++;
}
i = 0;
for(boolean ok = true; ok && i < flen && i < tlen; i++)
{
char achar = Character.toLowerCase(fromb.charAt(i));
if(achar == Character.toLowerCase(tob.charAt(i)))
{
if(achar == sep)
{
prevsep = i;
sepcount++;
}
}
else
{
ok = false;
}
}

if(sepcount == 0)
{
return null;
}
if(i == flen && i == tlen)
{
return "";
}
prevsep++;
fromb.delete(0, prevsep);
tob.delete(0, prevsep);
int state = 0;
for(i = 0; i < fromb.length()
{
char achar = fromb.charAt(i);
if(achar == sep)
{
state = 0;
i++;
}
else
if(state < 2)
{
fromb.setCharAt(i, '.');
state++;
i++;
}
else
{
fromb.deleteCharAt(i);
}
}

i = fromb.length() - 1;
if(i > 0 && fromb.charAt(i) != sep)
{
fromb.append(sep);
}
fromb.append(tob.toString());
flen = fromb.length();
i = flen - 1;
if(fromb.charAt(i) == sep)
{
fromb.delete(i, flen);
}
return fromb.toString();
}

private final void mkpath(File file)
throws IOException
{
ArrayList need = new ArrayList();
File check = file.getParentFile();
int max = 0;
for(; !check.exists(); check = check.getParentFile())
{
max++;
need.add(check);
}

for(int i = 0; i < max; i++)
{
check = (File)need.get(i);
check.mkdir();
need.set(i, null);
}

check = null;
need = null;
}

private final void writeFile(File dest)
throws IOException
{
int len = answer.length - offset;
FileOutputStream ds = new FileOutputStream(dest);
ds.write(answer, offset, len);
ds.close();
}


//public static void main(String args[])
//{
//(String fulllinkpath,String fulltargetpath,String arguments,String workingdirectory,String iconfile)

//try{
//WindowsShortcut a=new WindowsShortcut("c:/a.lnk","c:/sandro/winhelp.exe","","c:/","c:/icon.ico");
//}
//catch(Exception e){}
//}
}
15 years ago

Originally posted by Henry Wong:


You can call any OS program from java via the Runtime.exec() series of methods -- just build the command along with any parameters and call it. You can also send the input and read the output from that program.

Henry



I mostly understand how to ust the Runtime.exec(), but i'm still not sure how to use it to access shortcut.exe... is there anywhere where there is an example or explanation of how to accomplish this?
15 years ago
JNI
I've got a small C++ that creates a shortcut because to my understanding, java can't make one. Therefore i need to access the program, or class, or whatever to get it to work. To my understanding JNI can do this but i'm not sure how it all works and all that. Can anyone help or point me to somewhere that explains how i can use JNI because most of the online stuff isn't very helpful. Thanks
15 years ago
unfortunately, i'm using java and i'm not sure how to use that in the program. Any suggestions???
15 years ago
Hi. I'm making a program that will search a network drive for copies of the same file. Once it does that it is supposed to make a copy of those files, delete them, and turn them into shortcuts. Unfortunately, i can't seem to figure out how to create an .lnk file. If anybody has a solution, please, let me know.
15 years ago