Java Forum / General / August 2007
TextArea resistant to change...
julielaurek@gmail.com - 03 Aug 2007 20:47 GMT 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()[i].addActionListener(this); namesPanel.add(getButtons()[i]); } 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()[i])){ String pname = getPrinterNames()[i]; 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[i] = new Button (services[i].getName()); } return printerButtons; } public String[] getPrinterNames(){ printerNames = new String[services.length]; for (int i = 0; i <services.length; i++){ printerNames[i] = services[i].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[i]); 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[i] = fm.stringWidth(printerNames[i]); }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(); } }
}
Andrew Thompson - 04 Aug 2007 02:12 GMT ...
>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>
 Signature Andrew Thompson http://www.athompson.info/andrew/
Twisted - 04 Aug 2007 02:19 GMT > 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
Andrew Thompson - 04 Aug 2007 03:24 GMT >> 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: 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.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Twisted - 04 Aug 2007 04:09 GMT [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.
Andrew Thompson - 04 Aug 2007 04:54 GMT >[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".
 Signature Andrew Thompson http://www.athompson.info/andrew/
nebulous99@gmail.com - 04 Aug 2007 05:56 GMT > >[snip confused post] > [quoted text clipped - 7 lines] > 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...
Mark Space - 04 Aug 2007 09:56 GMT > *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.
nebulous99@gmail.com - 04 Aug 2007 10:05 GMT > nebulou...@gmail.com wrote: > > *Sigh* Google Groups forbids that, too. The text box you type into is [quoted text clipped - 4 lines] > 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...
~kurt - 04 Aug 2007 18:30 GMT > *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
Lew - 04 Aug 2007 20:11 GMT >> *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.... 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.
 Signature Lew
~kurt - 05 Aug 2007 01:54 GMT > 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
Twisted - 05 Aug 2007 18:46 GMT [appears to be an insulting post that gets to its punchline very circuitously and long-windedly]
Haven't you got anything better to do?
Lars Enderin - 05 Aug 2007 18:56 GMT Twisted skrev:
> [appears to be an insulting post that gets to its punchline very > circuitously and long-windedly] > > Haven't you got anything better to do? That's rich, coming from you!
nebulous99@gmail.com - 05 Aug 2007 21:08 GMT > > [appears to be an insulting post that gets to its punchline very > > circuitously and long-windedly] > > > Haven't you got anything better to do? > > That's rich, coming from you! Who the hell are you, and why don't I remember asking for your opinion? I don't suppose it occurred to you that making your debut post to a newsgroup an OT, flaming one isn't exactly either normal or wise?
blmblm@myrealbox.com - 04 Aug 2007 21:10 GMT > > *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.... 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?
 Signature B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.
~kurt - 05 Aug 2007 01:52 GMT >> 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
Mark Space - 05 Aug 2007 05:51 GMT >>> So, as long as you are posting FORTRAN, everything is good.... >>> [quoted text clipped - 5 lines] > 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. ;-)
blmblm@myrealbox.com - 05 Aug 2007 22:13 GMT > >>> So, as long as you are posting FORTRAN, everything is good.... > >>> [quoted text clipped - 5 lines] > > I don't see the point of FORTRAN beyond FORTRAN 77. There are better > > languages out there in my opinion. <shrug> Okay with me. Just sayin', for the record and for anyone who doesn't know, that Fortran beyond FORTRAN 77 does exist (and has some adherents, judging by traffic in comp.lang.fortran).
> Wow, you're just getting pwnzord left and right there, Mr. blmblm. ;-) I am? < pause while I Google for a definition of "pwnzord" >
Oh no, does this mean I have to drag this thread further off-topic to defend .... something?
("Mr." isn't the right title, BTW -- wrong gender -- but I won't argue with anyone who wants to claim that "probably male" is the way to bet when one isn't sure.)
 Signature B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.
Twisted - 05 Aug 2007 18:45 GMT On Aug 4, 4:10 pm, blm...@myrealbox.com <blm...@myrealbox.com> wrote:
> Just sayin' -- and demonstrating that it's not just Twisted's > nits that are subject to being picked? One issue with your post -- I have no nits.
Roedy Green - 04 Aug 2007 14:23 GMT >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?
 Signature Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Andrew Thompson - 04 Aug 2007 15:15 GMT ...
>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+%22web+host%22>
 Signature Andrew Thompson http://www.athompson.info/andrew/
Mark Space - 05 Aug 2007 05:58 GMT > .. >> I posted a bit of code the other day that was damaged by line wrap. [quoted text clipped - 8 lines] > This search also suggests there are lots of possibilities. > <http://www.google.com/search?q=free+%22web+host%22> 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...
Patricia Shanahan - 05 Aug 2007 06:26 GMT >> .. >>> I posted a bit of code the other day that was damaged by line wrap. [quoted text clipped - 18 lines] > > Note: code not compile or syntax checked... I was able to copy-paste it into Eclipse.
Patricia
Andrew Thompson - 06 Aug 2007 01:45 GMT >Hey guys!! > >I'm trying to figure ... I suppose it has become apparant now, that this thread has attracted a lot of comment not directly connected with the technical question.
That happens sometimes.
Note that if you were to supply an SSCCE (or link to one) I am confident that there are a number of people (myself included) who would still be interested in looking at the technical side of the problem, with a view to resolving it.
 Signature Andrew Thompson http://www.athompson.info/andrew/
julielaurek@gmail.com - 06 Aug 2007 15:47 GMT > julielau...@gmail.com wrote: > >Hey guys!! [quoted text clipped - 16 lines] > > Message posted viahttp://www.javakb.com Hi again!
I'm really still a java novice so really, I'm sorry if I offended anyone. I am not sure how to re-post this because I had simply copied and pasted from eclipse before and it worked just fine. From one of the suggestions above I've used google docs and you can find a slightly modified version of the code here: http://docs.google.com/Doc?id=dcqbcf4x_28g9vprb I simply need to figure out why when I re-set my text area I see no changes, although from this page of the Sun website it should work: http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html
Thanks, JL
julielaurek@gmail.com - 06 Aug 2007 20:43 GMT > julielau...@gmail.com wrote: > >Hey guys!! [quoted text clipped - 16 lines] > > Message posted viahttp://www.javakb.com Hey!!!!!!!!!! I found the answer (for those who actually wanted to know what was wrong with the code =))! You see the method where I created my buttons? That's where I was supposed to add the action listener, instead of later on in the constructor.
Peace...
JL
Andrew Thompson - 07 Aug 2007 00:03 GMT ...
>Hey!!!!!!!!!! >I found the answer Yay! :-)
>...(for those who actually wanted to know what was >wrong with the code =))! You see the method where I created my >buttons? It is always helpful to report the solution back.
>...That's where I was supposed to add the action listener, >instead of later on in the constructor. Thanks for getting back to the thread, & reporting the solution.
And as for the 'diversion' that happened - that was entirely other people's doing. They had fun doing it (hopefully), but in case they didn't, that is entirely their own problem.
>Peace... ditto.. Glad you found the technical resolution.
 Signature Andrew Thompson http://www.athompson.info/andrew/
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|