import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class Game {
public static void main(String[] args) {
final JFrame jf = new JFrame("MyGame");
jf.setLayout(null);
final JTextField jf1 = new JTextField();
jf1.setFont(new Font("Default", Font.BOLD, 28));
jf1.setBounds(180, 47, 120, 65);
jf.add(jf1);
JButton increment = new JButton("INCREMENT");
JButton decrement = new JButton("DECREMENT");
JButton close = new JButton("RESET");
increment.setBounds(45, 160, 110, 30);
decrement.setBounds(185, 160, 110, 30);
close.setBounds(325, 160, 110, 30);
jf.add(increment);
jf.add(decrement);
jf.add(close);
increment.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String crossIn = jf1.getText();
try {
Integer value = Integer.parseInt(crossIn);
jf1.setText(String.valueOf(value + 1));
} catch (Exception e2) {
JOptionPane.showMessageDialog(null, "Error!");
}
}
});
decrement.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String crossIn = jf1.getText();
try {
Integer value = Integer.parseInt(crossIn);
jf1.setText(String.valueOf(value - 1));
} catch (Exception e2) {
JOptionPane.showMessageDialog(null, "Error!");
}
}
});
close.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jf1.setText("");
}
});
jf.setVisible(true);
jf.setSize(500, 300);
jf.setLocation(760, 300);
jf.getContentPane().setBackground(Color.cyan);
jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}