Creating a multicolored board - java

I am to create a multicolored board, starting with the first square as black, then blue, red, and yellow, the squares are being filled diagonally and there are no empty colored squares. I know my algorithm is wrong, but I have not a clue as how to fix it.
Currently, my code prints out like this
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
public class Grid extends JPanel {
private static final long serialVersionUID = 1L;
public static final int GRID_COUNT = 8;
private Color[] colors = { Color.black, Color.yellow, Color.red,
Color.blue };
private int colorIndex = 0;
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D graphics = (Graphics2D) g;
graphics.setColor(Color.black);
Dimension size = getSize();
Insets insets = getInsets();
int w = size.width - insets.left - insets.right;
int h = size.height - insets.top - insets.bottom;
int sqrWidth = (int)((double)w / GRID_COUNT);
int sqrHeight = (int)((double)h / GRID_COUNT);
for (int row = 0; row < GRID_COUNT; row++) {
for (int col = 0; col < GRID_COUNT; col++) {
int x = (int) (row * (double) w / GRID_COUNT);
int y = (int) (col * (double) h / GRID_COUNT);
if ((row + col) % 2 == 0) {
int colorIndex = (row + col) % 4;
graphics.fillRect(x, y, sqrWidth, sqrHeight);
graphics.setColor(colors[colorIndex]);
colorIndex = (colorIndex + 1) % colors.length;
}
}
public static void main(String[] args) {
Grid grid = new Grid();
grid.setPreferredSize(new Dimension(400, 400));
JFrame frame = new JFrame("Grid");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(grid);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}

Let's look at the pattern:
Bk Gr Pn Bl
Gr Pn Bl Bk
Pn Bl Bk Gr
Bl Bk Gr Pn
But to make it simpler, let's call Bk 0, Gr 1, Pn 2 and Bl 3 to get:
0 1 2 3
1 2 3 0
2 3 0 1
3 0 1 2
This pattern is easily produced by calculating tile[x][y] = (x + y) % 4 for every tile, and using a lookup table to convert these numbers to colours (Either use an enumeration, or instead of assigning an integer value to the tile use the integer as a look-up in a table of colours and assign the colour to the tile)
If you've never seen it before, % 4 means 'divide by 4 and return the REMAINDER of the division'.

There are two mistake, I saw, first mistake is your pattern, you want to go from black, "then blue, red, and yellow" but you did
private Color[] colors = { Color.black, Color.yellow, Color.red, Color.blue };
change this one
and second mistake is that your program is counting evenly, means it is filling rectangle evenly ,
2 , 4 , 6, 8..
make your program will go on every single rectangle, which is in grey color...

I've run through the code quickly and there are number of little things which seem confusing to me..
Your color calculation is been thrown off because your original code was skipping every second cell...
if ((row + col) % 2 == 0) {
Which meant that when you tried to determine the color, you weren't getting the color you were expecting.
You were also setting the color of the cell within the row loop and not in the column loop, which seems weird to me...
(I added text in to for debugging, feel free to get rid of it)
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class Grid {
private static final long serialVersionUID = 1L;
public static final int GRID_COUNT = 8;
private Color[] colors = {Color.black, Color.yellow, Color.red,
Color.blue};
public static void main(String[] args) {
new Grid();
}
public Grid() {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
JFrame frame = new JFrame("Grid");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new GridPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public class GridPane extends JPanel {
#Override
public Dimension getPreferredSize() {
return new Dimension(200, 200);
}
#Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D graphics = (Graphics2D) g;
graphics.setColor(Color.black);
Dimension size = getSize();
Insets insets = getInsets();
int w = size.width - insets.left - insets.right;
int h = size.height - insets.top - insets.bottom;
FontMetrics fm = graphics.getFontMetrics();
int sqrWidth = (int) ((double) w / GRID_COUNT);
int sqrHeight = (int) ((double) h / GRID_COUNT);
int colorIndex = 0;
for (int row = 0; row < GRID_COUNT; row++) {
for (int col = 0; col < GRID_COUNT; col++) {
int x = (int) (col * sqrWidth);
int y = (int) (row * sqrHeight);
colorIndex = (row + col) % 4;
graphics.setColor(colors[colorIndex]);
graphics.fillRect(x, y, sqrWidth, sqrHeight);
String text = row + "/" + col;
graphics.setColor(Color.WHITE);
graphics.drawString(
text,
x + ((sqrWidth - fm.stringWidth(text)) / 2),
y + ((sqrHeight - fm.getHeight()) / 2) + fm.getAscent());
}
}
}
}
}

Related

Java AWT Graphics Class: Making Rows and Columns of Squares

I'm using the java.awt graphics class, and I'm trying to make rows and squares.
I can't seem to get the layout of the rows correctly.
I'm trying to code 8 rows with 3 columns each. However, I just get 2 rows with 12 columns.
If somebody can help me to create the outcome that I want, that would be greatly appreciated.
Here's my code:
g.setColor(Color.WHITE);
int x = 70;
int y = 80;
int w = 30;
int h = 35;
for(int row = 0; row < 3; row++) {
for(int col = 0; col < 4; col++) {
g.fillRect( x, y, w, h );
g.fillRect( x, y + h + 20, w, h );
x += w + 15;
}
System.out.println();
}
Here's the output: 2 rows, 12 columns of squares
Beware of how you are updating your position information. For example, you should only be updating the x position in the inner loop and resetting to 0 before entering the inner loop, and the y position should only be updated on each new row.
Alternatively, you could calculate the position directly, based on the row/column index and the row/column height, as demonstrated below.
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
JFrame frame = new JFrame();
frame.add(new TestPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public static class TestPane extends JPanel {
private static int COLUMN_COUNT = 3;
private static int ROW_COUNT = 8;
private static int COLUMN_WIDTH = 30;
private static int ROW_HEIGHT = 35;
public TestPane() {
}
#Override
public Dimension getPreferredSize() {
return new Dimension(3 * COLUMN_WIDTH, 8 * ROW_HEIGHT);
}
#Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();
int columnWidth = getWidth() / 3;
int rowHeight = getHeight() / 8;
int x = 0;
int y = 0;
for (int row = 0; row < ROW_COUNT; row++) {
for (int col = 0; col < COLUMN_COUNT ; col++) {
if (col % 2 == 0) {
x = columnWidth * col;
y = rowHeight * row;
g2d.fillRect(x + 2, y + 2, columnWidth - 4, rowHeight - 4);
}
}
}
g2d.dispose();
}
}
}

Java - Hexagon location in grid

Im searching for an algorythem to get the location of a hexagon in a grid.
I found this one but it doesnt seam to work:
for(int i = 0; i < width; i++) {
for(int j = 0; j < height; j++) {
grid[i][j] = new Hexagon(x+(j*((3*Hexagon.S)/2)), y+((j%2)*Hexagon.A)+(2*i*Hexagon.A));
}
}
The output is kind of strange:
output
This is the window-creating class(just a test class):
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Grid extends JPanel {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
int width = 2;
int height = 4;
int x = 100;
int y = 100;
Hexagon[][] grid = new Hexagon[width][height];
JFrame f = new JFrame();
Container cp = f.getContentPane();
for(int i = 0; i < width; i++) {
for(int j = 0; j < height; j++) {
grid[i][j] = new Hexagon(x+(j*((3*Hexagon.S)/2)), y+((j%2)*Hexagon.A)+(2*i*Hexagon.A));
cp.add(grid[i][j]);
}
}
f.setLayout(null);
f.setBounds(100, 100, 300, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
The Hexagon.java class:
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import javax.swing.JButton;
public class Hexagon extends JButton {
public static final int S = 50;
public static final int A = (int) (Math.sqrt(3)*(S/2));
private static final long serialVersionUID = 1L;
private final int x, y;
private final Polygon shape;
public Hexagon(int x, int y) {
this.x = x;
this.y = y;
this.shape = initHexagon();
setSize(2*S, 2*A);
setLocation(x-S, y-A);
setContentAreaFilled(false);
}
private Polygon initHexagon() {
Polygon p = new Polygon();
p.addPoint(x+(S/2), y-A);
p.addPoint(x+S, y);
p.addPoint(x+(S/2), y+A);
p.addPoint(x-(S/2), y+A);
p.addPoint(x-S, y);
p.addPoint(x-(S/2), y-A);
return p;
}
protected void paintComponent(Graphics g) {
g.setColor(Color.BLACK);
g.drawPolygon(this.shape);
}
protected void paintBorder(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.BLACK);
g2.setStroke(new BasicStroke(4));
g2.drawPolygon(this.shape);
}
public boolean contains(int x, int y) {
return this.shape.contains(x, y);
}
}
As i said, this class worked just fine using non-rectangular shapes.
There was no clipping or such.
You've posted your definition of Hexagon too late, so I copy-pasted a modified version of a similar class from my collection of code snippets.
Here is one way to generate a hexagonal grid:
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComponent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.GridLayout;
import java.util.function.*;
public class Hexagons extends JPanel {
private static final long serialVersionUID = 1L;
/** Height of an equilateral triangle with side length = 1 */
private static final double H = Math.sqrt(3) / 2;
static class Hexagon {
final int row;
final int col;
final double sideLength;
public Hexagon(int r, int c, double a) {
this.row = r;
this.col = c;
this.sideLength = a;
}
double getCenterX() {
return 2 * H * sideLength * (col + (row % 2) * 0.5);
}
double getCenterY() {
return 3 * sideLength / 2 * row;
}
void foreachVertex(BiConsumer<Double, Double> f) {
double cx = getCenterX();
double cy = getCenterY();
f.accept(cx + 0, cy + sideLength);
f.accept(cx - H * sideLength, cy + 0.5 * sideLength);
f.accept(cx - H * sideLength, cy - 0.5 * sideLength);
f.accept(cx + 0, cy - sideLength);
f.accept(cx + H * sideLength, cy - 0.5 * sideLength);
f.accept(cx + H * sideLength, cy + 0.5 * sideLength);
}
}
public static void main(String[] args) {
final int width = 50;
final int height = 50;
final Hexagon[][] grid = new Hexagon[height][width];
for(int row = 0; row < height; row++) {
for(int col = 0; col < width; col++) {
grid[row][col] = new Hexagon(row, col, 50);
}
}
JFrame f = new JFrame("Hexagons");
f.getContentPane().setLayout(new GridLayout());
f.getContentPane().add(new JComponent() {
#Override public void paint(Graphics g) {
g.setColor(new Color(0xFF, 0xFF, 0xFF));
g.fillRect(0,0,1000,1000);
g.setColor(new Color(0,0,0));
final int[] xs = new int[6];
final int[] ys = new int[6];
for (Hexagon[] row : grid) {
for (Hexagon h: row) {
final int[] i = {0};
h.foreachVertex((x, y) -> {
xs[i[0]] = (int)((double)x);
ys[i[0]] = (int)((double)y);
i[0]++;
});
g.drawPolygon(xs, ys, 6);
g.drawString(
"(" + h.row + "," + h.col + ")",
(int)(h.getCenterX() - 15),
(int)(h.getCenterY() + 12)
);
}
}
}
});
f.setBounds(0, 0, 500, 500);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
try {
Thread.sleep(100);
} catch (Throwable e) {
} finally {
f.repaint();
}
}
}
It produces the following output:
Sorry for the lack of anti-aliasing. A few hints:
Height H of an equilateral triangle with unit side length is sqrt(3) / 2
The six offsets from the center are (0, +1), (H, +1/2), (H, -1/2), (0, -1), (-H, -1/2), (-H, +1/2), everything times side length.
Distance between rows is 1.5, distance between columns is 2 * H (times scaling constant = side length).
Every odd row is shifted by (0, H) (times scaling constant).
The position of (row,col)-th hexagon is (1.5 * row, 2 * H * (col + 0.5 * (row % 2))) (times constant).
If you want to rotate the hexagons such that two of their sides are horizontal, you have to flip rows and columns.

How to create a colour gradient without Javafx/AWT?

so i have a little Problem and i try to solve it since hours.
I have a BufferedImage and i want to change the colour in a fluent way f.e. from red to white.
My main:
public static void main(String[] args) {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x != width; x++) {
for (int y = 0; y != height; y++) {
image.setRGB(x, y, color12(x, y));
try {
,,,
My method to change the color:
static int color12(int x, int y) {
int size = 100;
if (Math.abs(width / 2 - x) < size / 2 && Math.abs(height / 2 - y) < size / 2)
return new Color(255, 0, 0).getRGB();
else
return new Color(200, 200, 255).getRGB();
}
}
So i played around with the method, but i cant get it done.
My best "solution" was this:
int r = 0 ;
int b = 0;
int g = 0;
for (int i = 1; i < 255; i++)
r++;
else return new Color(r,g,b).getRGB();
Can anyone help me?
I'm not sure how you want the gradient (e.g. horizontal, vertical or diagonal), but here's an example using linear interpolation for a horizontal or vertical gradient.
import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public class ExampleFrame extends JFrame {
private static enum GradientOrientation {
HORIZONTAL, VERTICAL
};
private static BufferedImage createGradientImg(int width, int height, Color startColor, Color endColor, GradientOrientation o) {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int pos = o.equals(GradientOrientation.HORIZONTAL) ? x : y;
int size = o.equals(GradientOrientation.HORIZONTAL) ? width : height;
image.setRGB(x, y, getGradientRGB(startColor, endColor, pos, size));
}
}
return image;
}
private static int getGradientRGB(Color startColor, Color endColor, int pos, int size) {
double perc = (double) pos / size;
int newRed = (int) (endColor.getRed() * perc + startColor.getRed() * (1 - perc));
int newGreen = (int) (endColor.getGreen() * perc + startColor.getGreen() * (1 - perc));
int newBlue = (int) (endColor.getBlue() * perc + startColor.getBlue() * (1 - perc));
return new Color(newRed, newGreen, newBlue).getRGB();
}
public void createAndShow() {
BufferedImage img1 = createGradientImg(200, 100, Color.RED,
Color.WHITE, GradientOrientation.HORIZONTAL);
BufferedImage img2 = createGradientImg(200, 100, Color.BLUE,
Color.YELLOW, GradientOrientation.HORIZONTAL);
BufferedImage img3 = createGradientImg(200, 100, Color.WHITE,
Color.YELLOW, GradientOrientation.VERTICAL);
BufferedImage img4 = createGradientImg(200, 100, Color.BLACK,
Color.WHITE, GradientOrientation.VERTICAL);
BoxLayout layout = new BoxLayout(getContentPane(), BoxLayout.Y_AXIS);
getContentPane().setLayout(layout);
getContentPane().add(new JLabel(new ImageIcon(img1)));
getContentPane().add(new JLabel(new ImageIcon(img2)));
getContentPane().add(new JLabel(new ImageIcon(img3)));
getContentPane().add(new JLabel(new ImageIcon(img4)));
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
ExampleFrame ef = new ExampleFrame();
ef.createAndShow();
}
});
}
}

