Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

GridBagLayout to create a board

843806Feb 3 2009 — edited Feb 3 2009
Hi all.

I am using a GridBagLayout to create a board of 11x11 squares. These squares will be buttons, and all will be of the same size. But it has to be like a board made of bricks. The first row will be formed by 11 buttons. The first square of the second row has to start in the middle of the first square of the first row. The third row will be as the first row, and the fourth row as the second row...

My intention has been to use a GridBagLayout where the grid were formed by 11x21 squares, and each square will use two cells of width. I was thinking of putting the first button on the (0,0), the second on the (2,0), (4,0) ... (20,0).The first button of the second row on the (1,1), the second button of the second row on the (1,3)... (1,21).

This is what I have used:
import gato.PanelGato;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class ButtonTest {

	private static PanelGato panel;

	public static void main (String[] args) {
		panel = new PanelGato();
		panel.setLayout(new GridBagLayout());
		JFrame frame = new JFrame ();
		createPanel();
		frame.setPreferredSize(new Dimension(800,800));
		frame.add(panel);
		frame.pack();
		frame.setVisible(true);
	}

	public static void createPanel () {
		GridBagConstraints c = new GridBagConstraints();
		for (int i=0; i<11; i++) {
			int modOdd = 0;
			if (i%2==1)
				modOdd = 1;		
			for (int j=0; j<11; j++) {
//The 11 squares of a row are created here. gridy = the number of row, gridx = twice the number of row (+ 1 if it is a even row)
//The gridwidth = 2 because I want the buttons to use two cells.
				c = new GridBagConstraints();
				c.gridy = i;
				c.gridx = 2*j+modOdd;
				c.gridwidth=2;//case B: c.gridwidth=1
				panel.add(new JButton(),c);
			}
		}
	}
}
The result is a simple board, where the second row starts in the same place as the first row, and all the board is a square.
In the case B, where c.gridwidth=1, the result is like a chessboard where the buttons are only the black squares. It is not a "brick board", because the first button of the second row starts where the first one of the first row ends.

Could anyone help me?
Thank you very much for reading it :)

Comments

785636

Hello,

I want to learn more about what is the process to contribute to MySQL team as C++ developer, Thanks.

Hello,

I want to learn more about what is the process to contribute to MySQL team as C++ developer, Thanks.

Hello,

so sorry for the delay in responding.

You first need to sign a Oracle Contribution Agreement (OCA) - http://www.oracle.com/technetwork/community/oca-486395.html in order you to get in the list of Oracle's contributors.

You need to create an account in our bug system: https://bugs.mysql.com/ .

Once those two steps are done, you can contribute either by submitting a bug in our bug system of using the GitHub (please provide your GitHub name when you submit the OCA).

These are the process steps, if you have any technical questions, then please share it and I will help you to get an answer.

thank you,

-Lenka

fareed shah

Contributing code to MySQL, which is an open-source relational database management system, serves several important purposes:

1. **Improving MySQL's Functionality and Performance:**

  • By contributing code, developers can enhance the functionality and performance of MySQL. This can include adding new features, optimizing existing ones, or fixing bugs.

2. **Community Collaboration:**

  • MySQL is developed collaboratively by a community of contributors. Contributing code allows developers to actively participate in this community, share their expertise, and collaborate with other like-minded individuals.

3. **Addressing Issues and Bugs:**

  • Open-source projects often benefit from the diverse skills of contributors who can identify and fix issues or bugs. By contributing code, developers help ensure the stability and reliability of MySQL.

4. **Keeping MySQL Up-to-Date:**

  • Technology evolves rapidly, and MySQL needs to stay current to meet the demands of modern applications. Contributing code helps keep MySQL up-to-date with the latest industry standards, best practices, and technological advancements.

5. **Customization and Specialized Features:**

  • Organizations or individuals with specific needs can contribute code to MySQL to implement custom features or functionalities tailored to their requirements. This flexibility is a key advantage of open-source software.

6. **Quality Assurance:**

  • A large and active community of contributors helps in identifying and fixing issues through rigorous testing and quality assurance processes. This collective effort enhances the overall reliability of MySQL.

7. **Learning and Skill Development:**

  • Contributing to an open-source project like MySQL provides developers with valuable learning opportunities. It allows them to work on real-world projects, understand the intricacies of a complex system, and improve their coding skills.

8. **Building a Reputation:**

  • Actively contributing to a widely used and respected open-source project can enhance a developer's professional reputation. It showcases their skills, commitment, and ability to work collaboratively within a community.

9. **Supporting the Open-Source Ecosystem:**

  • Contributing to MySQL aligns with the principles of the open-source ecosystem. It promotes the sharing of knowledge, code, and resources for the benefit of the broader community.

In summary, contributing code to MySQL is not just about adding features or fixing bugs; it's about actively participating in a community-driven effort to create a robust, efficient, and continually evolving database management system. It's a collaborative process that brings together developers with diverse skills and perspectives to improve and maintain a critical piece of open-source infrastructure. CHECK

1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 3 2009
Added on Feb 3 2009
2 comments
1,381 views