Tangina mo
Kupal ka?unknown
java
13 days ago
4.9 kB
14
Indexable
import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.SwingConstants; class FoodHub { public static void main(String[] args) { JFrame frame = new JFrame("Justine B. Agcanas"); JPanel panel = new JPanel(); JLabel header = new JLabel("FoodCock", SwingConstants.CENTER); JLabel product1 = new JLabel("Hotdog 20"); JButton minus1 = new JButton("-"); JLabel quantity1 = new JLabel("0", SwingConstants.CENTER); JButton plus1 = new JButton("+"); JButton order = new JButton("Order"); JTextArea receipt = new JTextArea("Receipt"); JLabel product2 = new JLabel("Talabang 40"); JButton minus2 = new JButton("-"); JLabel quantity2 = new JLabel("0", SwingConstants.CENTER); JButton plus2 = new JButton("+"); product1.setBounds(50, 80, 200, 30); product1.setFont(new Font("Calibri", Font.PLAIN, 20)); minus1.setBounds(250, 80, 30, 30); minus1.setBackground(Color.pink); minus1.setFont(new Font("Calibri", Font.PLAIN, 15)); minus1.setBorder(null); quantity1.setBounds(300, 80, 30, 30); quantity1.setFont(new Font("Calibri", Font.PLAIN, 16)); plus1.setBounds(350, 80, 30, 30); plus1.setBackground(Color.pink); plus1.setFont(new Font("Calibri", Font.PLAIN, 15)); plus1.setBorder(null); plus1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int quantity = Integer.parseInt(quantity1.getText()); quantity++; quantity1.setText(Integer.toString(quantity)); } }); minus1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int quantity = Integer.parseInt(quantity1.getText()); if (quantity > 0) { quantity--; quantity1.setText(Integer.toString(quantity)); } } }); product2.setBounds(50, 120, 200, 30); product2.setFont(new Font("Calibri", Font.PLAIN, 20)); minus2.setBounds(250, 120, 30, 30); minus2.setBackground(Color.pink); minus2.setFont(new Font("Calibri", Font.PLAIN, 15)); minus2.setBorder(null); quantity2.setBounds(300, 120, 30, 30); quantity2.setFont(new Font("Calibri", Font.PLAIN, 16)); plus2.setBounds(350, 120, 30, 30); plus2.setBackground(Color.pink); plus2.setFont(new Font("Calibri", Font.PLAIN, 15)); plus2.setBorder(null); plus2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int quantity = Integer.parseInt(quantity2.getText()); quantity++; quantity2.setText(Integer.toString(quantity)); } }); minus2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int quantity = Integer.parseInt(quantity2.getText()); if (quantity > 0) { quantity--; quantity2.setText(Integer.toString(quantity)); } } }); order.setBounds(100, 160, 200, 30); order.setFont(new Font("Calibri", Font.PLAIN, 20)); order.setBackground(Color.pink); order.setBorder(null); order.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int hotdog = 20; int talabang = 40; int q1 = Integer.parseInt(quantity1.getText()); int total = hotdog * q1; int q2 = Integer.parseInt(quantity2.getText()); int total2 = talabang * q2; int totalAmount = total + total2; receipt.setText("Hotdog: " + q1 + " x " + hotdog + " = " + total + "\n" + "Talabang: " + q2 + " x " + talabang + " = " + total2 + "\n" + "Total: " + totalAmount); } }); receipt.setBounds(50, 200, 400, 200); receipt.setFont(new Font("Calibri", Font.PLAIN, 16)); receipt.setEditable(false); panel.setLayout(null); panel.setBounds(0, 0, 500, 500); panel.setBackground(Color.white); header.setFont(new Font("Calibri", Font.PLAIN, 25)); header.setBounds(0, 20, 500, 50); header.setOpaque(true); frame.setSize(500, 500); frame.setVisible(true); frame.setLayout(null); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(header); frame.add(product1); frame.add(minus1); frame.add(quantity1); frame.add(product2); frame.add(minus2); frame.add(plus2); frame.add(plus1); frame.add(quantity2); frame.add(order); frame.add(receipt); frame.add(panel); } }
Editor is loading...
Leave a Comment