TextArea resistant to change...

J

julielaurek

Hey guys!!

I'm trying to figure out what I've done wrong here. So I have the
piece of code at the end of this post and I'm trying to reset the text
everytime a button is clicked, but nothing happens. I am using
com.neva from this website:http://www.nevaobject.com/products.htm
(mainly JPrint, but you need Coroutine to make it work)
and it works fine with their sample code at the bottom of this page:
http://www.nevaobject.com/_docs/_jprint/JPrint.htm
So I must have a syntax or scope problem or something somewhere but I
can't figure it out. Can anyone please help me out?

Thanks,

JL

//Basically this dialog pops up when i click on a button generated by
another class, pWATCH.




import java.awt.*;
import java.awt.event.*;
import java.util.*;

import javax.print.*;

import com.neva.*;
public class PrinterMonitor extends Dialog implements ActionListener {
final int height = 450;
final int width = 200;
private pWATCH parent;
private String[] printerNames;
private Panel textPanel;
private TextArea printerMessages;
private PrintService[] services =
PrintServiceLookup.lookupPrintServices(null, null);

public PrinterMonitor(pWATCH parent) {
super(parent, "Printer Monitor", true);
this.parent = parent;
addWindowListener(new CloseHandler(this));

if(services.length != 0){
Panel introPanel = new Panel();
introPanel.setLayout(new GridLayout(2,1));
introPanel.add(new Label("Please select the printer you will be
monitoring", Label.CENTER));
introPanel.add(new Label("Please verify that pageWATCH is attached
to the chosen printer", Label.CENTER));

Panel namesPanel = new Panel();
namesPanel.setLayout(new GridLayout(4, 4));
for (int i = 0; i < getButtons().length; i++){
getButtons().addActionListener(this);
namesPanel.add(getButtons());
}
Panel cancelButtonP = new Panel();
cancelButtonP.setLayout(new GridLayout(4,4));
Button cancelButton = new Button("Cancel!");
cancelButton.addActionListener(this);
cancelButtonP.add(cancelButton);

Panel allButtons = new Panel();
allButtons.setLayout(new GridLayout(2,1));
allButtons.add(namesPanel);
allButtons.add(cancelButtonP);
add(allButtons, "Center");

textPanel = new Panel();
textPanel.setLayout(new GridLayout(1,1));
printerMessages = new TextArea();
printerMessages.setEditable(false);
textPanel.add(printerMessages);
add(textPanel, "South");
}
else{
Panel infoPanel = new Panel();
infoPanel.add (new Label("Sorry. There are no printers
connected to this machine.", Label.CENTER));
infoPanel.add(new Label("Please connect a printer and try
again.", Label.CENTER));
add(infoPanel, "Center");
}
int minScreenWidth = getWidth();
setSize(width + minScreenWidth, height);
setLocation(parent.getLocationOnScreen().x + 30,
parent.getLocationOnScreen().y + 30);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
for (int i = 0; i < getPrinterNames().length; i++){
if(cmd.equals(getPrinterNames())){
String pname = getPrinterNames();
JPrint jpr = new JPrint();
jpr.ReleasePrinter();
PrinterInfo info=JPrint.GetPrinterInfo(pname);
if(info!=null) {
String printername = "Printer Name: " + info.PrinterName();
String portname = "Port Name: " + info.PortName();
String comment = "Comment: " + info.Comment();
String numberofjobs = "Number of Jobs in Queue: " +
info.Jobs();
String averageppm = "AveragePPM" + info.AveragePPM();
printerMessages.setText("\n--- " + printername + " ---\n"
+ portname + "\n" + comment + "\n" + numberofjobs +
"\n" + averageppm + "\n");
}
}
}
}
}
public void colorUp(){
Color someSortOfBlue = new Color(51, 153, 153);
this.setBackground(someSortOfBlue);
}
public Button[] getButtons(){
Button[] printerButtons = new Button[services.length];
for (int i = 0; i < services.length; i++){
printerButtons = new Button (services.getName());
}
return printerButtons;
}
public String[] getPrinterNames(){
printerNames = new String[services.length];
for (int i = 0; i <services.length; i++){
printerNames = services.getName();
}
return printerNames;
}
public double myMax(double[] array){
double tracker1 = array[0];
double tracker2 = array[0];
double sizeOfArray = array.length ;
if (sizeOfArray == 0){
System.out.println("The array has no items!");
return 0;
}
for(int i = 1; i< sizeOfArray ; i++ ){
tracker1 = Math.max(tracker2, array);
tracker2 = tracker1;
}
return tracker1;
}
public int getWidth(){
printerNames = getPrinterNames();
FontMetrics fm = getFontMetrics(getFont());
double[] printerNamesWidth = new double[printerNames.length];
for (int i = 0; i < printerNames.length; i++){
printerNamesWidth =
fm.stringWidth(printerNames);
}return (int) myMax(printerNamesWidth);
}
class CloseHandler extends WindowAdapter{
PrinterMonitor pm;

public CloseHandler(PrinterMonitor pm){
this.pm = pm;
}

public void windowClosing (WindowEvent e){
pm.removeWindowListener(this);
pm.dispose();
}
}


}
 
A

Andrew Thompson

I'm trying to figure out what I've done wrong here. ...
//Basically this dialog pops up when i click on a button generated by
another class, pWATCH.

Uh-oh! When posting code, it is generally considered
best to post an SSCCE*. An SSCCE has all the bits
needed to reconstruct the problem on another machine.
This code, without it's own main, will surely not do that.

Further, I was prepared to add a main(), but when I tried to
compile the code, it produced 48 compilation errors due to
things like strings that had been broken in line-wrap.

Please consider posting SSCCE's in future. You will
get more, and better, help.
<http://www.physci.org/codes/sscce.html>
 
T

Twisted

Further, I was prepared to add a main(), but when I tried to
compile the code, it produced 48 compilation errors due to
things like strings that had been broken in line-wrap.

The OP is posting through Google Groups, which means two things:
a) he can't turn off line-wrap for code he pastes in and
b) he probably has no alternative news posting capability or he'd
already be using it in preference to GG, so suggesting that he not use
GG is pointless and will only annoy him
 
A

Andrew Thompson

Twisted said:
The OP is posting through Google Groups, which means two things:

This has *nothing* to do with the OP's method
of posting to usenet. I have successfully posted
many SSCCE's through both GG and my current
web interface to usenet (WITUN), JavaKB.
a) he can't turn off line-wrap for code he pastes in ...

..not that I even understand what that is supposed to
mean. 'Nobody' can turn off this line-wrap..

Note that even if GG or JavaKB did *not* wrap code,
most *rich* *client* news clients will wrap lines at
around 63 chars. The line-wrap problem can both be
caused, and experienced, by people posting or reading
with conventional news clients - it has nought to do
with the WITUN's - but more to do with years old
conventions of usenet, and how readers format the
posts.
 
T

Twisted

[snip confused post]

You misunderstand me.

Google ENFORCES line wrap. It automatically wraps everything in the
web form at (I think) 72 characters. So users of GG have no way to
post code with long lines WITHOUT those lines getting wrapped.
 
A

Andrew Thompson

Twisted said:
[snip confused post]

You misunderstand me.

Google ENFORCES line wrap. It automatically wraps everything in the
web form at (I think) 72 characters.

You misunderstand me. My point is for the *programmer*
to reformat the code and wrap lines at logical points to make
them short. Or if they cannot be bothered doing that, to
please not waste their time, or our bandwidth.

This point is of particular interest to people who actually
take code off fourms, paste it into an editor/IDE, compile,
run and debug it. To my knowledge, you do not have much
experience with that process, you are more interested in
philosophical, design and providing the short answer to
'code snippet' style questions.

Please try compiling some code from around the forum,
to get a feel for my point. An SSCCE can be breaking in
my PC, exactly like for the OP, in less than a minute.

Whether to post a simple question with a code snippet,
or to post a 'self contained' example is always a judgement
call. But if the OP seems to be posting more than snippets,
I will generally suggest going to the further effort of preparing
an SSCCE.

As an aside, have you ever read the SSCCE document?

There is more to an SSCCE than it might at first seem.
Most SSCCE's that are being prepared, never need to
be posted anywhere.
...So users of GG have no way to
post code with long lines WITHOUT those lines getting wrapped.

The solution to which is "don't attempt to post long lines".
 
N

nebulous99

Twisted said:
[snip confused post]
You misunderstand me.
Google ENFORCES line wrap. It automatically wraps everything in the
web form at (I think) 72 characters.

You misunderstand me. My point is for the *programmer*
to reformat the code and wrap lines at logical points to make
them short. Or if they cannot be bothered doing that, to
please not waste their time, or our bandwidth.

*Sigh* Google Groups forbids that, too. The text box you type into is
far wider than 72 characters and the wrap position isn't marked in any
way. A line can look fairly short and turn out to be just over the
limit, so the last word on it wraps unexpectedly. You have no way of
accurately judging when this will occur as there are no visual cues,
short of actually going to the bother of manually counting
characters(!), a slow and probably error-prone task that clearly
shouldn't be required. Of course, they can try to make sure the lines
are really REALLY short, but that might impact readability by making
the snippet too long vertically where this could have been avoided.
Composing in the editor of one's choice would likely fix that; too bad
GG just uses whatever your web browser uses for textareas in HTML
forms, and your web browser probably uses a plain-jane text field
control for that without bells or whistles. Unlike a real newsreader,
which would either indicate the wrap line, actually wrap as you typed
so you could see what it would look like when posted while editing, or
let you plug in the editor of your choice...
 
M

Mark Space

*Sigh* Google Groups forbids that, too. The text box you type into is
far wider than 72 characters and the wrap position isn't marked in any
way. A line can look fairly short and turn out to be just over the
limit, so the last word on it wraps unexpectedly. You have no way of

Unless you type short lines into your editor, check the code compiles,
and then just cut and paste that with the newlines already in place.
 
N

nebulous99

Unless you type short lines into your editor, check the code compiles,
and then just cut and paste that with the newlines already in place.

That's only applicable to full-blown SSSCEs and the like. And of
course that rather limits one from doing it on a whim for every
occasion that calls for a code snippet -- I don't know about the other
major IDEs, but Eclipse is rather sluggish to start up (though
responsive once running) and quite a memory hog, and there's a fair
amount of work involved in creating a whole new project, putting in
the code, compiling and testing etc.; perhaps if there was an easy way
to automate the bulk of the process and we all had 4GB-RAM b0xen
conducive to leaving Eclipse idling even when doing other stuff...but
I'm fairly sure most of us have only, say, 1GB or less RAM and
experience increasing slowdowns and thrashing once that's exceeded by
the running applications.

There's also the slight issue that it's all moot anyway, because the
typical IDE edit window doesn't line-wrap or mark column 72 any more
than Google Groups' post editor does, and tends to be quite wide (over
100 characters). So the suggestion to paste the code in from the IDE
editor only moves the problem, rather than solving it, and adds extra
hoops to jump through and, for those of us with a "mere" single
gigabyte of RAM in their machines, whole new actual problems too.

I suppose now you'll suggest using a *third* editor intermediary, one
that does wrapping or something, just to manage all of this ... at
which point you're *really* starting to discourage anyone from
rattling off a quick usenet post with helpful code snippet ideas in
it! Turning a one-minute job into a ten-minute one kind of cuts down
on how often someone's willing to do it...
 
R

Roedy Green

The OP is posting through Google Groups, which means two things:
a) he can't turn off line-wrap for code he pastes in and
I posted a bit of code the other day that was damaged by line wrap.
I thought later I should have posted it on the web site with an URL.
Are there public access places for people to do that who don't have
their own website?
 
A

Andrew Thompson

Roedy Green wrote:
...
I posted a bit of code the other day that was damaged by line wrap.
I thought later I should have posted it on the web site with an URL.
Are there public access places for people to do that who don't have
their own website?

GeoCities is still allowing membership, though you might
have to zip Java files for upload (they only accept specific
file types).

This search also suggests there are lots of possibilities.
<http://www.google.com/search?q=free+"web+host">

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200708/1
 
K

~kurt

*Sigh* Google Groups forbids that, too. The text box you type into is
far wider than 72 characters and the wrap position isn't marked in any

So, as long as you are posting FORTRAN, everything is good....

- Kurt
 
L

Lew

~kurt said:
So, as long as you are posting FORTRAN, everything is good....

One of the distinguishing personality characteristics of the successful
engineer is the drive to understand and exploit the subtleties of their
systems and tools. An engineer using GG would understand the text-line limit
and exploit it, or at least account for it, to improve the quality of their
communications. Far from finding it "insulting" or "impugning" of their
character, these happy GG users will thank those who advise them of the way to
best communicate their technical issues. They will understand and accommodate
the strengths and weaknesses of the GG interface, keeping their code postings
intelligible despite the known quirks of the medium. They will sing hosannas
to those who advised them how best to do this.

Otherwise they're egotistical crybabies. You can tell which from which by the
tone of their responses.
 
B

blmblm

So, as long as you are posting FORTRAN, everything is good....

If you're posting Fortran [*], however ....

[*] Preferred capitalization, AIUI, for Fortran 90 and beyond, which
provides for a less restrictive source format.

Just sayin' -- and demonstrating that it's not just Twisted's
nits that are subject to being picked?
 
K

~kurt

blmblm myrealbox.com said:
So, as long as you are posting FORTRAN, everything is good....

If you're posting Fortran [*], however ....

[*] Preferred capitalization, AIUI, for Fortran 90 and beyond, which
provides for a less restrictive source format.

I don't see the point of FORTRAN beyond FORTRAN 77. There are better
languages out there in my opinion.

- Kurt
 
K

~kurt

Lew said:
the strengths and weaknesses of the GG interface, keeping their code postings
intelligible despite the known quirks of the medium. They will sing hosannas
to those who advised them how best to do this.

Personally, when I ask for free help, I do my best to make it as easy as
possible for those who I am asking.

- Kurt
 
M

Mark Space

~kurt said:
blmblm myrealbox.com said:
So, as long as you are posting FORTRAN, everything is good....
If you're posting Fortran [*], however ....

[*] Preferred capitalization, AIUI, for Fortran 90 and beyond, which
provides for a less restrictive source format.

I don't see the point of FORTRAN beyond FORTRAN 77. There are better
languages out there in my opinion.

Wow, you're just getting pwnzord left and right there, Mr. blmblm. ;-)
 
M

Mark Space

Andrew said:
Roedy Green wrote:
..

GeoCities is still allowing membership, though you might
have to zip Java files for upload (they only accept specific
file types).

This search also suggests there are lots of possibilities.
<http://www.google.com/search?q=free+"web+host">

If you're using Google anyway, Google has this documents thing where you
can keep spreadsheets and whatnot on-line.

Just make a text document, paste your code in it, and provide a linky.

Let's see if it works:

http://docs.google.com/Doc?id=ddgtkqjv_0gs5j5f

Note: code not compile or syntax checked...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top