import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class addTwoNumber extends JFrame implements ActionListener {
JButton addButton = new JButton("add");
JButton exitButton = new JButton("exit");
JButton resetButton = new JButton("reset");
JTextField num1 = new JTextField(5);
JTextField num2 = new JTextField(5);
JTextField output = new JTextField(8);
int nm1,nm2, out =0 ;
String n1, n2;
public addTwoNumber()
{
super("add two numbers");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel myPanel = new JPanel();
myPanel.add(num1);
myPanel.add(num2);
myPanel.add(output);
myPanel.add(addButton);
myPanel.add(exitButton);
myPanel.add(resetButton);
setContentPane(myPanel);
exitButton.addActionListener(this);
addButton.addActionListener(this);
}
public static void main(String[] args)
{
addTwoNumber frame = new addTwoNumber();
frame.setSize(600,100);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == exitButton)
{
System.exit(0);
}
else if(source == addButton)
{
n1 = num1.getText();
nm1 = Integer.parseInt(n1);
n2 = num2.getText();
nm2 = Integer.parseInt(n2);
out = nm1+nm2;
String nu = (""+out);
output.setText(nu);
}
else if(source == resetButton)
{
String empty = ("");
num1.setText(empty);
num2.setText(empty);
output.setText(empty);
}
}
}
볼드한부분이 작동을하지않습니다 1 + 1 = 2 가나온이후 리셋버튼을누르면 세 필드가 전부 비게하고싶은데.. 아무변화가없네요 조언좀 부탁드립니다