import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;
public class Project2 extends JApplet implements ActionListener
{
private static final int LABEL_SIZE = 19;
private static final int BUTTON_SIZE = 50;
//DATA DICTIONARY
private JPanel centerPanel; //panel that will hold the periodic table
private BorderLayout centerLayout; //place the periodic table in the center of the screen
private JLabel labelArray[]; //array that will hold the labels in the periodic table
private JButton buttonArray[]; //array that will hold the buttons for each element
private GridLayout periodicLayout; //layout to organize the multiple element buttons
@Override
public void init() //Set up the GUI (periodic table)
{
//Initialize the layout that will be used for the periodic tbale (10 rows, 19 columns)
periodicLayout = new GridLayout(10, 19 , 3, 3);
setLayout(periodicLayout);
//Initilize the array that will hold all the buttons
buttonArray = new JButton[BUTTON_SIZE];
//Initilize the array that will hold all the buttons
labelArray = new JLabel[LABEL_SIZE];
//populate the buttonArray
labelArray[0] = new JLabel(" "); labelArray[1] = new JLabel("1"); labelArray[2] = new JLabel("2");
labelArray[3] = new JLabel("3"); labelArray[4] = new JLabel("4"); labelArray[5] = new JLabel("5");
labelArray[6] = new JLabel("6"); labelArray[7] = new JLabel("7"); labelArray[8] = new JLabel("8");
labelArray[9] = new JLabel("9"); labelArray[10] = new JLabel("10");
labelArray[11] = new JLabel("11"); labelArray[12] = new JLabel("12");
labelArray[13] = new JLabel("13"); labelArray[14] = new JLabel("14");
labelArray[15] = new JLabel("15"); labelArray[16] = new JLabel("16");
labelArray[17] = new JLabel("17"); labelArray[18] = new JLabel("18");
//populate the buttonArray
buttonArray[0] = new JButton("H"); buttonArray[1] = new JButton("He");
buttonArray[2] = new JButton("Li"); buttonArray[3] = new JButton("Be");
buttonArray[4] = new JButton("B"); buttonArray[5] = new JButton("C");
buttonArray[6] = new JButton("N"); buttonArray[7] = new JButton("O");
buttonArray[8] = new JButton("F"); buttonArray[9] = new JButton("Ne");
buttonArray[10] = new JButton("Na"); buttonArray[11] = new JButton("Mg");
buttonArray[12] = new JButton("Al"); buttonArray[13] = new JButton("Si");
buttonArray[14] = new JButton("P"); buttonArray[15] = new JButton("S");
buttonArray[16] = new JButton("Cl"); buttonArray[17] = new JButton("Ar");
//Initialize the top panel which will hold the calculator's text field
centerPanel = new JPanel();
centerPanel.setLayout(periodicLayout);
//first row
centerPanel.add(labelArray[0]);
centerPanel.add(labelArray[1]);
for(int i=0; i<18; i++)
{
centerPanel.add(labelArray[0]);
}
centerPanel.add(labelArray[18]);
//Second row
centerPanel.add(labelArray[1]); centerPanel.add(buttonArray[0]); centerPanel.add(labelArray[2]);
for(int i=0;i<10;i++)
{
centerPanel.add(labelArray[0]);
}
for(int i=13; i<18; i++)
{
centerPanel.add(labelArray[i]);
}
centerPanel.add(buttonArray[2]);
//Thrid Row
//Fourth Row
//Fifth Row
//Sixth Row
//Seventh Row
//Eigth Row
//Ninth Row
//Tenth Row
add(centerPanel, BorderLayout.CENTER);
}
Any suggestions? Also there are labels for the number of the current row and column
thanks in advance

New Topic/Question
Reply



MultiQuote




|