How to draw a wall in paint method based on user input

I fairly new to programming and I have decided to take an intro to java class. I have an assignment where I have to create a wall using a for loop that changes height of the wall based on user input. I think I got most of the code right but I can't seem to connect the user input with the for loop. Any help would be appreciated.
//Package List
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
public class Wall extends JApplet implements ActionListener{
//Component declaration
JLabel directions;
JTextField input = new JTextField( 10 );
private JButton go;
//Variable declaration
int userinput;
//Method declaration
public void init()
{
getContentPane().setBackground(new Color (128, 128, 128));//Changes backround of JApplet to black
//Set JButton and JLabel
setLayout (new FlowLayout( ));
directions = new JLabel("Enter in any number between 1 and 20 and then press Enter on your keyboard.");
go = new JButton( "Go!" );
go.setBackground( Color.GREEN );
go.setFocusPainted( false );
go.addActionListener( this );
add (directions );
add (input);
add( go );
}
public void actionPerformed( ActionEvent ae )
{
String text = input.getText();
userinput = Integer.parseInt( text );
repaint();
}
//Method declaration
public void paint(Graphics g)
{
super.paint(g);
int startX = 50;
int startY = 650;
int width = 50;
int height = 20;
int spacing = 2;
int xOffset = 0;
for (int row = 0; row < userinput; row++) {
int y = startY + (row * ( height + spacing));
if ( row % 2 == 0) {
xOffset = width / 2;
} else {
xOffset = 0;
}
for (int col = 0; col < 8; col++) {
int x = xOffset + (startX + (col * (width + spacing)));
System.out.println(x + "x" + y);
g.setColor( Color.RED );
g.fillRect( x, y, width, height);
}
}
}
}
Basically, your code works, but your starty is to large and seems to be painting off the screen.
Generally, you should avoid overriding paint of top level containers like JApplet (why are using applets?!) and instead, use a component like JPanel instead.
A few reasons for this, but the one you will run into is that paint can paint over the child components, BUT, because of the way painting works, those child components, when updated, can paint over what you've painted ... which altogether, is just weird for the user.
Instead, separate you code into logic units, each unit should be responsible for a single unit (of logic) work
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Wall extends JApplet implements ActionListener {
//Component declaration
JLabel directions;
JTextField input = new JTextField(10);
private JButton go;
private WallPanel wallPanel;
//Method declaration
public void init() {
getContentPane().setBackground(new Color(128, 128, 128));//Changes backround of JApplet to black
//Set JButton and JLabel
setLayout(new BorderLayout());
JPanel controls = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
directions = new JLabel("Enter in any number between 1 and 20 and then press Enter on your keyboard.");
go = new JButton("Go!");
go.setBackground(Color.GREEN);
go.setFocusPainted(false);
go.addActionListener(this);
controls.add(directions, gbc);
controls.add(input, gbc);
controls.add(go, gbc);
wallPanel = new WallPanel();
add(controls, BorderLayout.NORTH);
add(wallPanel);
}
public void actionPerformed(ActionEvent ae) {
String text = input.getText();
wallPanel.setRowCount(Integer.parseInt(text));
repaint();
}
public class WallPanel extends JPanel {
private int rowCount;
public void setRowCount(int rowCount) {
this.rowCount = rowCount;
repaint();
}
public int getRowCount() {
return rowCount;
}
#Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int startX = 50;
int startY = 0;
int width = 50;
int height = 20;
int spacing = 2;
int xOffset = 0;
for (int row = 0; row < getRowCount(); row++) {
int y = startY + (row * (height + spacing));
if (row % 2 == 0) {
xOffset = width / 2;
} else {
xOffset = 0;
}
for (int col = 0; col < 8; col++) {
int x = xOffset + (startX + (col * (width + spacing)));
g.setColor(Color.RED);
g.fillRect(x, y, width, height);
}
}
}
}
}
So, basically, all I've done here is move the "wall painting" to it's own component/class and provided a simple setter (and getter) for changing the number of rows

