import java.io.*;
import java.awt.*;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import java.awt.Panel;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.MenuBar;
import java.awt.Menu;
import java.awt.MenuItem;
import javax.swing.JScrollBar;
import java.awt.TextField;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
class PanelTest extends JFrame
{
int i,j=0;
int x=190;
int row=135;
int colum=190;
MenuItem autoSum,autoAverage,min,max;
MenuItem system;
Panel panel1=new Panel();//button panel for up buttons
Panel panel2=new Panel();//button panel for side buttons
Panel panel3=new Panel();//button panel for formula bar
Panel fieldPanel=new Panel();//Text field panel for textfield
//declaration of buttons
JButton button[]=new JButton[10];//button for side
JButton button1=new JButton("A");
JButton button2=new JButton("B");
JButton button3=new JButton("C");
JButton button4=new JButton("D");
JButton button5=new JButton("E");
JButton button6=new JButton("F");
JButton button7=new JButton("G");
JButton button8=new JButton("H");
JButton button9=new JButton("I");
JButton button10=new JButton("J");
JButton t1=new JButton ("RESULT");
JButton t3=new JButton ("ENTER FORMULA");
JButton t4=new JButton ("CLICK HERE");
//declaration of textfields
TextField t[][]=new TextField[10][10];
TextField t2=new TextField("");
public PanelTest()
{
super ("SIMPLE ARITHMETIC EVALUTION 2.1");//constructor for title bar
Container c=getContentPane();
// fieldPanel.setLayout(new GridLayout(10,10,1,1));//set layout for textfield
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
t[i][j]=new TextField(" ");
t[i][j].setBounds(row,colum,70,25);
fieldPanel.add(t[i][j]);
row=row+75;
}
row=135;
colum=colum+30;
}
for(int i=0;i<10;i++)
{
button[i]=new JButton(""+(i+1));
panel2.add(button[i]);
}
button1.setBounds(135,160,70,25);
button2.setBounds(210,160,70,25);
//button2.setForGround(Color.red);
button3.setBounds(285,160,70,25);
button4.setBounds(360,160,70,25);
button5.setBounds(435,160,70,25);
button6.setBounds(510,160,70,25);
button7.setBounds(585,160,70,25);
button8.setBounds(660,160,70,25);
button9.setBounds(735,160,70,25);
button10.setBounds(810,160,70,25);
t1.setBounds(60,510,270,90);
t3.setBounds(330,510,270,45);
t4.setBounds(600,510,270,90);
t2.setBounds(330,555,270,45);
panel3.add(t1);
panel3.add(t3);
panel3.add(t4);
panel3.add(t2);
//wok for side bottons
for(i=0;i<10;i++)
{
button[i].setBounds(60,x,70,25);
x=x+30;
}
c.add(button1);
c.add(button2);
c.add(button3);
c.add(button4);
c.add(button5);
c.add(button6);
c.add(button7);
c.add(button8);
c.add(button9);
c.add(button10);
c.add(t1);
c.add(t3);
c.add(t4);
c.add(t2);
for(i=0;i<10;i++)
{
c.add(button[i]);
}
c.add(panel2);
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
c.add(t[i][j]);
}
}
c.add(fieldPanel);
c.add(panel3);
/*work of bar*/
MenuBar bar=new MenuBar();
setMenuBar(bar);
//fileMenu start
Menu fileMenu=new Menu("File");
MenuItem newFile=new MenuItem("New File .......Alt N");
MenuItem openFile=new MenuItem("Open File .....Alt O");
MenuItem exitFile=new MenuItem("Exit ...........Alt Esc");
fileMenu.add(newFile);
fileMenu.add(openFile);
fileMenu.add(exitFile);
bar.add(fileMenu);
//About Menu star
Menu aboutMenu=new Menu("About");
MenuItem project=new MenuItem("Our Project");
MenuItem project1=new MenuItem("Other Project");
aboutMenu.add(project);
aboutMenu.add(project1);
bar.add(aboutMenu);
//View Menu
Menu viewMenu=new Menu("View");
Menu devlopersProfile=new Menu("Devlopers Profile");
MenuItem zeroEightProfile=new MenuItem("08 Profile");
MenuItem rony=new MenuItem("MD.SHIFUDDIN AL MASUD");
MenuItem banna=new MenuItem("TARAK AMAN BANNA");
MenuItem joy=new MenuItem("DEBASHIS CHAKROBORTI");
MenuItem shawon=new MenuItem("SHAWON BORUA");
MenuItem shristi=new MenuItem("SHRISTI SUMONA NATH");
MenuItem toma=new MenuItem("TOMA HATI");
devlopersProfile.add(rony);
devlopersProfile.add(banna);
devlopersProfile.add(joy);
devlopersProfile.add(shawon);
devlopersProfile.add(shristi);
devlopersProfile.add(toma);
viewMenu.add(devlopersProfile);
viewMenu.add(zeroEightProfile);
bar.add(viewMenu);
//HELP MENU
Menu help=new Menu("Help");
system=new MenuItem("HOW TO RUN");
help.add(system);
bar.add(help);
//action menu
Menu action=new Menu("Action");
autoSum=new MenuItem("Auto Sum");
autoAverage=new MenuItem("Auto Average");
MenuItem autoMultiply=new MenuItem("Auto Multiply");
MenuItem min=new MenuItem("Minumum");
MenuItem max=new MenuItem("Maximum");
action.add(autoSum);
action.add(autoAverage);
action.add(autoMultiply);
action.add(min);
action.add(max);
bar.add(action);
show();
TextFieldHandler handler = new TextFieldHandler();
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
t[i][j].addActionListener(handler);
}
}
help.addActionListener(handler);
autoSum.addActionListener(handler);
autoAverage.addActionListener(handler);
t4.addActionListener(handler);
min.addActionListener(handler);
max.addActionListener(handler);
system.addActionListener(handler);
}
class TextFieldHandler implements ActionListener
{
int sum=0,sum1=0,sum2=0,mul=1,i=0,j=0,minimum=0,l=0,maximum=0,length=0,location=0,length1=0,length2=0,counter1=0,counter2=0,counter11=0,counter22=0;
int a[]=new int[100];
char array[]=new char[10];
char array1[]=new char[10];
char array2[]=new char[10];
//MyPanel ob=new MyPanel();
public void actionPerformed( ActionEvent event )
{
String string ,string1;
sum=0;
mul=1;
if(event.getSource()==system)
{
Help myhelp=new Help();
myhelp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myhelp.setSize(800,700);
myhelp.setVisible(true);
}
if(event.getSource()==t4)
{ l=0;
//t[9][9].setText("");
for(i=0;i<10;i++)
{ for(j=0;j<10;j++)
{ string=t[i][j].getText();
string1="0"+string.trim();
a[l]=Integer.parseInt(string1);
l++;
}
}
string=t2.getText();
string1=string.trim();
length=string1.length();
string1.getChars(0,(length),array,0);
for(i=0;i<length;i++)
{ if(array[i]=='+'||array[i]=='-'||array[i]=='*')
{ location=i;
}
}
for(i=0;i<location;i++)
{ array1[i]=array[i];
length1++;
}
j=0;
if(length-length1==4)
{
array2[0]=array[location+1];
array2[1]=array[location+2];
array2[2]=array[location+3];
//JOptionPane.showMessageDialog(null," "+(length-length1));
}
else
{
array2[0]=array[location+1];
array2[1]=array[location+2];
//JOptionPane.showMessageDialog(null," "+(length-length1));
}
if(length1==3)
{ i=9;
if(array1[0]=='a')
j=0;
if(array1[0]=='b')
j=1;
if(array1[0]=='c')
j=2;
if(array1[0]=='d')
j=3;
if(array1[0]=='e')
j=4;
if(array1[0]=='f')
j=5;
if(array1[0]=='g')
j=6;
if(array1[0]=='h')
j=7;
if(array1[0]=='i')
j=8;
if(array1[0]=='j')
j=9;
i=i*10;
j=i+j;
sum1=j;
//JOptionPane.showMessageDialog(null," "+(j)+" "+i);
}
else
{ if(array1[0]=='a')
j=0;
if(array1[0]=='b')
j=1;
if(array1[0]=='c')
j=2;
if(array1[0]=='d')
j=3;
if(array1[0]=='e')
j=4;
if(array1[0]=='f')
j=5;
if(array1[0]=='g')
j=6;
if(array1[0]=='h')
j=7;
if(array1[0]=='i')
j=8;
if(array1[0]=='j')
j=9;
if(array1[1]=='1')
i=0;
if(array1[1]=='2')
i=1;
if(array1[1]=='3')
i=2;
if(array1[1]=='4')
i=3;
if(array1[1]=='5')
i=4;
if(array1[1]=='6')
i=5;
if(array1[1]=='7')
i=6;
if(array1[1]=='8')
i=7;
if(array1[1]=='9')
i=8;
i=i*10;
j=i+j;
sum1=j;
}
//JOptionPane.showMessageDialog(null,"position "+(sum1));
if((length-length1)==4)
{ int i=9;
if(array2[0]=='a')
j=0;
if(array2[0]=='b')
j=1;
if(array2[0]=='c')
j=2;
if(array2[0]=='d')
j=3;
if(array2[0]=='e')
j=4;
if(array2[0]=='f')
j=5;
if(array2[0]=='g')
j=6;
if(array2[0]=='h')
j=7;
if(array2[0]=='i')
j=8;
if(array2[0]=='j')
j=9;
i=i*10;
j=i+j;
sum2=j;
}
else
{ if(array2[0]=='a')
j=0;
if(array2[0]=='b')
j=1;
if(array2[0]=='c')
j=2;
if(array2[0]=='d')
j=3;
if(array2[0]=='e')
j=4;
if(array2[0]=='f')
j=5;
if(array2[0]=='g')
j=6;
if(array2[0]=='h')
j=7;
if(array2[0]=='i')
j=8;
if(array2[0]=='j')
j=9;
if(array2[1]=='1')
i=0;
if(array2[1]=='2')
i=1;
if(array2[1]=='3')
i=2;
if(array2[1]=='4')
i=3;
if(array2[1]=='5')
i=4;
if(array2[1]=='6')
i=5;
if(array2[1]=='7')
i=6;
if(array2[1]=='8')
i=7;
if(array2[1]=='9')
i=8;
i=i*10;
j=i+j;
sum2=j;
}
if(array[location]=='+')
{ sum=a[sum1]+a[sum2];
string=String.valueOf(sum);
t1.setText(string1+ "=" +string);
//t1.setText(string);
}
if(array[location]=='-')
{ int sub=a[sum1]-a[sum2];
string=String.valueOf(sub);
t1.setText(string1+ "=" +string);
// t1.setText(string);
}
if(array[location]=='*')
{ int mul=a[sum1]*a[sum2];
string=String.valueOf(a[sum1]*a[sum2]);
t1.setText(string1+ "=" +string);
//t1.setText(string);
}
}
if(event.getSource()==autoAverage)
{
sum=0;
j=0;
l=0;
//t[9][9].setText("");
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
string=t[i][j].getText();
string1="0"+string.trim();
a[l]=Integer.parseInt(string1);
l++;
}
}
for(i=0;i<l;i++)
{ if(a[i]==0)
{
j++;
}
}
j=0;
for(i=0;i<l;i++)
{
sum=sum+a[i];
}
sum=sum/(100-(j-10));
string=String.valueOf(sum);
t1.setText(string);
}
if(event.getSource()==autoSum)
{
sum=0;
j=0;
l=0;
t[9][9].setText("");
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{ string=t[i][j].getText();
string1="0"+string.trim();
a[l]=Integer.parseInt(string1);
l++;
}
}
for(i=0;i<l;i++)
{
sum=sum+a[i];
}
string=String.valueOf(sum);
t1.setText(string);
}
if(event.getSource()==min)
{ sum=0;
j=0;
l=0;
t[9][9].setText("");
for(i=0;i<10;i++)
{ for(j=0;j<10;j++)
{ string=t[i][j].getText();
string1="0"+string.trim();
a[l]=Integer.parseInt(string1);
l++;
}
}
minimum=a[0];
for(i=0;i<l;i++)
{ if(minimum>a[i])
minimum=a[i];
}
string=String.valueOf(minimum);
t[9][9].setText(string);
}
if(event.getSource()==max)
{
sum=0;
j=0;
l=0;
t[9][9].setText("");
for(i=0;i<10;i++)
{ for(j=0;j<10;j++)
{ string=t[i][j].getText();
string1="0"+string.trim();
a[l]=Integer.parseInt(string1);
l++;
}
}
maximum=a[0];
for(i=0;i<l;i++)
{ if(minimum<a[i])
maximum=a[i];
}
string=String.valueOf(maximum);
t[9][9].setText(string);
}
}
}
}
class Help extends JFrame
{
JLabel label,label1,label2,label3,label4,label5,label6;
//JButton button=new JButton("TYPES OF HELP");
public Help()
{
super("THE WORDL OF HELP");
setLayout(new FlowLayout());
Icon photo=new ImageIcon(getClass().getResource("ron.jpg"));
label=new JLabel();
label1=new JLabel("ASs");
label2=new JLabel();
label3=new JLabel();
label4=new JLabel();
label5=new JLabel();
label6=new JLabel();
//label.setText("AUTO RUN::");
/*+
"1.Frist enter nnumeric value to the textfield."+
"2.Click Auto Sum for sum."+
"3.Click Auto Average to average"+
"4.Click Minimum to get the minimum value."+
"5.Click Maximum to get the miaximum value."+
"MANUAL MANIPULSATION::"+
"1.Frist enter nnumeric value to the textfield."+
"2.Enter address of the data at the formula bar"+
"3.Now press RESULT button."+
"THANK YOU SIR");
*/
label.setIcon(photo);
//label.setHorizontalTextPosition(SwingConstants.CENTER);
//label.setVerticalTextPosition(SwingConstants.BOTTOM);
label.setToolTipText("CSE THE ULTIMATE");
add(label);
label1.setText("AUTO RUN::");
label1.setBounds(5,5,70,34);
//label.setText("AUTO RUN::");
//label.setText("AUTO RUN::");
//label.setText("AUTO RUN::");
add(label);
}
}
class MyPanel
{
public static void main(String a[])
{
PanelTest myTest=new PanelTest();
myTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myTest.setSize(900,700);
}
}