import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//LIBRARY
public class finals { public static void main(String[]args)
{
JFrame.setDefaultLookAndFeelDecorated(true); //DESIGN FRAME
JFrame cp=new JFrame("CELLPHONE SHOP"); //CREATING FRAME
cp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// EXIT PROGRAMM
cp.setVisible(true);
//CREATING PANEL
JPanel panel=new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("SELECT BRAND"));
JPanel panel2=new JPanel();
panel2.setBorder(BorderFactory.createTitledBorder("ITEMS"));
JPanel panel3=new JPanel();
panel3.setBorder(BorderFactory.createTitledBorder("TRANSACTION"));
//CREATING JFIELD
JTextField budget=new JTextField();
budget.setBounds(200, 200, 50, 5);
JTextField price=new JTextField();
price.setBounds(250, 250, 50, 5);
JTextField total=new JTextField();
total.setBounds(300, 250, 50, 5);
total.setEditable(false);
// ADD PANEL
panel3.add(budget);
panel3.add(price);
panel3.add(total);
//CREATING JLABEL
JLabel label=new JLabel();
label.setHorizontalTextPosition(JLabel.CENTER);
label.setBounds(40,50,100,400);
//CREATING JBUTTON
JButton samsung=new JButton("SAMSUNG");
JButton oppo=new JButton("OPPO");
JButton vivo=new JButton("VIVO");
//SET SIZE BUTTONS
samsung.setBounds(20,50,90,20);
oppo.setBounds(20,50,90,20);
vivo.setBounds(20,50,90,20);
cp.setSize(400,400);
cp.setLayout(new GridLayout(3,1));
panel.add(samsung);
panel.add(oppo);
panel.add(vivo);
//ADDING PANEL TO FRAME
cp.add(panel);
cp.add(panel2);
cp.add(panel3);
//FUNCTION OF BUTTONS
oppo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
JButton enter=new JButton("TOTAL");
enter.setBounds(20,50,90,20);
panel3.add(enter);
String oppo1[]={ "OPPO A3S 4000$","OPPO F1 5000$","OPPO A5S 6000$"};
JComboBox box1=new JComboBox(oppo1);
panel2.add(box1);
JButton select=new JButton("select");
select.setBounds(20,50,90 ,20);
panel2.add(select);
select.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
String choice="You selected: "+
box1.getItemAt(box1.getSelectedIndex());
label.setText(choice);
panel2.add(label);
String textfield1 = budget.getText();
String textfield2 = total.getText();
String textfield3 = price.getText();
int a = Integer.parseInt(textfield1);
int b = Integer.parseInt(textfield2);
int price1 = Integer.parseInt(textfield3);
int c = 0;
int z = 0;
if(e.getSource() == enter)
{
if(a > price1)
{
JOptionPane.showMessageDialog(null, "Insufficient Money!!!");
}
else
{
z = a - price1;
String fresult = String.valueOf(z);
enter.setText(fresult);
}
}
}
});
}
});
}
}