How can I create a JButton with border shadow in Swing

How can I create a JButton like this with inner shadow in Swing?
I wan to create JButton with different Color of border, like top and left border color should be black and right and bottom border color should be of white color.
But all together, I want inner shadow of dark gray color in top and left side like above image.
First I thought you can just achieve this with a simple BevelBorder, but unfortunately you can't set the border's thickness comfortably... So I had to basically make a customized Border. You can customize it more if you don't like the style of my button in the paintBorder method, but you have to know how to work with Graphics. Here is what I've got:
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.Border;
/**
*
*/
public class MyBorder implements Border {
private int thickness_ = 4;
private Color white = Color.WHITE;
private Color gray = Color.GRAY;
private Color black = Color.BLACK;
public static void main(String[] args) {
JFrame frm = new JFrame("Border Test");
frm.setLayout(new FlowLayout());
JButton btn = new JButton("Button");
MyBorder border = new MyBorder();
btn.setBorder(border);
btn.setFocusPainted(false);
btn.setPreferredSize(new Dimension(60,30));
btn.setBackground(Color.LIGHT_GRAY);
frm.add(btn);
frm.setSize(200,200);
frm.setVisible(true);
}
public void paintBorder(Component c, Graphics g, int x, int y, int width,
int height) {
Color oldColor = g.getColor();
int i;
for (i = 0; i < thickness_; i++) {
g.setColor(white);
g.drawRect(x + i, y + i, width - i - i - 1, height - i - i - 1); //White Rectangle
}
for (i = 0; i < thickness_/2; i++) {
g.setColor(black);
g.drawLine(x + i, y + i, (width - x) - (i * 2), y + i); //Top Outer Edge
g.drawLine(x + i, y + i, x + i, (height - y) - (i * 2)); //Left Outer Edge
}
for (i = thickness_/2; i < thickness_; i++) {
g.setColor(gray);
g.drawLine(x + i, y + i, (width - x) - (i * 2), y + i); //Top Inner Edge
g.drawLine(x + i, y + i, x + i, (height - y) - (i * 2)); //Left Inner Edge
}
g.setColor(oldColor);
}
public int getThickness() {
return thickness_;
}
public void setThickness(int i) {
thickness_ = i;
}
public boolean isBorderOpaque() {
return true;
}
public Insets getBorderInsets(Component c) {
return new Insets(thickness_, thickness_, thickness_, thickness_);
}
}

Categories

Resources