1 Replies - 397 Views - Last Post: 01 May 2009 - 10:09 AM Rate Topic: -----

#1 rishabhsharma  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 342
  • Joined: 26-March 09

Button Pascal

Post icon  Posted 01 May 2009 - 08:47 AM

I have a snippet which shows Pascal Triangle in the form of Buttons(Triangle in the form of Buttons). Al-right it is working well but when I click number of rows from the JComboBox it doesn't show immediate reaction but when I minimise it and again maximise it shows the result correctly. I want that the result should be displayed without minimizing and maximizing it again.

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

public class PascalCombo extends JFrame implements ActionListener
	{
		PascalCombo()
			{
				this.setTitle("Pascal");
				this.setSize(800,800);
				this.setLayout(new GridBagLayout());
				
				row = new JComboBox(new String[] {"5", "8", "12", "15"});
				row.addActionListener(this);
				panel = new JPanel();
				panel.add(row);
				this.add(panel, new GBC(0,0));
			}
		public void actionPerformed(ActionEvent event)  
			{   
				JFrame frame = new JFrame();
				frame = this;
				int rows = Integer.parseInt((String)row.getSelectedItem());
				grid = new int[rows][];
						
				for(int i = 0; i < rows; i ++ )
					 {
						grid[i] = new int[i+1];
						grid[i][0] = 1;
						grid[i][i] = 1;
						
							 for ( int j = 1; j < i; j ++ )
								 {
									 grid[i][j]=grid[i-1][j]+grid[i-1][j-1];
								 }
					   }  
				 for (int i=0; i < grid.length; i++) 
					   {   
						   pane = new JPanel();
						   for (int j=0; j < grid[i].length; j++) 
								{
									 pane.add(new JButton(new Integer(grid[i][j]).toString()));
								}
						   frame.add(pane,new GBC(1,i));
					   }
				}
		
	   JComboBox row;
	   int grid[][];
	   JPanel pane, panel;
	   public static void main(String[] args)
			{
				new PascalCombo().setVisible(true);
			}
	 }



Is This A Good Question/Topic? 0
  • +

Replies To: Button Pascal

#2 tivrfoa  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 98
  • Joined: 25-January 09

Re: Button Pascal

Posted 01 May 2009 - 10:09 AM

put here the GBC class!!!!!

try to add frame.validate(); in the last line of the actionPerformed method.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1