Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
827 B
1
Indexable
Never
package midterm2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class midterm1task1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame frame = new JFrame();
		frame.setSize(300, 200);
		JButton b1 = new JButton("100");
		JButton b2 = new JButton("0");
		frame.add(b1, BorderLayout.NORTH);
		frame.add(b2, BorderLayout.SOUTH);
		
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int a = Integer.parseInt(b2.getLabel());
				a++;
				b2.setLabel(""+a);
			}
		});
		
		b2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int b = Integer.parseInt(b1.getLabel());
				b--;
				b1.setLabel(""+b);
			}
		});
		frame.setVisible(true);
	}

}