Wikipedia:Reference desk/Archives/Computing/2015 May 11

Computing desk
< May 10 << Apr | May | Jun >> May 12 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


May 11 edit

setVisible in Swing edit

Why is false the default value for setVisible in Java Swing? If you're going through the trouble of creating a window, wouldn't you want it visible by default? Dismas|(talk) 05:38, 11 May 2015 (UTC)[reply]

Eventually, probably yes. But you may want the window to remain hidden while it is being populated. Making the default value False gives the programmer more control over exeactly when they make the window visible to the user. (This is based on general logic - someone with more Swing knowledge may come along with a more specific explanation). Gandalf61 (talk) 10:52, 11 May 2015 (UTC)[reply]
Dismas, I think you are slightly mistaken in your premise. Consult the documentation for JComponent, from which many other Swing UI objects are derived. "Components are initially visible, with the exception of top-level components." In other words, the default visibility is true, except for a handful of items (like JFrame - but these exceptions are clearly documented in the constructor javadoc). See Using Top-Level Containers... for information on the methodology and design philosophy. Nimur (talk) 11:01, 11 May 2015 (UTC)[reply]

Appending to the end of a line in Java edit

Say I have a CSV file and I want to append something onto the end of a line. How would I do that? Would I need to put the whole line into a string and then write over it essentially but with the added text on the end?

Also, how can I get the index of an item in a JComboBox?

Yes, this is for homework but they are not direct questions. Just very small pieces of a larger whole.

Thanks, Dismas|(talk) 10:59, 11 May 2015 (UTC)[reply]

There are many ways to accomplish these tasks... as you should know, String objects in Java are immutable. If you want to modify text data, you need a different approach. Consider the StringBuffer object, which implements Appendable; and implements several variations of insert. You can also use String.insert..., but you need to be careful and understand exactly how often you are instantiating brand new objects. This is the canonical answer for Java, but there are many other ways you can accomplish the task. You can construct your own custom object to represent a data structure comprised of many sub-strings. You can store individual characters or string fragments in arrays, linked lists, trees, or Java container objects. You can use Swing objects like JTextField to wrap the text storage; when appending, you can use the unique string appending syntax of Java to hide the operations of instantiating brand new strings (although this is inefficient use of compute- and memory- resources, it may be a maximally productive use of programmer-time).
For your next question, have you consulted the JavaDoc? With due respect, your teacher or professor is doing a poor job if they haven't deeply emphasized that the JavaDoc is your first resource, particularly for those features that form the Java standard class library. Nimur (talk) 11:15, 11 May 2015 (UTC)[reply]
First off, allow me to apologize for bothering you with my questions. The JavaDoc has not been my first resource or even any resource for me. I was aware of it but you're correct if you thought that my teacher hasn't mentioned it at all. Besides reading the Java tutorials, her other mainstay of the course has been Java for Dummies for which she provided a link where we can download it for free without any sign in or proof that we are students (and thus possibly suggesting that the school has paid for its use). As far as I understand the copyright in the beginning of the book, it's not to be given away freely either in dead tree or pdf form, so I'm unsure as to how this has been legal.
Getting back to the JavaDoc though, I'm not really sure how to read it though I will try to muddle through with it. Thank you for pointing me to it. Dismas|(talk) 13:01, 11 May 2015 (UTC)[reply]
The JavaDoc link above is to the frameless version. Near the top, you will a link that says "Frames". Click that. Now, every class that comes with Java is listed down the left side. If you want to know something about JTextField, you scroll down until you see that class. Click on it and it will bring up a class description. Look through that. You will see all the possible constructors and methods for the class. Often, there are links to tutorials in the description. This should the the primary source of information when programming in Java. I have personally taught Java for four semesters. The first two weeks covered structure, how to compile, and flow control. Then, we spent a week doing nothing but looking up how to do things using the JavaDoc. After that, I wouldn't accept any complaints like "I couldn't figure out how to get the width of a JFrame." 209.149.114.86 (talk) 13:39, 11 May 2015 (UTC)[reply]
Indeed. Dismas, we are happy to volunteer our time to help answer your questions about computing; but in this particular instance perhaps the best help we can provide is to direct you toward the methodology of checking the official JavaDoc... because, (as you will shortly discover), that is where you will find clear instructions on exactly how to locate an object by index in a JComboBox. The very same will apply to many other similar procedural questions that you will have in the future as a Java programmer. At first, the documentation format is a bit intimidating, but it is very consistently formatted and structured, so if you invest an hour to learn how to read, understand, and directly search it, it will save you countless hours of future undirected search. In fact, one of Java's greatest comparative advantages as a programming language is that it has had, since its earliest history, great documentation. The documentation is not flawless, but it is vastly superior to documentation you would find for, say, the FORTRAN or C or Pascal standard libraries.
Every great programmer started out as a novice (and somebody had to tell all of us to RTFM at least once before we understood that this advice is not always meant in anger or derision). Nimur (talk) 15:10, 11 May 2015 (UTC)[reply]

