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);
}
}
Button Pascal
Page 1 of 11 Replies - 356 Views - Last Post: 01 May 2009 - 10:09 AM
#1
Button Pascal
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.
Replies To: Button Pascal
#2
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.
try to add frame.validate(); in the last line of the actionPerformed method.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|