| sending raw data to a printer driver |
|
 |
Index ‹ java-programmer
|
- Previous
- 1
- Finding path of running classFile currentDir = new File(System.getProperty("user.dir"));
I need to know the path to a class that is running and have had
partial success. The code shown above finds the folder where the JVM
is running.
If I start my app from a terminal window or a native executable IDE,
the JVM will run in the folder where my class is located and
currentDir points to the folder that I need. But if I start the app
from an IDE written in Java, I get the folder where the IDE is located
rather than the folder where the app that I was running is located.
My app will be used in a classroom setting by people who will NOT have
command prompt permissions. They will have to run it from an IDE.
I'd really like to stick with the one that we're currently using
(written in Java).
Apparently, both the IDE and my application are running in the same
JVM. Is there any way to get the application to run in its own JVM so
user.dir points to that folder?
If not, any other suggestions?
TIA
tom
- 1
- Learning ArraysHi, I am just learning arrays and I am trying to get this 2D array to print
out like this:
0 1 2 3 4 5 6
0 1 2 3 4 5 6
0 1 2 3 4 5 6
0 1 2 3 4 5 6
0 1 2 3 4 5 6
but insteads it prints out like this: 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4
5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6
I can get it to work with system.out.println but I need to use a
JOptionPane.showMessageDialog box as I have attempted to do. Any ideas?
(my code is below) Thanks!!!!!!!!!!
import javax.swing.*;
public class array5by7{
public static void main (String args[]){
String outputString = "";
int table[][] = new int [5][7];
for (int row=0; row<table.length; row++)
{
for (int col = 0; col <table[row].length; col++)
table[row][col] = 0 + col;
}
for (int row=0; row<table.length; row++)
{
for (int col = 0; col<table[row].length; col++)
outputString += (table[row][col] + " ");
}
JOptionPane.showMessageDialog (null, outputString + "\n");
}
}
- 2
- iulivarzariuda.. invites you to Going.comHey! Check out this cool new site Going.com. They'll keep you posted
on What's Happening and Who's Going around town.
- Be in the know about fun events, concerts, parties and see who's
going.
- Keep up with your friends and share what you are up to.
- Get invited to exclusive Going.com sponsored special events.
I figured you would want in on it too. Check it out at:
http://going.com/join_me/SsPiUUVYFC
iulivarzariuda..
This email was sent by the person in the from line and the subject
line. Please email them directly if you have any questions.
Going is compliant with the Can-Spam Act of 2003. For more
information, read our privacy policy at
http://going.com/privacy_policy.php.
Going, Inc - 8 Winter Street, Boston, MA 02108, USA
email***@***.com
- 2
- cannot start application server 8 ?installed the Sun Java System Application Server 8 recently. I run the
"asadmin start-domain --verbose domain1" command to try to start it,
however, it didn't happen. i'm using windows 2k server SP$.
thank's!
--
AbdelHalim MIMOUNI
- 2
- Java Applet Parameter LimitHi all,
I would like to know the maximum number of parameters that can be passed
to an applet. While I think there is no theoretical maximum, I believe
there to be a practical limitation for browsers.
I am using winXP, IE6 and firefox1, and jre1.4.2.
I have a graphing applet which works very well except when there are a
large number of parameters i.e. 5000. When I load such an example with
appletviewer the applet opens fine. However when I load the same applet
in either IE6 or firefox1 then nothing happens except the page appears
to be loading but gets no where even if you leave it for hours - in
other words the browsers seem to hang. Java does not appear to load into
memory - the icon does not appear in the system tray which leads me to
believe that it is a browser limitation, rather than a java one.
Does anyone know if there is such a limitation? Do you think it could be
remedied by merging the tags - i.e. having less but longer params? Or is
there another way of passing data to the applet?
Many thanks,
Chris.
- 2
- junit test in eclipse
code from some tutorial
---------
import junit.framework.TestCase;
public class SampleTest extends TestCase {
...
}
---------
code from another tutorial
---------
import org.junit.*;
import static org.junit.Assert.*;
public class SampleTest {
...
}
---------
Second one is working well. I think second one is simpler, so I like it.
But I can't use them with TestSuite.
"
The method addTest(Test) in the type TestSuite is not applicable for the
arguments
(Class<ArmorTypeWrapperTest>)
"
---------
import junit.framework.Test;
import junit.framework.TestSuite;
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for vanguard.wardrobe");
//$JUnit-BEGIN$
suite.addTest(ArmorTypeTest.class);
suite.addTest(ArmorTypeWrapperTest.class);
//$JUnit-END$
return suite;
}
}
---------
Thank you
Sean
- 2
- 7
- Refusing TCP connections - ServerSocketI want to create a ServerSocket.
I want it to accept one connection.
If another connection request comes in, I want it to be refused, not queued.
Even if I set backlog to 1, on the OS I'm testing on (Linux) I'm able to
queue up a bunch more connections (5 or 6).
I know the actual backlog size is OS dependent even if I explicitly set it
in the ServerSocket constructor.
So, how do I refuse all subsequent connections after I accept that first one?
--
Steve Sobol, Victorville, CA PGP:0xE3AE35ED www.SteveSobol.com
Geek-for-hire. Details: http://www.linkedin.com/in/stevesobol
- 8
- JBoss e eccezioni...Ciao a tutti, ho un problema con JBoss! Ogni volta che entra in errore
la mia applicazione, JBoss s'impalla e rimango in pending 10 minuti
prima che mi lanci fuori un eccezione. Avete idea se ci sono variabili
da settare perch?non rimanga cos?tanto in attesa? Grazie.
- 10
- Application for Nokia 3410 cell 'phone
This should be simple enough! I have a Nokia 3410. I have downloaded the
J2ME Wireless Toolkit. I would like to write some applications for the cell
'phone.
Now, I read that J2ME is a range of standards and applications, not a
platform. Fair enough.
Since this is in Java, I'd like to write my applications so that they run on
all cell 'phones - or all Nokia 'phones at least.
What I'd like to know is the following:
- What steps do I need to take to write and load a 'Hello World'application
into my 3410 and see it run?
If there is a document you can point me to, or a better newsgroup that would
be great!
Later on it would be nice to know how to advertise an cell 'phone
application so other people can download it and pay for it - but that can
wait until I have one fully written. For that I need to know the above!
--
"The pure and simple truth is rarely pure and never simple." - Oscar Wilde
- 10
- How to determine the PID of your Java programHi
I was unable to find a decent How-To for finding the PID of a Java
program running on Windows, that did not use JNI. Here is a solution
that uses netstat.
Hope this is useful. If you have a better strategy, let me know!
Thanks
Andrew
package pid;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.SocketTimeoutException;
/**
* Program to obtain the Process Identifier (PID) of the running Java
program
* Assumes the Windows program
* @author Andrew Ward
*/
public class GetPID {
public static void main(String[] args) {
getPid();
}
/**
* Obtain the PID, by listening on a port, then using netstat -ano
* to find the PID of the processing listening on the port
* @return the pid of this process
*/
public static int getPid() {
// Select a port between 50000 and 51000
final int port = 50000 + (int) (Math.round(Math.random() * 1000));
// Windows specific command line
// Netstat -ano will return many lines, one of which will match
// TCP 0.0.0.0:<port> 0.0.0.0:0 LISTENING
<pid>
final String cmd = "netstat -ano";
final String criteria = "0.0.0.0:" + port;
// Listen on the port for 5 seconds
new SocketListener(port, 5 * 1000).start();
int pid = -1;
try {
// Run netstat
Process process = Runtime.getRuntime().exec(cmd);
InputStream istr = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(istr));
String str;
while ((str = br.readLine()) != null) {
if (str.indexOf(criteria) > 0) {
String match = str.substring(1+str.lastIndexOf(" "));
pid = Integer.valueOf(match);
System.out.println("PID: " + pid + " {" + str + "}");
}
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
return pid;
}
/** listen on a socket */
public static class SocketListener extends Thread {
int port;
int wait;
public SocketListener(int port, int wait) {
this.port = port;
this.wait = wait;
}
public void run() {
try {
ServerSocket server = new ServerSocket(this.port);
server.setSoTimeout(this.wait);
server.accept();
server.close();
}
catch(SocketTimeoutException e)
{
// We are expecting the accept() call to timeout
// so ignore this exception
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
}
}
- 10
- cannot call a paint function across classes?Just wondering if this is possible, as im having no luck working it out, no
matter what ive tried so far..
I have 2 classes, lets call them gP and kP. in gP ive got this function:
public void paint55(java.awt.Graphics graphics) {
Dimension d=getSize();
graphics.setColor(Color.RED);
graphics.fillRect(0, 0, (int)d.getWidth(), (int)d.getHeight());
graphics.setColor(Color.BLACK);
//call another function here
}
now, in the kP class, im using a jComboBox, the combo box works fine, but i
want to try and call that function from it
Ive tried
gP.paint55();
ive tried referencing it as gP paint55();
Just cant work it out, any ideas?
Thanks
- 12
- java.lang.NoClassDefFoundError when calling method from EJBI have a java app that runs on Websphere 6.0 and I needed a way to run
a scheduled task once a day that sends out emails. I used the
following link from IBM's site to develop a stateless EJB session bean
that ran the WAS task scheduler.
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.zseries.doc/info/zseries/scheduler/tasks/tsch_schedulebtask.html
I placed a call in the implemented process method (just like the
example says) to a non-EJB method and I get a
java.lang.NoClassDefFoundError error on the method I am tryign to call.
I'm new to EJB so I'm not sure if you can even make a call from an EJB
to a normal (non-EJB) method. Any help would be appreciated.
- 14
- 15
- How to add a button next to title at the JTabbedPaneHi,
I want to add a small button next to the title of each tabbed pane and
receive user's mouse click event at the small button.
And finally, the selected pane will be removed.
How to add other object, button, into Title part of JTabbedPane ?
Any ideas?
|
| Author |
Message |
Z.K

|
Posted: 2007-7-20 13:26:00 |
Top |
java-programmer, sending raw data to a printer driver
In Windows I have some win32 code that I use in VC++ programs to send
raw data to the printer driver. I would like to do the same thing in
Java; does anyone know how to do this. Specifically, I need to send
printer codes or language commands to a printer. Specifically in the
case I am trying to write is to be a able to send command codes to an
Intermec barcode printer through a text file which has IPL (Intermec
Printer Language) code in it. It is just text, but it instructs the
printer what to do. Of course the printer code is not restricted to
just printer codes. If I could figure out how to send raw data to the
printer driver, this would help a lot.
Z.K.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2007-7-20 13:56:00 |
Top |
java-programmer >> sending raw data to a printer driver
On Fri, 20 Jul 2007 05:25:51 GMT, "Z.K" <email***@***.com> wrote,
quoted or indirectly quoted someone who said :
>In Windows I have some win32 code that I use in VC++ programs to send
>raw data to the printer driver. I would like to do the same thing in
>Java; does anyone know how to do this.
see http://mindprod.com/jgloss/printing.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- java dont have #includes, it sucks !!!http://java.sun.com/docs/books/tutorial/java/concepts/class.html
how can i link diferent modules in one single .class in that lousy
object-wacko language ??? java sucks !!!!!
hahahahahahahahahahahahahahahahaha
either have pointers or #defines !!!! its a C abortion !!!! who
cares ???
C RUUUUUUUULEEEEEZZZZZZZZZ DAMMIT !!!!
- 2
- doubts regarding j2meI am new in j2me...I have some doubts...
1. How to insert an image into a servlet?
2. How to access it from a mobile using j2me?
3. How to send an image file from a mobile to a servlet?
Please help me...
- 3
- IllegalStateException...Writer being already used by this servletHi All,
I am faceing a problem (ofcourse thats what makes all of us come
here)..what I am trying to do is , create a image offscreen in a
servlet , then using PixelGrabber serialize the int[] and then the
applet reads it, ..so far fairly straight, now here...
...
...
ObjectOutputStream out = new
ObjectOutputStream(res.getOutputStream());
System.out.println("Inside isReq after out obj");
out.writeInt(w);
out.writeInt(h);
out.writeObject(pixels);
}
/**
try{
res.setContentType("text/html");
printer=res.getWriter();
printer.println("Object Writing done");
printer.close();
}catch(Exception ex){}
}
else{
printer.println("Object Writing <b>Not</b> done");
printer.close();
}**/
After Object writing is being done , I wish to display a html page
(with applet embedded) but using the above code it is giving me a
error "IllegalStateException: Writer being already used by the
servlet..."
Can anyone help me out...
Regards
Ray
- 4
- Positioning scrollable dataI have pasted a bare bones program below which demonstrates the
problem I am trying to solve.
I have a JTextArea on a JScrollPane, and the number of lines to be
displayed exceeds the display area. Thus scrolling is activated, and
the starting screen shows from line 1 onwards with the scrollbars
available for scrolling. So far so good.
Now I want to redisplay another screen. Once again the number of lines
exceeds the display area, This time around though, the END of the
lines are displayed. Instead of (for instance) lines 1 to 10 of 100
lines being displayed, lines 90 to 100 are being displayed.
I don't want this. Each time I want to data on the JTextArea to be
displayed from line 1 onwards.
Some research that I did indicated that getViewport().setViewPosition
would be my friend. However, as you can see in the code below, I DID
code this, but it would not work.
Does anybody have an idea how to change the code below so that I can
get the display that I want?
Thanks!
/*
* Example code to demonstrate the problem:
* The first time the data in the JTextArea is displayed,
* the data is positioned at the first line.
* Subsequently (after clicking the Next button), the data
* is positioned such that the last line is displayed.
* I want to reposition the data in the JTextArea such
* that each time after a refresh, the first line of the data
* should be displayed.
***********************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Example extends JFrame implements ActionListener
{
JTextArea textArea;
JScrollPane js;
JButton nextButton = new JButton( "Next" );
JButton endButton = new JButton( "End" );
int counter = -1;
Example()
{
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
textArea = new JTextArea( 15, 50);
textArea.append( " " );
js = new JScrollPane( textArea );
nextButton.addActionListener( this );
endButton.addActionListener( this );
JPanel pane = new JPanel();
pane.setLayout( new FlowLayout() );
pane.add( nextButton );
pane.add( endButton);
pane.add( js );
setContentPane( pane );
setLines();
setTitle("Example");
setSize(600,400);
setVisible(true);
} //end constructor
public void actionPerformed( ActionEvent evt )
{
Object source = evt.getSource();
if( source == nextButton )
{
setLines();
}
else if( source == endButton )
{
System.exit(0);
}
repaint();
}
void setLines()
{
textArea.setText( "" );
counter++;
for( int n=0; n<100; n++ )
{
textArea.append( counter + " " + n + "This line is filler
data to demonstrate problem\n" );
}
// Attempt to position to top of data... but it does not work :(
js.getViewport().setViewPosition( new Point( 0,0 ) );
}
public static void main( String[] args )
{
new Example();
}
}
- 5
- How to get you Extenal/Real IP (Router)Hi All,
I am writing a code as a Java Application (not Applet or Servlet) and I
am trying to find out what is my real IP address (not 192.168. one). I
am behind my LinkSys router and everything I try I still get 192.168.
I have tried:
- InetAddress: Always returns 192.168 address (unless I am missing
something).
- Open Socket to www.cnn.com,80 and read local address (still 192.168).
- I am reading about Upnp but not sure if that's the way I can ask my
Router about my real IP.
- Calling http://www.whatismyip.com and parse the result seems too
strange.
Any idea?
Thanks in advance,
Homer
- 6
- Which WebSphere productsHi,
I want to develop some portal application with WebSphere. There are
quite a few modules/plugins for WebSphere. I don't know which ones are
useful. I downloaded the following WebSphere related products:
- WebSphere Application Community Edition Version 2 (for Solaris 10)
- Eclipse SDK (3.3.1.1) for Windows
- RAD_V7.0_Part(1-10)
I don't know how useful is RAD_V7.0.
I also found IBM website also have a product called "WebSphere Portal
V6.0". I am confused which products I need to download? The
requirement of my development is shown as below:
Mandatory:
- Develop Portal and Portlets.
- Interact with MySQL database engine (3.0)
Optionally:
- UML (able to reverse engineering).
Can anyone please tell me what modules I need to download? and where
can I download it?
I may be need to give a call to IBM to get a trail version of CDs that
include these application. But I want to know how I need in this
development.
Thank you very much in advance.
- 7
- OutOfMemoryError - Any Way to Exit JVM?Hi all,
We're having a major problem keeping Java calculators (that were
written by a third party vendor) alive. They leak memory and
eventually cause OutOfMemoryErrors. We cannot address the problem
directly until the vendor does, so we need to manage these dying
calculators.
Unfortunately, they are all started in separate processes and an
OutOfMemory error seems to kill *only* the thread, NOT the JVM. Is
there a way to ensure that the JVM dies as well?
My real hope is that some JVM has a command line option to kill the
whole thing when it has an allocation error. Otherwise, perhaps we can
add another thread to the process that watches it, but that's harder.
Any help would be greatly appreciated.
Thanks,
Steve Lieberman
- 8
- close() of active socket does not work on FreeBSD 6On Wednesday 13 December 2006 04:49, Daniel Eischen wrote:
> On Tue, 12 Dec 2006, Poul-Henning Kamp wrote:
> > In message <email***@***.com>, Bruce Evans writes:
> >> On Mon, 11 Dec 2006, Daniel Eischen wrote:
> >>
> >> It's probably a nightmare in the kernel too. close() starts looking
> >> like revoke(), and revoke() has large problems and bugs in this area.
> >
> > There is the distinctive difference that revoke() operates on a name
> > and close() on a filedescriptor, but otherwise I agree.
>
> Well, if threads waiting on IO are interruptable by signals,
> can't we make a new signal that's only used by the kernel
> and send it to all threads waiting on IO for that descriptor?
> When it gets out to actually setup the signal handler, it
> just resumes like it is returning from an SA_RESTART signal
> handler (which according to another posting would reissue
> the IO command and get EBADF).
Stop using signal, it is slow for threaded process, first you don't
know which threads are using the descriptor, second, you have
to run long code path in kernel signal code to find and deliver
the signals to all interested threads, that is too expensive for
benchmark like apache benchmark.
David Xu
_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
- 9
- toString() or Renderer(s) for BizObjects shown in GUI ComponentsHi There,
What do people prefer for populating GUI Components (Swing) with
Business Objects ?
overriding the toString() method of those Business Objects ? or
creating renderers for each type of component ? (or something else ?)
overriding the toString() method seems easiest, and seems to work --
even seems like thats how the Swing designers intended it (since
components like JComboBox, JList, etc take Objects to populate the
model),
but of course - it may be that in one instance you want your Person
BusinessObject to show up as LastName, FirstName, and in another
component you want to see FirstName, LastName - so a single toString()
method won't cut it.
using renderers instead of toString seems to work too -- but means
potentially writing renderers for almost every component and business
object combination (assuming no use of the toString() method on the
business objects).
Does anybody have any thoughts on this ? a better approach ?
Many Thanks
T
- 10
- 11
- WHICH J2ME Development Tool?Hello,
After researching the J2ME development tools, I finally decided on NetBeans
and I downloaded it today, with the mobility pack. I found NetBeans be very
powerful, yet I am just starting with Java. NetBeans overwhelmed me, even
with the simple NetBeans-generated "Hello World" MIDLet. I need a simpler
and less powerful development tool. Which development tool do you use for
J2ME? Thank you very much.
Best Regards,
T.I.
- 12
- Any good GUI design/prototyper tools?I'm looking for a tool that will let me quickly design/prototype Swing
GUI layouts so I can get screenshots for review by end users. The
emphasis is on design, not building as such - I'm not interested in
*using* any generated code at this stage, although the tool needs to
be able to save and load layouts, and preview the layouts.
What is really required is something that works like a drawing program
but with Swing components. Ideally it would:
o Allow absolute positioning and sizing, because at this stage I'm
essentially doing graphic design and don't want to be worrying about
implementation of layout managers
o Allow easy moving and alignment of elements or groups of elements
o Have a Property Editor, but with configuration of defaults so that I
don't have to, for example, change the font on every element.
o Have a quick build/preview so I can get screenshots easily.
I have looked at a few IDEs and GUI builder tools, but so far nothing
seems really orientated towards making this particular task quick and
easy. Does anyone know of anything that's appropriate... or should I
be thinking about coding something myself?
- 13
- customize JScrollBarHello,
I want to scroll up/down by pressing buttons
other than the standards of JScrollBar(These
simple up und down arrows).
Is it possible?
- 14
- Potentially dumb questionCould anyone tell me where I might download the latest version of the
Java Development Kit? I have an old Java book and I thought I might
play with it but I need a kit that works with Win XP.
TIA
-Lex
- 15
- Struts: How do I validate data from an edit form?Hello!
In my Struts app - after submit - I want to validate fields that were
filled with values from a database beforehand. To fill the fields with
the old values I write the existing data into a bean and use it in my
JSP as follows:
<jsp:useBean id="formData" scope="request" class="com.xyz"/>
<html:text name="formData" property="test"/>
So far so good.
When a validation error occurs the user is redirected to the same JSP.
The problem now is that the fields are empty because the bean defined
in the JSP doesn't exist anymore. In fact I actually don't want this
bean to be used. The form-bean which is containing the new data should
be used.
How can I acchieve that?
Regards,
Stefan
|
|
|