Write a GUI application that prompts the user for a number between 1 and 5. Be sure to include error checking so that the program continues to prompt the user for a number until the user's entry is between 1 and 5, inclusive.

Once a valid number is entered, the program should display a grid of horizontal and vertical lines inside the frame.
These lines should be drawn such that:

• The lines create x number of horizontal and x number of vertical boxes, where x is the number entered by the user.

• Each box should be 100 pixels by 100 pixels.

• The grid is spaced inside the frame such that it is perfectly centered both horizontally and vertically, with a 10-pixel border between the edge of the frame and the grid.

I cannot figure out how to make a border with the gridlayout. Please help!

Have you decided what makes the grid, JButtons, JPanels, etc.?

If you use a JPanel as a container for the grid made up of buttons, or other panels, you can use the BevelBorder to make borders by adding it onto the panel.

and it is not difficult to use. For a JPanel named p, you can do this with a single statement:

p.setBorder(new javax.swing.border.BevelBorder(1));

Read up the API for more details:
javax.swing.border.BevelBorder

Write a GUI application that prompts the user for a number between 1 and 5. Be sure to include error checking so that the program continues to prompt the user for a number until the user's entry is between 1 and 5, inclusive.

Once a valid number is entered, the program should display a grid of horizontal and vertical lines inside the frame.
These lines should be drawn such that:

• The lines create x number of horizontal and x number of vertical boxes, where x is the number entered by the user.

• Each box should be 100 pixels by 100 pixels.

• The grid is spaced inside the frame such that it is perfectly centered both horizontally and vertically, with a 10-pixel border between the edge of the frame and the grid.

I cannot figure out how to make a border with the gridlayout. Please help!

I cannot figure out how to make a border with the gridlayout. Please help!

Write a GUI application that prompts the user for a number between 1 and 5. Be sure to include error checking so that the program continues to prompt the user for a number until the user's entry is between 1 and 5, inclusive.

Once a valid number is entered, the program should display a grid of horizontal and vertical lines inside the frame.
These lines should be drawn such that:

• The lines create x number of horizontal and x number of vertical boxes, where x is the number entered by the user.

• Each box should be 100 pixels by 100 pixels.

• The grid is spaced inside the frame such that it is perfectly centered both horizontally and vertically, with a 10-pixel border between the edge of the frame and the grid

Each box should be 100 pixels by 100 pixels.

• The grid is spaced inside the frame such that it is perfectly centered both horizontally and vertically, with a 10-pixel border between the edge of the frame and the grid

Write me java code for a GUI application that prompts the user for a number between 1 and 5. Be sure to include error checking so that the program continues to prompt the user for a number until the user's entry is between 1 and 5, inclusive.

Once a valid number is entered, the program should display a grid of horizontal and vertical lines inside the frame.
These lines should be drawn such that:

• The lines create x number of horizontal and x number of vertical boxes, where x is the number entered by the user.

• Each box should be 100 pixels by 100 pixels.

• The grid is spaced inside the frame such that it is perfectly centered both horizontally and vertically, with a 10-pixel border between the edge of the frame and the grid.

I cannot figure out how to make a border with the gridlayout. Please help!

Java - MathMate, Tuesday, December 15, 2009 at 2:45pm
Have you decided what makes the grid, JButtons, JPanels, etc.?

If you use a JPanel as a container for the grid made up of buttons, or other panels, you can use the BevelBorder to make borders by adding it onto the panel.

and it is not difficult to use. For a JPanel named p, you can do this with a single statement:

p.setBorder(new javax.swing.border.BevelBorder(1));

Read up the API for more details:
javax.swing.border.BevelBorder

Java - jeam, Tuesday, July 13, 2010 at 3:36pm

Write a GUI application that prompts the user for a number between 1 and 5. Be sure to include error checking so that the program continues to prompt the user for a number until the user's entry is between 1 and 5, inclusive.

