Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Joe Pawlak

Greenhorn
+ Follow
since Dec 02, 2003
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 Joe Pawlak

Thanks, Joe.
validate() worked and I've never heard of CardLayout. I'll have to give that a try.
Thanks again.
16 years ago
I have an applet that contains JTextFields, JButtons, JLabels, etc. When one of the buttons is pressed I use removeAll() to clear the applet so I can add different components to the screen. The problem is that the applet does not refresh. Everything clears, but the new components do not show up until the appletviewer screen is resized, or the an event happens in the browser window. For example, if I were to print the page, then it would refreh.
Is there a way to refresh this without resizing the window?
Thanks.
16 years ago
I would like to create a game that is networked. It does not need to be complicated, 2 players is fine. It probably be best if the users did not have to enter their IP's or any other information, just connect to the page and when there are enough players, play.
If anyone can point me in the right direction to get me started, that would be greatly appreciated.
Thanks.
16 years ago
So far I have this:

But the columns of Radio Buttons are too far apart, and are causing the questions to be cut off with an ...
The JPanel can be a little wider, but I don't want to make it as wide as it has to be right now in order for the entire question to be shown.
Thanks.
16 years ago
Craig, that works, but is there any way to decrease the distance between the two columns of the Radio Buttons? I tried making the panel smaller and took out the hgaps and vgaps, but those didn't seem to work.
16 years ago
I tried making two separate arrays of JRadioButtons and then putting those into ButtonGroups, but that is not working.
16 years ago
Better yet, I have this code that will do what I need it to once I change the code a bit. But the problem is, the code allows the user to select as many radio buttons in a column as (s)he wants. But what I need is the user to select one option from each column.
I tried to change the code, but it didn't quite work. So if anyone could help it would be greatly appreciated, thanks.
CODE:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ScrollDemo extends JFrame {
JScrollPane scrollpane;
public ScrollDemo() {
super("JScrollPane Demonstration");
setSize(300, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
init();
setVisible(true);
}
public void init() {
JRadioButton form[][] = new JRadioButton[13][3];
String counts[] = { "", "1", "2" };
String categories[] = { "Household", "Office", "Extended Family",
"Company (US)", "Company (World)", "Team",
"Will", "Birthday Card List", "High School",
"Country", "Continent", "Planet" };
JPanel p = new JPanel();
p.setSize(600, 400);
p.setLayout(new GridLayout(13, 3, 10, 0));
for (int row = 0; row < 13; row++) {
ButtonGroup bg = new ButtonGroup();
for (int col = 0; col < 3; col++) {
if (row == 0) {
p.add(new JLabel(counts[col]));
}
else {
if (col == 0) {
p.add(new JLabel(categories[row - 1]));
}
else {
form[row - 1][col - 1] = new JRadioButton();
bg.add(form[row -1][col - 1]);
p.add(form[row -1][col - 1]);
}
}
}
}
scrollpane = new JScrollPane(p);
getContentPane().add(scrollpane, BorderLayout.CENTER);
}
public static void main(String args[]) {
new ScrollDemo();
}
}
16 years ago
Also, besides just being able to select 2, they should still be able to select 1 instead of 2.
16 years ago
I know there is a way to only allow one JCheckBox to be selected, but is there a way to allow only 2 to be selected?
Thanks.
16 years ago
Thanks Gregg.
It looks like it should work.
16 years ago
I have to write a Java app that takes data and turns it into a graph. I know how to get the data, but how would I draw the graph?
Would I use the Graphics class like in an applet?
Thanks.
16 years ago
Does anyone know if its possible to make a GUI frontend for a C++ console app? The app is all ANSI, no third-party includes.
If it is possible, could someone please point me in the right direction?
Thanks.
16 years ago
I believe you would use the F: drive instead of the C: drive when mapping PC #2's classpath
But what I'm trying to do is get the absolute file path, so I can read/write to a folder that is outside of the JAR. I tried using relative file paths when my program wasn't in a JAR, and that did not always work, so now I need a different way to find out the absolute file path when my program is inside of a JAR.
Thanks.
16 years ago
Exception in thread "main" java.lang.NullPointerException
is the error I get. Then, it shows the files/lines where that exception is occuring. At each of those lines is where I call a method that is supposed to find the path where the program is run from. For example, if the program is at C:\java\main.class that method will return C:\java\
This method works when the application is not packaged in a JAR, but as soon as I package it, I get those exceptions.
Is there some other way to figure this out when the applicaton is inside a JAR? I remember seeing somewhere that I should use getResource if it's packaged inside a JAR.
Any help would be appreciated.
Thanks.
16 years ago