Java Code

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

/*

* To change this template, choose Tools | Templates


* and open the template in the editor.
*/
package javaapplication1;

/**
*
* @author user
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import static javax.swing.JFrame.EXIT_ON_CLOSE;

public class Project extends Frame implements ActionListener{

private VendingMachine ITE;


private JLabel
titleL,PriceL,ItemL,ItemL1,ItemL2,ItemL3,ItemL4,ItemL5,ItemL6,ItemL7,ItemL8,ItemL
9,ItemL10,
ItemL11,ItemL12,ItemL13,ItemL14,AskL1,AskL2;
private JTextField AskTF1,AskTF2;
private JButton Yes,No;
private ButtonHandler1 SB;
private ButtonHandler2 IB;
int Width = 400;

int Height = 400;

public Project(){
titleL=new JLabel("Vending Mahcine");
PriceL=new JLabel("Number|Name|Price");
AskTF1=new JTextField("What is your order? ");
AskTF2=new JTextField("How much is your money? ");
Yes=new JButton("Yes");
No=new JButton("No");
SB=new ButtonHandler1();
IB=new ButtonHandler2();
Yes.addActionListener(SB);
No.addActionListener(IB);

Container pane = getContentPane();


pane.setLayout(new GridLayout(3,1));
pane.add(AskL1);
pane.add(AskTF1);

pane.add(AskL2);
pane.add(AskTF2);

pane.add(Yes);
pane.add(No);

setVisible(true);

setTitle("VendingMAchine");
setSize(Width,Height);
setDefaultCloseOperation(EXIT_ON_CLOSE);

public class ButtonHandler1 implements ActionListener{


public void actionPerformed(ActionEvent e){
ITE.showAllData();

public class ButtonHandler2 implements ActionListener{


public void actionPerformed(ActionEvent e){
String input1=AskTF1.getText();
String input2=AskTF2.getText();

ITE.setAnswer(Integer.parseInt(input1));
ITE.setAnswer2(Integer.parseInt(input2));

JOptionPane.showMessageDialog(null,"The data has been inserted to the


object");

You might also like