Once a valid number is entered, the program should display a grid of horizontal and vertical lines inside the frame.
These lines should be drawn such that:

• The lines create x number of horizontal and x number of vertical boxes, where x is the number entered by the user.

• Each box should be 100 pixels by 100 pixels.

• The grid is spaced inside the frame such that it is perfectly centered both horizontally and vertically, with a 10-pixel border between the edge of the frame and the grid.

I cannot figure out how to make a border with the gridlayout. Please help!


Java - jeam, Tuesday, July 13, 2010 at 4:06pm
I cannot figure out how to make a border with the gridlayout. Please help!


Java - jeam, Thursday, July 15, 2010 at 12:45am
Write a GUI application that prompts the user for a number between 1 and 5. Be sure to include error checking so that the program continues to prompt the user for a number until the user's entry is between 1 and 5, inclusive.

Once a valid number is entered, the program should display a grid of horizontal and vertical lines inside the frame.
These lines should be drawn such that:

• The lines create x number of horizontal and x number of vertical boxes, where x is the number entered by the user.

• Each box should be 100 pixels by 100 pixels.

• The grid is spaced inside the frame such that it is perfectly centered both horizontally and vertically, with a 10-pixel border between the edge of the frame and the grid

Java - jeam, Thursday, July 15, 2010 at 12:36pm
Each box should be 100 pixels by 100 pixels.

• The grid is spaced inside the frame such that it is perfectly centered both horizontally and vertically, with a 10-pixel border between the edge of the frame and the grid

To create a GUI application with a grid layout and include a border around the grid, you would typically use a combination of layout managers such as BorderLayout and GridLayout. Here's an outline of how you can achieve this:

1. Create a JFrame object to serve as the main window of your application:

```java
JFrame frame = new JFrame("Grid Application");
```

2. Use BorderLayout to set the layout manager for the frame:

```java
frame.setLayout(new BorderLayout());
```

3. Create a JPanel to hold the grid:

```java
JPanel gridPanel = new JPanel(new GridLayout(x, x));
```
Note: Replace 'x' with the number entered by the user.

4. Set an empty border around the grid panel to create the desired spacing:

```java
gridPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
```

5. Create a loop to generate the horizontal and vertical lines as individual components and add them to the grid panel:

```java
for (int i = 0; i < x; i++) {
gridPanel.add(new JSeparator(SwingConstants.HORIZONTAL));
gridPanel.add(new JSeparator(SwingConstants.VERTICAL));
}
```

6. Add the grid panel to the center of the frame:

```java
frame.add(gridPanel, BorderLayout.CENTER);
```

7. Set the size and visibility of the frame, and handle any necessary closing operations:

```java
frame.setSize(600, 600); // Set an appropriate size
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Specify the desired close operation
frame.setVisible(true); // Make the frame visible
```

Putting it all together, here's the complete example code:

```java
import javax.swing.*;
import java.awt.*;

public class GridApplication {
public static void main(String[] args) {
int x = getInputInRange(1, 5);

JFrame frame = new JFrame("Grid Application");
frame.setLayout(new BorderLayout());

JPanel gridPanel = new JPanel(new GridLayout(x, x));
gridPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

for (int i = 0; i < x; i++) {
gridPanel.add(new JSeparator(SwingConstants.HORIZONTAL));
gridPanel.add(new JSeparator(SwingConstants.VERTICAL));
}

frame.add(gridPanel, BorderLayout.CENTER);

frame.setSize(600, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

private static int getInputInRange(int min, int max) {
int input = -1;
String inputString;
while (input < min || input > max) {
inputString = JOptionPane.showInputDialog(
"Please enter a number between " + min + " and " + max);
try {
input = Integer.parseInt(inputString);
} catch (NumberFormatException e) {
// Invalid input, loop continues
}
}
return input;
}
}
```

In this example, the `getInputInRange()` method handles the error checking to ensure the user's input is within the specified range.