estoy trabado en un proyecto con un juego de bingo en java pero kiere ke tenga dos cuadros de cuadricula péro no me sale bien(el cuadro me sale con gridlayout o con el ke vi en esta pagina)
le envio la imagen de como podria ser
y el documento del proyecto si nos podrian ayudar
entedi el de bingo ke pusieron pero como se acomodaria para ke no ocupe toda la ventana?
PD: la prefe no puso este proyecto pero no puso nigun ejemplo y e tenido ke invetigar junto con un amigo pero estamos ya bien cerrados
envio el codigo de lo ke hivcimos para ke vean ke estamos bien cerrados ya
imagen de lo ke creo ke deveria kedar
http://imageranch.com/files/1099762918_bingo1.jpgPD :no es en javasrcipt no lo domino , es en java normal de graficos
gracias de antemano
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyGame extends Frame {
/*******************************************/
private MenuBar menuBar1;
private Menu menu1;
private MenuItem menuNewGame;
private MenuItem menuExit;
private MenuItem menuAbout;
private static JButton button[];
private String sign = "X";
private static String status[] = new String[ 30 ];
private static String theWinner = "";
private boolean available = false;
private Menu menu2;
private MenuItem menuBoys;
private MenuItem menuGirls;
public MyGame() {
super( "Bingo" );
initComponents();
}
private void initComponents() {
setLayout( new GridLayout( 5, 5, 1, 1 ) );
setSize(500,500);
menuBar1 = new MenuBar();
menu1 = new Menu();
menuNewGame = new MenuItem();
menuExit = new MenuItem();
menuAbout = new MenuItem();
menu1.setLabel("File");
menuNewGame.setLabel("New Game");
menuNewGame.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
newGameActionPerformed(evt);
}
});
menu1.add(menuNewGame);
menuExit.setLabel("Exit");
menuExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
exitActionPerformed(evt);
}
});
menu1.add(menuExit);
menuAbout.setLabel("About...");
menuAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
aboutActionPerformed(evt);
}
});
menu1.add(menuAbout);
menuBar1.add(menu1);
menu2 = new Menu();
menuBoys= new MenuItem();
menu2.setLabel("Imagen");
menuBoys.setLabel("Boys");
menuBoys.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
boysActionPerformed(evt);
}
}); menu2.add(menuBoys);
menuGirls= new MenuItem();
menu2.setLabel("Imagen");
menuGirls.setLabel("Girls");
menuGirls.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
girlsActionPerformed(evt);
}
}); menu2.add(menuGirls);
menuBar1.add(menu2);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
exitForm(evt);
}
});
setMenuBar(menuBar1);
setVisible(true);
/*************************************/
button = new JButton[ 26 ];
for ( int i = 1; i < 26; i++ ) {
button[ i ] = new JButton();
button[ i ].setFocusPainted( false );
button[ i ].setActionCommand( Integer.toString( i ) );
button[ i ].setFont( new Font( "Dialog", 0, 48 ) );
button[ i ].setPreferredSize( new Dimension( 100, 100 ) );
button[ i ].setToolTipText( "Click to make your move" );
button[ i ].addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent evt ) {
buttonAction( evt.getActionCommand() ); }
} );
add( button[ i ] );
}//end of for
pack();
}//end of init
private void aboutActionPerformed(ActionEvent evt) {
JOptionPane.showMessageDialog( MyGame.this, "This simple game is created by \nMLavrov. \nI hope you will enjoy it!",
"Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE );
}
/*************************************************************/
private void boysActionPerformed(ActionEvent evt) {
JOptionPane.showMessageDialog( MyGame.this, "Imagen","boys", JOptionPane.INFORMATION_MESSAGE );
}
private void girlsActionPerformed(ActionEvent evt) {
JOptionPane.showMessageDialog( MyGame.this, "Imagen_2","girls", JOptionPane.INFORMATION_MESSAGE );
}
/********************************************************************/
private void exitActionPerformed(ActionEvent evt) {
System.exit( 0 );
}
private void newGameActionPerformed(ActionEvent evt) {
setNewGame();
}
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit( 0 );
}
public static void main( String args[] ) {
new MyGame().show();
setNewGame();
}
private void buttonAction( String btn ) {
int index = Integer.parseInt( btn );
if ( button[ index ].getText() == "" ) {
button[ index ].setText( sign );
status[ index ] = sign;
checkGameStatus();
nextMove();
}//end of if
else
JOptionPane.showMessageDialog( MyGame.this,
"This square is already occupied, \nplease try another one.",
"Oops...", JOptionPane.ERROR_MESSAGE );
}//end of buttonAction()
private void nextMove() {
if ( button[ 5 ].getText() == "" ){
button[ 5 ].setText( "O" );
status[ 5 ] = "O";
}//end of if
else {
int move = randomMove();
if ( button[ move ].getText() != "" )
nextMove();
else {
button[ move ].setText( "O" );
status[ move ] = "O";
}//end of else
}//end of else
checkGameStatus();
}//end of nextMove()
private int randomMove() {
int attempt = 0;
if ( available ) {
attempt = ( 1 + ( int ) ( Math.random() * 9 ) ); // any number from 0 to 9
}//end if
return attempt;
}//end of rendomMove()
public static void setNewGame() {
for ( int j = 1; j < 10; j++ ) {
button[ j ].setText( "" );
status[ j ] = "";
}//end of for
theWinner = "";
}//end of setNewGame()
private void checkGameStatus() {
//check top horizontal row
if ( ( status[ 1 ] != "" ) && ( status[ 1 ] == status [ 2 ]
&& status[ 2 ] == status[ 3 ] ) ){
theWinner = status[ 1 ];
gameStop( theWinner );
}
//check middle horizontal row
if ( ( status[ 4 ] != "" ) && ( status[ 4 ] == status [ 5 ]
&& status[ 5 ] == status[ 6 ] ) ){
theWinner = status[ 4 ];
gameStop( theWinner );
}
//check bottom horizontal row
if ( ( status[ 7 ] != "" ) && ( status[ 7 ] == status [ 8 ]
&& status[ 8 ] == status[ 9 ] ) ){
theWinner = status[ 7 ];
gameStop( theWinner );
}
//check left vertikal column
if ( ( status[ 1 ] != "" ) && ( status[ 1 ] == status [ 4 ]
&& status[ 4 ] == status[ 7 ] ) ){
theWinner = status[ 1 ];
gameStop( theWinner );
}
//check middle vertikal
if ( ( status[ 2 ] != "" ) && ( status[ 2 ] == status [ 5 ]
&& status[ 5 ] == status[ 8 ] ) ){
theWinner = status[ 2 ];
gameStop( theWinner );
}
//check right vertikal
if ( ( status[ 3 ] != "" ) && ( status[ 3 ] == status [ 6 ]
&& status[ 6 ] == status[ 9 ] ) ){
theWinner = status[ 3 ];
gameStop( theWinner );
}
//check diagonal 1
if ( ( status[ 1 ] != "" ) && ( status[ 1 ] == status [ 5 ]
&& status[ 5 ] == status[ 9 ] ) ){
theWinner = status[ 1 ];
gameStop( theWinner );
}
//check diagonal 2
if ( ( status[ 3 ] != "" ) && ( status[ 3 ] == status [ 5 ]
&& status[ 5 ] == status[ 7 ] ) ){
theWinner = status[ 3 ];
gameStop( theWinner );
}
//check for available squares
found: {
for ( int a = 1; a < 10; a++ ) {
if ( status[ a ] == "" ){
available = true;
break found;
}
else
available = false;
}//end of for
}//end of found block
if ( !available )
gameStop( "tie" );
}//end of checkGame()
private void gameStop( String win ) {
if ( win == "tie" ){
JOptionPane.showMessageDialog( MyGame.this, "It's a tie, baby!!! \nLets play again!",
"That was a game...", JOptionPane.INFORMATION_MESSAGE );
setNewGame();
}
else {
String output = "The player \"" + win + "\" has won!!! \nWould you like to play again?";
int choice = JOptionPane.showConfirmDialog( MyGame.this, output,
"Congratulations!", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE );
if ( choice == 0 )
setNewGame();
else
System.exit( 0 );
}//end of else
}//end of gameStop()*/
}//end of class