Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
932 B
1
Indexable
Never
package midterm2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class midterm3task1 {
		public static void main(String[] args) {
			JFrame frame = new JFrame();
			frame.setSize(300, 200);
			JButton button1 = new JButton("9999");
			JButton button2 = new JButton("3");
			frame.add(button1, BorderLayout.NORTH);
			frame.add(button2, BorderLayout.SOUTH);
			
			button1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					int tmp = Integer.parseInt(button2.getLabel());
					tmp--;
					button2.setLabel(""+tmp);
				}
			});
			 button2.addActionListener(new ActionListener() {
				 public void actionPerformed(ActionEvent e) {
					int tmp = Integer.parseInt(button2.getLabel());
					 int tmp1 = Integer.parseInt(button1.getLabel());
				
					button1.setLabel(""+(tmp1-tmp));
				 }
			 });
			frame.setVisible(true);
		}
}