KINSAY KABALO UG MVC DIHA? PALIHUG KO PAKI CONVERT ANI NA CODE
JAVA GUI TO
MVC FRAMEWORK
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ATM_MACHINE extends JFrame implements ActionListener{
private JTextField txtX;
private JTextField txtY;
private JLabel lblDisplay;
private JButton btnADD;
private JButton btnSUB;
private JButton btnClear;
private JButton btnExit;
private Panel p1,p2;
public ATM_MACHINE(){
super("Sum");
p1= new Panel();
p1.setLayout(new GridLayout(4,2));
txtX = new JTextField();
txtY = new JTextField();
p1.add(new JLabel("Remaining Balance:"));
p1.add(txtX);
p1.add(new JLabel("Enter Amount:"));
p1.add(txtY);
p1.add(new JLabel("Total Balance: "));
lblDisplay = new JLabel();
p1.add(lblDisplay);
add(p1,BorderLayout.NORTH);
p2 = new Panel();
btnADD = new JButton("DEPOSIT");
btnSUB = new JButton("WITHDRAW");
btnClear = new JButton("OTHER TRANSACTION");
btnExit = new JButton("Exit");
btnADD.addActionListener(this);
btnSUB.addActionListener(this);
btnClear.addActionListener(this);
btnExit.addActionListener(this);
p2.add(btnADD);
p2.add(btnSUB);
p2.add(btnClear);
p2.add(btnExit);
add(p2,BorderLayout.CENTER);
setVisible(true);
pack();
}
public void actionPerformed(ActionEvent e){
lblDisplay.setText(e.getActionCommand());
if (e.getActionCommand().equals("OTHER TRANSACTION")== true){
lblDisplay.setText("");
txtX.setText("");
txtY.setText("");
}else if (e.getActionCommand().equals("Exit")== true)
System.exit(0);
else if (e.getActionCommand().equals("DEPOSIT")== true){
int num1= 0;
int num2 = 0;
int sum = 0;
Integer x = 0;
try{
num1 =x.parseInt(txtX.getText());
num2 =x.parseInt(txtY.getText());
sum = num1 + num2;
x = sum;
lblDisplay.setText(x.toString());
}catch(NumberFormatException ex){
lblDisplay.setText("Please input a number.");
}
}
else {
int num1= 0;
int num2 = 0;
int sum = 0;
Integer x = 0;
try{
num1 =x.parseInt(txtX.getText());
num2 =x.parseInt(txtY.getText());
sum = num1 - num2;
x = sum;
lblDisplay.setText(x.toString());
}catch(NumberFormatException ex){
lblDisplay.setText("Please input a number.");
}
}
}
public static void main(String a[]){
ATM_MACHINE g = new ATM_MACHINE();
}
}