import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class jframe extends JFrame implements ActionListener
{
String a=null,b=null,c=null;
double x,y,z;
JButton b1,b2,b3,b4;
JTextField t1,t2,t3;
Container con;
jframe(String s)
{
super(s);
setSize(300,300);
con=getContentPane();
con.setLayout(new FlowLayout(FlowLayout.LEFT));
t1=new JTextField(7);
t2=new JTextField(7);
t3=new JTextField(7);
b1=new JButton("+");
b2=new JButton("-");
b3=new JButton("X");
b4=new JButton("%");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
con.add(t1);
con.add(t2);
con.add(t3);
con.add(b1);
con.add(b2);
con.add(b3);
con.add(b4);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
a=t1.getText();
b=t2.getText();
x=Double.parseDouble(a);
y=Double.parseDouble(b);
z=x+y;
t3.setText(String.valueOf(z));
}
if(e.getSource()==b2)
{
a=t1.getText();
b=t2.getText();
x=Double.parseDouble(a);
y=Double.parseDouble(b);
z=x-y;
t3.setText(String.valueOf(z));
}
if(e.getSource()==b3)
{
a=t1.getText();
b=t2.getText();
x=Double.parseDouble(a);
y=Double.parseDouble(b);
z=x*y;
t3.setText(String.valueOf(z));
}
if(e.getSource()==b4)
{
a=t1.getText();
b=t2.getText();
x=Double.parseDouble(a);
y=Double.parseDouble(b);
z=x/y;
t3.setText(String.valueOf(z));
}
}
}
class jframe1
{
public static void main(String args[])
{
JFrame f=new jframe("Frame with button");
f.setVisible(true);
}
}
import java.awt.event.*;
import java.awt.*;
class jframe extends JFrame implements ActionListener
{
String a=null,b=null,c=null;
double x,y,z;
JButton b1,b2,b3,b4;
JTextField t1,t2,t3;
Container con;
jframe(String s)
{
super(s);
setSize(300,300);
con=getContentPane();
con.setLayout(new FlowLayout(FlowLayout.LEFT));
t1=new JTextField(7);
t2=new JTextField(7);
t3=new JTextField(7);
b1=new JButton("+");
b2=new JButton("-");
b3=new JButton("X");
b4=new JButton("%");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
con.add(t1);
con.add(t2);
con.add(t3);
con.add(b1);
con.add(b2);
con.add(b3);
con.add(b4);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
a=t1.getText();
b=t2.getText();
x=Double.parseDouble(a);
y=Double.parseDouble(b);
z=x+y;
t3.setText(String.valueOf(z));
}
if(e.getSource()==b2)
{
a=t1.getText();
b=t2.getText();
x=Double.parseDouble(a);
y=Double.parseDouble(b);
z=x-y;
t3.setText(String.valueOf(z));
}
if(e.getSource()==b3)
{
a=t1.getText();
b=t2.getText();
x=Double.parseDouble(a);
y=Double.parseDouble(b);
z=x*y;
t3.setText(String.valueOf(z));
}
if(e.getSource()==b4)
{
a=t1.getText();
b=t2.getText();
x=Double.parseDouble(a);
y=Double.parseDouble(b);
z=x/y;
t3.setText(String.valueOf(z));
}
}
}
class jframe1
{
public static void main(String args[])
{
JFrame f=new jframe("Frame with button");
f.setVisible(true);
}
}
No comments:
Post a Comment