Gulshan Singh

Ranch Hand
+ Follow
since Apr 22, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gulshan Singh

The relevant code is:


All variables used have been initialized; that's not the problem.
This test gives me a null pointer exception at the first verify line:


But this test works:


Why does the second test work?
9 years ago

Pranav Raulkar wrote:Hi, Gulshan. Do all the activities have the same UI? If yes, you don't need to create 100 xml files.


They're similar. For example, one may contain one text view and one image, while the other will contain 2 text views and 2 images. So if the best practice is to do it programmatically, I could put 3 blank text views and 3 blank images and only fill in the ones I needed programmatically. Anyway, if I do implement the 100 xml files, which actually won't be anymore work than doing it programmatically as I would have to type out the strings and image paths anyway, the application will be a few megabytes, which isn't good but I guess it will work.

Thanks.
9 years ago
In the layout directory in the res folder can I make sub folders and access layouts from there?

And on a completely unrelated note, when editing xml layouts using the graphical interface, properties are added inline. Is there a way to allow properties to be added in a newline?
9 years ago
In my application there is an activity which only contains textviews and images and there are back and forward buttons, so the user can switch between each screen using these buttons and the android return key changes the screen to the last activity. Now for each different page that the user can change to in this activity should I make a new xml layout? If I take this approach there will be atleast 100 xml layouts... Instead should I programmatically implement the view or is there a better option?
9 years ago
Hi, I'm new to android development. I have a screen with a bunch of buttons aligned vertically. They don't all fit on the screen so they squished on the bottom. How do I make it so that each is the same size and instead of fitting them all on one screen I can just scroll down?
9 years ago
I need to place a label in my application, but I can't get it to work. The netbeans gui builder used a grouplayout to place my other components, but because I was also using drawImage(), the components weren't placed exactly where they showed up in the builder. That was ok, but now I have a label that needs to be placed at an exact coordinate, so I'm doing it programmatically. They are the labels called fr, fl, and f2 in the code posted below. Can someone tell me or show me how to add at least one of these labels to the display? I've tried a few methods but no matter what I do nothing shows up, so I just got rid of them. I've marked where the placement code should go in DisplayCanvas by the comment /*LABEL PLACEMENT CODE GOES HERE*/.

LensSimulation: http://gsingh2011.pastebin.com/mPs5gBmd
DisplayCanvas: http://gsingh2011.pastebin.com/de4Gxp9d
9 years ago
Ok, when would you use a BufferedImage instead of just an Image?
9 years ago

Rob Prime wrote:You've modified that auto-created class manually, didn't you?
1) initComponents creates your GUI but it isn't called anywhere.
2) that method is missing the calls that actually add (hint: that's a method name) the text field and label to the panel.



Wow, that was dumb. Yup, I modified it and accidentally deleted that part. Thanks, it works now.
9 years ago
I'm writing a simulation for thin lenses and their magnification properties. After I completed the basics of the simulation, I used the GUI Builder of Netbeans 6.9.1 to put in a JLabel and JTextField so the user can set the focal length of the lens (if you don't get the physics, don't worry about it. That's not the issue.) So Netbeans generated the code, but it doesn't show up on the screen. Here are my two classes:

LensSimulation - http://gsingh2011.pastebin.com/Sda2gMB5
DisplayCanvas - http://gsingh2011.pastebin.com/Y3v4TXbp

Why aren't the label and textfield showing up? Do I need to make a new panel?
9 years ago
I created a class that extends JFrame in Netbeans 6.9.1. I placed all of the drawings I needed in the source code, but I wanted to put in a label using the gui builder. The only way I could access the gui builder however, was by making a new jframe file. Is there anyway to edit an existing class that extends jframe? I guess I can just copy and paste my code into a jframe form created by netbeans, but that's annoying and I want to know how to use netbeans.
I'm looking at the code here which let's you drag an image around the screen:
http://www.java2s.com/Code/Java/2D-Graphics-GUI/Imagewithmousedragandmoveevent.htm

Why did they do this:

Why did they have to go through the trouble of making a bufferedimage and then converting it to a graphic and then drawing the image? Why not just instantiate a new Graphic2D object and use that to draw the image?
9 years ago
Thanks for moving it.. like I said, I didn't know if it was easy or hard. I looked at that post, but it wasn't very descriptive about how to do it... I just some example code or atleast give me some terms to search or some links. Thanks.
11 years ago
I don't know if this is a beginner or intermediate question, but I'm hoping someone can answer it here. I want to make an app that will run in the background and still be able to capture my keypresses. My end goal is to kind of make some shortcut commands on my computer, but its actually more for knowing how to do it... Running in the background probably shouldn't be that hard, but will it still be able to capture keypresses when other windows are in focus? And how would I capture the keypresses without implementing Swing and making a GUI? Any help would be appreciated.
11 years ago
I have a text field, and I want to check for the enter key so I can perform an action. I tried a keylistener and then checking to see if the key was the enter key, but that didn't work... I don't know what else to try.
11 years ago
Ok, I actually might do that instead. Thanks.
11 years ago