Magnets edit

On the command prompt in Windows 7 how does one generate a magnet URI from a dot torrent file? — Preceding unsigned comment added by 117.178.12.70 (talk) 16:22, 11 May 2015 (UTC)[reply]

Firefox crashes (and flash player) edit

Has anyone else seen a large uptick in Firefox crashing very recently? For the past two weeks about, Firefox has been crashing constantly, on three different Macs I use. Two are Mac Minis, one running Yosemite and another running Snow leopard and the third is a IMac running Yosemite. All three have the latest Firefox and latest Flash player. Firefox has been crashing on all three on various sites with video content; long beach-balling, and if I don't force quit (where is shows ("not responding")), I've been getting the message that flash player has crashed. So, given three different computers, I am imputing this is not just me (but maybe it could be an add-on; I run classic theme restorer on all three)? Maybe some incompatibility between the latest flash and latest Firefox? (When I re-open these sites in Safari of Chrome there's no problem)--96.246.181.46 (talk) 18:19, 11 May 2015 (UTC)[reply]

FWIW, in maybe the last 10 days, the Firefox window has suddenly vanished completely on 3 or 4 occasions while I was streaming a programme from the BBC iPlayer (in the UK, as you can probably tell from my spelling). While not frequent enough to be a problem, this is a higher rate than the previous, very rare instances of this over the last few years. {The poster formerly known as 87.81.230.195} 212.95.237.92 (talk) 13:22, 13 May 2015 (UTC)[reply]

Testing Router's Intermittent Connection Drops edit

I recently purchased a new router because my old router would intermittently lose connection once every hour or so. Is there a simple website or web app I can use to test how frequently my connection drops? I suppose playing an online video game would do the trick, since my game would stop when my connection drops, but is there a more passive, less CPU-intensive method of testing the connection? Thanks. Acceptable (talk) 19:35, 11 May 2015 (UTC)[reply]

You'd need to test with both the old router and the new to get a fair comparison. Do you really want to do that ? StuRat (talk) 14:37, 12 May 2015 (UTC)[reply]
Well I've had the old router for a while, so I know that it drops pretty consistently every hour or so. So if the new one does not drop after a few hours, I am pretty comfortable concluding that the new one is indeed an improvement. Acceptable (talk) 18:33, 12 May 2015 (UTC)[reply]
 
DSL modem 200 CELL 19A-BX-AR 01-2007 defective capacitors (2014)
Start a test download and ping a known machine with lower ping rate, but not limited to 4 pings. Trace the ping by appending it to a file. Some routers contain obsolescent dimensioned parts making the device fail reliable operating. --Hans Haase (有问题吗) 20:33, 12 May 2015 (UTC)[reply]
While some DSL routers for consumer use are really bad, commercial rack mount switches and routers are designed more reliable than a personal computer. If you are able to repair it, go for it, but use suitable parts. --Hans Haase (有问题吗) 20:46, 12 May 2015 (UTC)[reply]
My router has a "troubleshooting" page where you can ping an IP address. I'm not at home so can't look up the specifics, but I suspect it's a fairly common feature, maybe you can try that? If you find out your ISPs gateway and ping that from your router, this will show you if the connection betwen your router and your ISP is dropping. Then ping from your computer to any address on the internet you can reach. If both pings fail at the same time when you experience the "issue" you are having, you know it's the connection between your ISP and router and you should be able to report that as a fault your ISP should fix. If the ping on your compter drops out but the router one doesn't you know it must be up or down stream of the connection between your ISP and your router. Vespine (talk) 01:02, 13 May 2015 (UTC)[reply]
Ther are a number of utilities that will ping an address and log it, thus showing dropped connections. -- Gadget850 talk 01:27, 13 May 2015 (UTC)[reply]
If Your DSL router's capacitors look like that in the picture, You know why it is going offline. --Hans Haase (有问题吗) 12:38, 16 May 2015 (UTC)[reply]