12 years ago
Hey friends, this is a java based gui calculator that i created..To run it please save it and compile it on cmd using jvm
ps: JAVA lovers please fill in with your comments
import java.awt.*;
import java.awt.event.*;
class Event implements ActionListener
{
Frame f;
Button b[];
int s,s1,w,t,t1;
TextField tf;
boolean second,first,plus,minus,multiply,divide,x,y,q;
Event(String s)
{
f= new Frame(s);
b= new Button[25];
for(int j=1 ; j<4; j++ )
{
b[j] = new Button(String.valueOf(j));
b[j].setBounds(50* j,100,40,40);
b[j].addActionListener(this);
f.add(b[j]);
}
for(int j=4; j<7;j++)
{
b[j] = new Button(String.valueOf(j));
b[j].setBounds(50*(j-3),150,40,40);
b[j].addActionListener(this);
f.add(b[j]);
}
for(int j=7; j<10;j++)
{
b[j] = new Button(String.valueOf(j));
b[j].setBounds(50 *(j-6),200,40,40);
b[j].addActionListener(this);
f.add(b[j]);
}
b[10] = new Button("0");
b[10].setBounds(50,250,40,40);
f.add(b[10]);
b[10].addActionListener(this);
b[11] = new Button("=");
b[11].setBounds(100,250,90,40);
f.add(b[11]);
b[11].addActionListener(this);
b[12] = new Button("-");
b[13] = new Button("*");
b[14] = new Button("/");
b[15] = new Button("+");
b[16]= new Button("CLEAR The Mess");
b[16].setBounds(50,300,190,40);
f.add(b[16]);
b[16].addActionListener(this);
b[17]= new Button("Coding courtesy: Deven ");
b[17].setBounds(260,40,190,40);
f.add(b[17]);
b[17].addActionListener(this);
b[18]= new Button("Exit");
b[18].setBounds(260,300,190,40);
f.add(b[18]);
b[18].addActionListener(this);
b[19]= new Button("Minimize");
b[19].setBounds(260,250,190,40);
f.add(b[19]);
b[19].addActionListener(this);
b[20]= new Button("Maximize");
b[20].setBounds(260,200,190,40);
f.add(b[20]);
b[20].addActionListener(this);
for(int j=12 ;j<16;j++)
{
b[j].setBounds(200,50 *(j-10),40,40);
f.add(b[j]);
b[j].addActionListener((this));
}
tf = new TextField();
tf.setBounds(50,40,190,40);
f.add(tf);
f.setLayout(null);
f.setSize(500,400);
f.setVisible(true);
}
public static void main(String... aa)
{
Event d = new Event("Deven Calculator");
}
public void actionPerformed(ActionEvent e)
{
for(int j=12;j<16;j++)
{
if(e.getSource()==b[j])
{
tf.setText(b[j].getLabel());
second = true;
first = true;
b[j].setForeground(Color.red);
}
}
for(int j=15;j<16;j++)
{
if(e.getSource()==b[j])
{
plus=true;
}
}
for(int j=12;j<13;j++)
{
if(e.getSource()==b[j])
{
minus=true;
}
}
for(int j=14;j<15;j++)
{
if(e.getSource()==b[j])
{
divide=true;
}
}
for(int j=13;j<14;j++)
{
if(e.getSource()==b[j])
{
multiply=true;
}
}
for(int i=1;i<11 ;i++)
{
if(e.getSource() == b)
{
b.setForeground(Color.blue);
if(first== false)
{
if(second == true)
{
tf.setText( b.getLabel() );
second = false;
}
else
{
tf.setText(tf.getText()+b.getLabel());
tf.setForeground(Color.red);
}
int s=Integer.parseInt(tf.getText());
t=s;
}
else
{
if(second == true)
{
tf.setText(b.getLabel());
second = false;
}
else
{
tf.setText(tf.getText()+b.getLabel());
tf.setForeground(Color.red);
}
int s1 = Integer.parseInt(tf.getText());
t1=s1;
}
}
}
for(int k=11;k<12;k++)
{
if(e.getSource() == b[11])
{
b[k].setForeground(Color.RED);
if(plus==true)
{
int w = t+t1;
tf.setText(String.valueOf(w));
b[11].setLabel(String.valueOf(w));
s=0;s1=0;w=0;
plus=false;
}
if(minus==true)
{
int w = t-t1;
tf.setText(String.valueOf(w));
b[11].setLabel(String.valueOf(w));
s=0;s1=0;w=0;
minus=false;
}
if(multiply==true)
{
int w = t*t1;
tf.setText(String.valueOf(w));
b[11].setLabel(String.valueOf(w));
s=0;s1=0;w=0;
multiply=false;
}
if(divide==true)
{
int w = t/t1;
tf.setText(String.valueOf(w));
b[11].setLabel(String.valueOf(w));
s=0;s1=0;w=0;
divide= false;
}
}
}
for(int p=16;p<17;p++)
{
if(e.getSource() == b[16])
{
tf.setText("");
b[1].setForeground(Color.black);
b[2].setForeground(Color.black);
b[3].setForeground(Color.black);
b[4].setForeground(Color.black);
b[5].setForeground(Color.black);
b[6].setForeground(Color.black);
b[7].setForeground(Color.black);
b[8].setForeground(Color.black);
b[9].setForeground(Color.black);
b[10].setForeground(Color.black);
b[11].setForeground(Color.black);
b[12].setForeground(Color.black);
b[13].setForeground(Color.black);
b[14].setForeground(Color.black);
b[15].setForeground(Color.black);
b[16].setForeground(Color.black);
b[17].setForeground(Color.black);
b[18].setForeground(Color.black);
b[19].setForeground(Color.black);
b[11].setForeground(Color.black);
b[11].setLabel("=");
f.setSize(500,400);
first=false;second=false;
}
}
for(int m=17;m<18;m++)
{
if(e.getSource() == b[17])
{
if(x== false)
{
tf.setText("Coding courtesy: Deven");
b[m].setBounds(260,120,190,40);
b[m].setLabel("See the Source code ");
b[m].setForeground(Color.red);
tf.setForeground(Color.blue);
x=true;
}
else
{
b[m].setLabel("Coding courtesy: Deven");
b[m].setBounds(260,40,190,40);
b[m].setForeground(Color.blue);
tf.setText("Really!!!");
tf.setForeground(Color.RED);
x=false;
q=true;
}
if(q== true)
{
try
{
Process p = Runtime.getRuntime().exec(" notepad finalCalcy.java");
}
catch(Exception ea)
{
}
q = false;
}
}
}
for(int m=18;m<19;m++)
{
if(e.getSource() == b[18])
{
f.setVisible(false);
}
}
for(int m=19;m<20;m++)
{
if(e.getSource() == b[19])
{
f.setSize(50,50);
}
}
for(int m=20;m<21;m++)
{
if(e.getSource() == b[20])
{
f.setSize(1250,800);
}
}
}
}
ps: JAVA lovers please fill in with your comments
import java.awt.*;
import java.awt.event.*;
class Event implements ActionListener
{
Frame f;
Button b[];
int s,s1,w,t,t1;
TextField tf;
boolean second,first,plus,minus,multiply,divide,x,y,q;
Event(String s)
{
f= new Frame(s);
b= new Button[25];
for(int j=1 ; j<4; j++ )
{
b[j] = new Button(String.valueOf(j));
b[j].setBounds(50* j,100,40,40);
b[j].addActionListener(this);
f.add(b[j]);
}
for(int j=4; j<7;j++)
{
b[j] = new Button(String.valueOf(j));
b[j].setBounds(50*(j-3),150,40,40);
b[j].addActionListener(this);
f.add(b[j]);
}
for(int j=7; j<10;j++)
{
b[j] = new Button(String.valueOf(j));
b[j].setBounds(50 *(j-6),200,40,40);
b[j].addActionListener(this);
f.add(b[j]);
}
b[10] = new Button("0");
b[10].setBounds(50,250,40,40);
f.add(b[10]);
b[10].addActionListener(this);
b[11] = new Button("=");
b[11].setBounds(100,250,90,40);
f.add(b[11]);
b[11].addActionListener(this);
b[12] = new Button("-");
b[13] = new Button("*");
b[14] = new Button("/");
b[15] = new Button("+");
b[16]= new Button("CLEAR The Mess");
b[16].setBounds(50,300,190,40);
f.add(b[16]);
b[16].addActionListener(this);
b[17]= new Button("Coding courtesy: Deven ");
b[17].setBounds(260,40,190,40);
f.add(b[17]);
b[17].addActionListener(this);
b[18]= new Button("Exit");
b[18].setBounds(260,300,190,40);
f.add(b[18]);
b[18].addActionListener(this);
b[19]= new Button("Minimize");
b[19].setBounds(260,250,190,40);
f.add(b[19]);
b[19].addActionListener(this);
b[20]= new Button("Maximize");
b[20].setBounds(260,200,190,40);
f.add(b[20]);
b[20].addActionListener(this);
for(int j=12 ;j<16;j++)
{
b[j].setBounds(200,50 *(j-10),40,40);
f.add(b[j]);
b[j].addActionListener((this));
}
tf = new TextField();
tf.setBounds(50,40,190,40);
f.add(tf);
f.setLayout(null);
f.setSize(500,400);
f.setVisible(true);
}
public static void main(String... aa)
{
Event d = new Event("Deven Calculator");
}
public void actionPerformed(ActionEvent e)
{
for(int j=12;j<16;j++)
{
if(e.getSource()==b[j])
{
tf.setText(b[j].getLabel());
second = true;
first = true;
b[j].setForeground(Color.red);
}
}
for(int j=15;j<16;j++)
{
if(e.getSource()==b[j])
{
plus=true;
}
}
for(int j=12;j<13;j++)
{
if(e.getSource()==b[j])
{
minus=true;
}
}
for(int j=14;j<15;j++)
{
if(e.getSource()==b[j])
{
divide=true;
}
}
for(int j=13;j<14;j++)
{
if(e.getSource()==b[j])
{
multiply=true;
}
}
for(int i=1;i<11 ;i++)
{
if(e.getSource() == b)
{
b.setForeground(Color.blue);
if(first== false)
{
if(second == true)
{
tf.setText( b.getLabel() );
second = false;
}
else
{
tf.setText(tf.getText()+b.getLabel());
tf.setForeground(Color.red);
}
int s=Integer.parseInt(tf.getText());
t=s;
}
else
{
if(second == true)
{
tf.setText(b.getLabel());
second = false;
}
else
{
tf.setText(tf.getText()+b.getLabel());
tf.setForeground(Color.red);
}
int s1 = Integer.parseInt(tf.getText());
t1=s1;
}
}
}
for(int k=11;k<12;k++)
{
if(e.getSource() == b[11])
{
b[k].setForeground(Color.RED);
if(plus==true)
{
int w = t+t1;
tf.setText(String.valueOf(w));
b[11].setLabel(String.valueOf(w));
s=0;s1=0;w=0;
plus=false;
}
if(minus==true)
{
int w = t-t1;
tf.setText(String.valueOf(w));
b[11].setLabel(String.valueOf(w));
s=0;s1=0;w=0;
minus=false;
}
if(multiply==true)
{
int w = t*t1;
tf.setText(String.valueOf(w));
b[11].setLabel(String.valueOf(w));
s=0;s1=0;w=0;
multiply=false;
}
if(divide==true)
{
int w = t/t1;
tf.setText(String.valueOf(w));
b[11].setLabel(String.valueOf(w));
s=0;s1=0;w=0;
divide= false;
}
}
}
for(int p=16;p<17;p++)
{
if(e.getSource() == b[16])
{
tf.setText("");
b[1].setForeground(Color.black);
b[2].setForeground(Color.black);
b[3].setForeground(Color.black);
b[4].setForeground(Color.black);
b[5].setForeground(Color.black);
b[6].setForeground(Color.black);
b[7].setForeground(Color.black);
b[8].setForeground(Color.black);
b[9].setForeground(Color.black);
b[10].setForeground(Color.black);
b[11].setForeground(Color.black);
b[12].setForeground(Color.black);
b[13].setForeground(Color.black);
b[14].setForeground(Color.black);
b[15].setForeground(Color.black);
b[16].setForeground(Color.black);
b[17].setForeground(Color.black);
b[18].setForeground(Color.black);
b[19].setForeground(Color.black);
b[11].setForeground(Color.black);
b[11].setLabel("=");
f.setSize(500,400);
first=false;second=false;
}
}
for(int m=17;m<18;m++)
{
if(e.getSource() == b[17])
{
if(x== false)
{
tf.setText("Coding courtesy: Deven");
b[m].setBounds(260,120,190,40);
b[m].setLabel("See the Source code ");
b[m].setForeground(Color.red);
tf.setForeground(Color.blue);
x=true;
}
else
{
b[m].setLabel("Coding courtesy: Deven");
b[m].setBounds(260,40,190,40);
b[m].setForeground(Color.blue);
tf.setText("Really!!!");
tf.setForeground(Color.RED);
x=false;
q=true;
}
if(q== true)
{
try
{
Process p = Runtime.getRuntime().exec(" notepad finalCalcy.java");
}
catch(Exception ea)
{
}
q = false;
}
}
}
for(int m=18;m<19;m++)
{
if(e.getSource() == b[18])
{
f.setVisible(false);
}
}
for(int m=19;m<20;m++)
{
if(e.getSource() == b[19])
{
f.setSize(50,50);
}
}
for(int m=20;m<21;m++)
{
if(e.getSource() == b[20])
{
f.setSize(1250,800);
}
}
}
}