Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class Costam
- {
- static int postcode;
- static int amount = 29;
- static int bill;
- static final JFrame frame = new JFrame();
- static final JLabel name = new JLabel();
- static final JFormattedTextField postcodeField = new JFormattedTextField(new Integer(0));
- static final JButton startShopping = new JButton("startShopping");
- static void Costam()
- {
- frame.setTitle("Costam");
- frame.setSize(800, 600);
- frame.setLocationRelativeTo(null);
- frame.setLayout(null);
- name.setText("Welcome to ...");
- name.setBounds(100, 100, 200, 20);
- frame.add(name);
- name.setVisible(true);
- }
- static void screen1 (Boolean flag)
- {
- name.setVisible(flag);
- postcodeField.setVisible(flag);
- startShopping.setVisible(flag);
- }
- public static void main(String[] args)
- {
- frame.setTitle("Costam");
- frame.setSize(800, 600);
- frame.setLocationRelativeTo(null);
- frame.setLayout(null);
- name.setText("Welcome to ...");
- name.setBounds(100, 100, 200, 20);
- frame.add(name);
- name.setVisible(true);
- postcodeField.setBounds(100, 300, 200, 20);
- postcodeField.setText(null);
- frame.add(postcodeField);
- postcodeField.setVisible(true);
- final JLabel products = new JLabel();
- products.setText("Products");
- products.setBounds(100, 100, 200, 20);
- frame.add(products);
- products.setVisible(false);
- final JLabel output = new JLabel();
- output.setBounds(100, 200, 200, 20);
- frame.add(output);
- output.setVisible(false);
- startShopping.setBounds(100, 200, 200, 20);
- startShopping.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- screen1(false);
- postcode = (int) postcodeField.getValue();
- System.out.println(postcode);
- products.setVisible(true);
- bill = postcode * amount;
- output.setText(Integer.toString(bill));
- output.setVisible(true);
- }
- });
- frame.add(startShopping);
- startShopping.setVisible(true);
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement