|
rhag posted:So in order to achieve your goal you should have your own object, with a setNeckbeards() method. Create one instance of that object, add it to the vector, set the neckbeards value to something else, and see it change everywhere that object is referenced. So, basically I need to... code:
Am I going to run into problems with failing to initialize "contents" if it's not a blocked primative?
|
# ? Jul 15, 2009 20:35 |
|
|
# ? May 9, 2024 04:53 |
|
rhag posted:What? What does the scope of a variable has to do with references ? What are you talking about? If you had paid attention to what Gravity Pike actually wrote, as opposed to jumping at straws to pen your magnum opus, my post would seem perfectly clear. No-one else was having problems with the idea that variables of Object type (of whatever storage class) are actually references to objects. I'm sure your parents are very proud that you've mastered the idea well enough to babble incomprehensibly about it. GP wanted to know if you could create a reference to a variable, and the answer is no, you can't. rhag posted:I have no words for this... That's a relief.
|
# ? Jul 15, 2009 20:36 |
|
Gravity Pike posted:And making sure that every variable I might care about is of type Thing. Yeah, that's a valid way of doing it. Gravity Pike posted:The get/set syntax is inconvenient, and I figured there might be an easier way built into the language. The closest you'll get is the closure stuff I mentioned, if you make the variables instance fields somewhere instead of locals. But I wouldn't say it's easier than what you're doing. It'd be less syntactically heavyweight if you just make it a public field; that's fairly reasonable for something like this. code:
Gravity Pike posted:Am I going to run into problems with failing to initialize "contents" if it's not a blocked primative? Instance variables are always implicitly initialized. Variables of object type get initialized to null.
|
# ? Jul 15, 2009 20:46 |
|
rjmccall posted:
So, would you then please tell me what the following code does? What is "ref"? code:
"ref" is a variable. "ref" holds the reference to the MyNewRef object instance. whether ref is local, private, public or whatever it doesn't change its status as a variable (you can change its value by saying: ref=new MyNewRef() this getting a new instances), and it will never change the fact that "ref" is just a reference. If you can't see the absurdity of your statement...
|
# ? Jul 15, 2009 21:04 |
|
rhag posted:So, would you then please tell me what the following code does? What is "ref"? It's exactly what you said: a variable that holds a reference to an object. What is wrong with you that you can't comprehend the difference between that and a variable that holds a reference to another variable? References are always references to something; Java allows you to create references to objects (indeed, it's the only way you can interact with objects), but not references to variables. Here, look, this is a variable that holds a reference to another variable: code:
|
# ? Jul 15, 2009 21:49 |
|
I loving love this argument. What round is this?
|
# ? Jul 15, 2009 22:02 |
|
rjmccall posted:It's exactly what you said: a variable that holds a reference to an object. What is wrong with you that you can't comprehend the difference between that and a variable that holds a reference to another variable? References are always references to something; Java allows you to create references to objects (indeed, it's the only way you can interact with objects), but not references to variables. "ref" in my code is a variable "a" in your code is a variable ref is a reference to an object, a is a primitive. Now i get your confusion. Please please, go back to CS101 and brush up on these very simple concepts. Come back after that and we'll talk. In response to another question in this thread asked earlier: In Java objects are passed by reference, primitives are passed by value. All the time and you cannot change this. This is something set in stone. However, there is a set of objects that you cannot change their contents: String,Integer, Double,etc. As such, even if you are passing a string object as a reference to a method, you cannot change its contents in that method and expect to see the new char array i the caller. Thus: code:
The caller will never know that, it still has a reference to the old object. The same is true for Integer. Doing this: code:
code:
But...all of this babble is really just basic Java. Any book about the language (somewhat decent, not written by a VB programmer ) will tell you this and more.
|
# ? Jul 15, 2009 22:13 |
|
I think rjmccall and HatfulOfHollow might know all that, and I think it might have been covered repeatedly in this thread rhag posted:Please please, go back to CS101 and brush up on these very simple concepts. Come back after that and we'll talk. Didn't call him a gay babby, still not up to AD's standards HatfulOfHollow posted:I loving love this argument. What round is this? 43 pages mod 5ish, probably round 8.
|
# ? Jul 15, 2009 22:21 |
|
rhag posted:Java passes everything by value, and an object reference is a primitive type. Inside a method call, when you receive a primitive value on the stack, you can reassign the value and it won't affect the caller. If the primitive type you receive is an object reference and you don't reassign it, you can poke at the object to your heart's content and your actions will have consequences outside the current method.
|
# ? Jul 15, 2009 22:27 |
|
Lysidas posted:The most accurate way to think about this is as follows: That's probably the most concise way to put it. My favorite way to demonstrate it is with two code snippets (obvously you'll need an enclosing class): code:
code:
crazyfish fucked around with this message at 00:11 on Jul 16, 2009 |
# ? Jul 16, 2009 00:09 |
|
rhag posted:(concatenate strings with +, while == performs an .equals() ). BZZZT. == foo is NOT .equals(foo) for Strings You'd have to use .intern() or something similar for == to consistently work.
|
# ? Jul 16, 2009 03:38 |
|
Brain Candy posted:BZZZT. == foo is NOT .equals(foo) for Strings so.. == just points to memory. Iirc, it literally compares memory addresses (yes, even in java) and a .equals() method has 2-4 different checks for equality, one of which (*should) includes == (to see if the memory reference is the same).
|
# ? Jul 16, 2009 05:04 |
|
Brain Candy posted:BZZZT. == foo is NOT .equals(foo) for Strings That is correct. However, "interning" is done automatically most of the time due to the following specifications: # Literal strings within the same class (§8) in the same package (§7) represent references to the same String object (§4.3.1). # Literal strings within different classes in the same package represent references to the same String object. # Literal strings within different classes in different packages likewise represent references to the same String object. # Strings computed by constant expressions (§15.28) are computed at compile time and then treated as if they were literals. # Strings computed by concatenation at run time are newly created and therefore distinct. For those who are wondering wtf this all means, run the following code: code:
true Hello false true
|
# ? Jul 16, 2009 05:11 |
|
I'm using Netbeans to build a sample GUI and all the code autogeneration is going fine but I've run into a problem. I put so much stuff in the GUI that it goes past 1200 pixels in the vertical direction, so I can't see some of the buttons and text fields I've added to the bottom of the GUI. The GUI doesn't have a scrollbar so I added one from the Swing Controls menu, but I guess it isn't linked to the main JFrame because sliding the scrollbar up and down doesn't actually do anything. Basically, does anyone know what I'd need to do to add scrollbar functionality to my GUI via Netbeans? I'm not very familiar with Swing, so writing it myself rather than autogenerated would not be preferred, but if I have to I can.
|
# ? Jul 16, 2009 05:25 |
|
I think what you want is a ScrollPane and then you will need to insert your GUI elements into the ScrollPane. You can do this with the editor in netbeans, it'll just take you a while to put everything back where it was :\
|
# ? Jul 16, 2009 06:14 |
|
Shavnir posted:I think what you want is a ScrollPane and then you will need to insert your GUI elements into the ScrollPane. You can do this with the editor in netbeans, it'll just take you a while to put everything back where it was :\ Yeah I figured this was the route to go, but I'm having some weird behavior with the ScrollPane. When I put any text field, label, or anything else into the ScrollPane that I create, it immediately fills the whole thing up and won't let me resize it. Have you run into this before?
|
# ? Jul 16, 2009 06:47 |
|
Just wanna throw out that a CS101 class that uses both the terms 'objects' and 'primitive types' is probably worthless
|
# ? Jul 16, 2009 06:53 |
|
Gonna throw out that a CS101 class that uses Java is absolutely worthless
|
# ? Jul 16, 2009 13:11 |
|
csammis posted:Gonna throw out that a CS101 class that uses Java is absolutely worthless When I teach a 101 equivalent, I make sure to use a combination of LISP and 68000 assembly to give them the best start in life.
|
# ? Jul 16, 2009 13:50 |
|
rhag posted:now I get it. You sir are confusing the "variable" concept with the "primitive" concept. lollin @ dis
|
# ? Jul 16, 2009 16:41 |
|
quadreb posted:When I teach a 101 equivalent, I make sure to use a combination of LISP and 68000 assembly to give them the best start in life. So GOAL then? http://en.wikipedia.org/wiki/Game_Oriented_Assembly_Lisp
|
# ? Jul 16, 2009 16:50 |
|
I am trying to make a few modifications to a java program that was written by someone else. The previous programmer left her source code as well as the .class files. I can run the main .class file and the program starts, however when I recompile the main .java file without making any changes to it and try to run the program again, I encounter a NullPointerException for one of the lines in the main file. Replacing the .class file that I compiled with the original one makes the program run again. The only explanation I can come up with is that the .class was compiled from a different source file than the one I was left with. Am I correct, or is there another explanation?
useless player fucked around with this message at 19:32 on Jul 16, 2009 |
# ? Jul 16, 2009 19:18 |
|
useless player posted:I am trying to make a few modifications to a java program that was written by someone else. The previous programmer left her source code as well as the .class files. I can run the main .class file and the program starts, however when I recompile the main .java file without making any changes to it and try to run the program again, I encounter a NullPointerException for one of the lines in the main file. Replacing the main .class file that I compiled with the original one makes the program run again. The only explanation I can come up with is that the .class was compiled from a different source file than the one I was left with. Am I correct, or is there another explanation? That is the most logical explanation. The original .class was compiled from a different source file than what you have.
|
# ? Jul 16, 2009 19:34 |
|
dealmaster posted:Yeah I figured this was the route to go, but I'm having some weird behavior with the ScrollPane. When I put any text field, label, or anything else into the ScrollPane that I create, it immediately fills the whole thing up and won't let me resize it. Have you run into this before? To get what you want, you'll need to create a custom scrollable component (extents JPanel probably). You have a nice tutorial here: http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html#scrollable
|
# ? Jul 16, 2009 19:38 |
|
rhag posted:That is the most logical explanation. The original .class was compiled from a different source file than what you have. So I've tried decompiling the main .class file and examining the source. The class constructor calls a method with a really weird name, $$$setupUI$$$(), which does not appear in the source file I was given. Searching through every source file for the string 'setupUI' turns up nothing. This really sucks, but I guess the class file is from another source. Edit: Actually it turns out that the previous programmer worked on the project in an IDE and her computer crashed. I'm just working with the raw source files and that would explain the weirdness about compiling. Does anybody have any experience in a situation like this? useless player fucked around with this message at 02:49 on Jul 17, 2009 |
# ? Jul 16, 2009 23:31 |
|
rhag posted:To get what you want, you'll need to create a custom scrollable component (extents JPanel probably). That's one option. The other is to just drop a JPanel in there and put all of the components inside of that.
|
# ? Jul 17, 2009 00:00 |
|
useless player posted:Edit: Actually it turns out that the previous programmer worked on the project in an IDE and her computer crashed. I'm just working with the raw source files and that would explain the weirdness about compiling. Does anybody have any experience in a situation like this? IDE's shouldn't generally produce code that is IDE dependent (that's not to say it hasn't happened). Why don't you debug why you're getting the exception and work from there?
|
# ? Jul 17, 2009 05:33 |
|
useless player posted:So I've tried decompiling the main .class file and examining the source. The class constructor calls a method with a really weird name, $$$setupUI$$$(), which does not appear in the source file I was given. Searching through every source file for the string 'setupUI' turns up nothing. This really sucks, but I guess the class file is from another source. What's the fully qualified package for that class? I googled $$$setupUI$$$ and found a groovy project for the intellij ide here: http://www.jetbrains.net/jira/browse/GRVY-2045 Anything look familiar?
|
# ? Jul 17, 2009 06:13 |
|
quadreb posted:IDE's shouldn't generally produce code that is IDE dependent (that's not to say it hasn't happened). Why don't you debug why you're getting the exception and work from there? They would if she used the IDE's GUI layout tool.
|
# ? Jul 17, 2009 10:20 |
|
Mill Town posted:They would if she used the IDE's GUI layout tool. Not if the tool was any good - a good GUI layout tool is merely a frontend, not something that makes your software required to be bundled with extra layout classes and crap. Licensing, portability, etc - it's a mess.
|
# ? Jul 17, 2009 10:34 |
|
rhag posted:That is correct. However, "interning" is done automatically most of the time due to the following specifications:
|
# ? Jul 17, 2009 13:44 |
|
1337JiveTurkey posted:That's one option. The other is to just drop a JPanel in there and put all of the components inside of that. For right now I've switched to a tabbed layout and it actually works a little better as far as organization is concerned, and it's alleviated the need for scrollbars, but I would still like them to be an option since I don't know what resolutions people will be using this application on. As of right now an abstraction of the basic layout is this: code:
|
# ? Jul 17, 2009 14:42 |
|
This is more an Eclipse setup question (and I come from an IntelliJ setup so Eclipse is very new to me) Project tree is /svn/project/trunk/core/src/main/java/com/company/package/class Project builds fine with Maven, and works properly when deployed; however Eclipse keeps throwing errors that: com.company.package is not valid and needs to be main.java.com.package. It also does not recognize / reference other classes within the same package. Eclipse can see my Maven repo, but not this. I have the same project setup with IntelliJ and it's working fine. Using Dynamic Web Project at the moment, but the others had similar results. Is this a setting or in the type of project it should be?
|
# ? Jul 17, 2009 14:52 |
|
geeves posted:Project tree is /svn/project/trunk/core/src/main/java/com/company/package/class
|
# ? Jul 17, 2009 15:17 |
|
dealmaster posted:For right now I've switched to a tabbed layout and it actually works a little better as far as organization is concerned, and it's alleviated the need for scrollbars, but I would still like them to be an option since I don't know what resolutions people will be using this application on. Yes. By creating a new class, that extends JPanel and implements Scrollable. The tutorial that I've posted the link to provides the solution nicely. And scrollbars will only appear when needed. However...I'm not really sure why do you need scrollbars at all. I mean..the components should resize themselves when the application resizes. A very good layout to use is GridBagLayout. Complex but very powerful. If the users have a small resolution (you have to set a minimum supported, lets say 800x600), the components will just be smaller, but they should be proportional to a 1600x1200 resolution.
|
# ? Jul 17, 2009 15:21 |
|
geeves posted:This is more an Eclipse setup question (and I come from an IntelliJ setup so Eclipse is very new to me)
|
# ? Jul 17, 2009 15:24 |
|
zootm posted:Are you using the Maven plugin for Eclipse? I imagine some horrors occur trying to make Maven's ultra-consistent weirdness work within an ad-hoc project context. I have m2eclipse installed, but I don't think I'll use, I usually just build from the command line. I had the MVN plugin for IntelliJ installed and maybe used it once total over 3 years. quote:This sounds like Eclipse doesn't know what your root source directory is . In the project properties, set the source directory to that "main/java". Then the packages will follow from there( eclipse will properly see com.company.package as the package). Yep, this was it - thanks!
|
# ? Jul 17, 2009 15:34 |
|
rhag posted:Yes. Yeah I tried using this layout, but I can't seem to figure out how to spread the combo boxes and text fields out how I'd like to. I tried using different anchor values and messing with the insets, but all the buttons, labels, etc. all end up clumping together. Even if I try to leave a bunch of blank space between two of them using the customize layout option in Netbeans, they don't actually move far away from each other, they're still stuck together.
|
# ? Jul 17, 2009 15:54 |
|
dealmaster posted:Yeah I tried using this layout, but I can't seem to figure out how to spread the combo boxes and text fields out how I'd like to. I tried using different anchor values and messing with the insets, but all the buttons, labels, etc. all end up clumping together. Even if I try to leave a bunch of blank space between two of them using the customize layout option in Netbeans, they don't actually move far away from each other, they're still stuck together. you need to get away from that GUI editor. It's so easy to write a nice UI in java, that using a GUI editor will only slow you down. Read this: http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html It tells you how to use it, what all the arguments mean, etc.
|
# ? Jul 17, 2009 16:11 |
|
|
# ? May 9, 2024 04:53 |
|
rhag posted:you need to get away from that GUI editor. It's so easy to write a nice UI in java, that using a GUI editor will only slow you down. Yeah it would probably be better, but I've never done GUI programming by hand, so trying to do what I've already done with the editor by hand is really daunting. At the moment, the GUI editor is allowing me to do things that I have no idea how to do by hand, which is why I chose to use it. Edit: I'm taking your advice though, I'm not too far along and programming it by hand is actually already giving me functionality that the autogenerated code didn't produce. Edit2: I'm glad I took your advice, I've found that you're right, copy and pasting code and doing it by hand is a lot faster and effective than drawing boxes on the screen, plus I'm getting familiar with all these classes, which is a good thing. dealmaster fucked around with this message at 18:57 on Jul 17, 2009 |
# ? Jul 17, 2009 17:05 |