import java.awt.event.*;
import javax.swing.*;
public class Tradulator {
static String firstnum, secondnum, summ;
static float sum, firstn, secondn;
public static void main(String[] args) {
JFrame f=new JFrame("Tradulator");
JLabel l1=new JLabel("Sale Price : ");
JLabel l2=new JLabel("Buy Price : ");
JLabel l3=new JLabel("Result : ");
l1.setBounds(50,50, 100,40);
l2.setBounds(50,100, 100,40);
l3.setBounds(50,150, 100,40);
final JTextField tf1=new JTextField();
tf1.setBounds(150,50, 100,40);
final JTextField tf2=new JTextField();
tf2.setBounds(150,100, 100,40);
final JTextField tf3=new JTextField();
tf3.setBounds(150,150, 100,40);
JButton bPL=new JButton("P/L");
bPL.setBounds(50,200,55,30);
bPL.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
firstnum=tf1.getText();
secondnum=tf2.getText();
firstn=Float.parseFloat(firstnum);
secondn=Float.parseFloat(secondnum);
sum=firstn - secondn;
summ=String.valueOf(sum);
tf3.setText(summ);
}
});
JButton bPLp=new JButton("P/L %");
bPLp.setBounds(120,200,95,30);
bPLp.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
firstnum=tf1.getText();
secondnum=tf2.getText();
firstn=Float.parseFloat(firstnum);
secondn=Float.parseFloat(secondnum);
sum=((firstn - secondn)/secondn)*100;
summ=String.valueOf(sum);
tf3.setText(summ);
}
});
JButton bmul=new JButton("X");
bmul.setBounds(50,250,55,30);
bmul.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
firstnum=tf1.getText();
secondnum=tf2.getText();
firstn=Float.parseFloat(firstnum);
secondn=Float.parseFloat(secondnum);
sum=firstn*secondn;
summ=String.valueOf(sum);
tf3.setText(summ);
}
});
JButton bdiv=new JButton("/");
bdiv.setBounds(120,250,55,30);
bdiv.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
firstnum=tf1.getText();
secondnum=tf2.getText();
firstn=Float.parseFloat(firstnum);
secondn=Float.parseFloat(secondnum);
sum=firstn/secondn;
summ=String.valueOf(sum);
tf3.setText(summ);
}
});
JButton bclr=new JButton("Clear");
bclr.setBounds(100,300,105,30);
bclr.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText("");
tf2.setText("");
tf3.setText("");
}
});
f.add(l1);
f.add(tf1);
f.add(l2);
f.add(tf2);
f.add(l3);
f.add(tf3);
f.add(bPL);
f.add(bPLp);
f.add(bmul);
f.add(bdiv);
f.add(bclr);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
//f.setBackground(Color.yellow);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Output example
Thanks
Happy Developing !
import javax.swing.*;
public class Tradulator {
static String firstnum, secondnum, summ;
static float sum, firstn, secondn;
public static void main(String[] args) {
JFrame f=new JFrame("Tradulator");
JLabel l1=new JLabel("Sale Price : ");
JLabel l2=new JLabel("Buy Price : ");
JLabel l3=new JLabel("Result : ");
l1.setBounds(50,50, 100,40);
l2.setBounds(50,100, 100,40);
l3.setBounds(50,150, 100,40);
final JTextField tf1=new JTextField();
tf1.setBounds(150,50, 100,40);
final JTextField tf2=new JTextField();
tf2.setBounds(150,100, 100,40);
final JTextField tf3=new JTextField();
tf3.setBounds(150,150, 100,40);
JButton bPL=new JButton("P/L");
bPL.setBounds(50,200,55,30);
bPL.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
firstnum=tf1.getText();
secondnum=tf2.getText();
firstn=Float.parseFloat(firstnum);
secondn=Float.parseFloat(secondnum);
sum=firstn - secondn;
summ=String.valueOf(sum);
tf3.setText(summ);
}
});
JButton bPLp=new JButton("P/L %");
bPLp.setBounds(120,200,95,30);
bPLp.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
firstnum=tf1.getText();
secondnum=tf2.getText();
firstn=Float.parseFloat(firstnum);
secondn=Float.parseFloat(secondnum);
sum=((firstn - secondn)/secondn)*100;
summ=String.valueOf(sum);
tf3.setText(summ);
}
});
JButton bmul=new JButton("X");
bmul.setBounds(50,250,55,30);
bmul.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
firstnum=tf1.getText();
secondnum=tf2.getText();
firstn=Float.parseFloat(firstnum);
secondn=Float.parseFloat(secondnum);
sum=firstn*secondn;
summ=String.valueOf(sum);
tf3.setText(summ);
}
});
JButton bdiv=new JButton("/");
bdiv.setBounds(120,250,55,30);
bdiv.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
firstnum=tf1.getText();
secondnum=tf2.getText();
firstn=Float.parseFloat(firstnum);
secondn=Float.parseFloat(secondnum);
sum=firstn/secondn;
summ=String.valueOf(sum);
tf3.setText(summ);
}
});
JButton bclr=new JButton("Clear");
bclr.setBounds(100,300,105,30);
bclr.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText("");
tf2.setText("");
tf3.setText("");
}
});
f.add(l1);
f.add(tf1);
f.add(l2);
f.add(tf2);
f.add(l3);
f.add(tf3);
f.add(bPL);
f.add(bPLp);
f.add(bmul);
f.add(bdiv);
f.add(bclr);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
//f.setBackground(Color.yellow);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Output example
Thanks
Happy Developing !
No comments:
Post a Comment