import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
public class MyGuiExample2Ok extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JTextField textField_2;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MyGuiExample2Ok frame = new MyGuiExample2Ok();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MyGuiExample2Ok() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 821, 516);
contentPane = new JPanel();
contentPane.setBackground(new Color(0, 128, 128));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setFont(new Font(“Tahoma”, Font.PLAIN, 30));
textField.setBounds(195, 13, 142, 43);
contentPane.add(textField);
textField.setColumns(10);
JLabel lblNewLabel = new JLabel(“\u0391\u03C1\u03B9\u03B8\u03BC\u03CC\u03C2 \u03B1:”);
lblNewLabel.setForeground(new Color(0, 0, 255));
lblNewLabel.setFont(new Font(“Tahoma”, Font.BOLD, 25));
lblNewLabel.setBounds(35, 15, 148, 43);
contentPane.add(lblNewLabel);
textField_2 = new JTextField();
textField_2.setFont(new Font(“Tahoma”, Font.PLAIN, 30));
textField_2.setBounds(195, 97, 142, 43);
contentPane.add(textField_2);
textField_2.setColumns(10);
JLabel lblNewLabel_1 = new JLabel(“\u0391\u03C1\u03B9\u03B8\u03BC\u03CC\u03C2 \u03B2:”);
lblNewLabel_1.setForeground(new Color(0, 0, 255));
lblNewLabel_1.setFont(new Font(“Tahoma”, Font.BOLD, 25));
lblNewLabel_1.setBounds(36, 95, 151, 43);
contentPane.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel(” \u0391\u03C0\u03BF\u03C4\u03AD\u03BB\u03B5\u03C3\u03BC\u03B1″);
lblNewLabel_2.setForeground(new Color(0, 0, 139));
lblNewLabel_2.setFont(new Font(“Tahoma”, Font.BOLD, 30));
lblNewLabel_2.setBounds(72, 245, 223, 59);
contentPane.add(lblNewLabel_2);
JButton btnNewButton = new JButton(“\u03C0\u03C1\u03CC\u03C3\u03B8\u03B5\u03C3\u03B5 “);
btnNewButton.setForeground(new Color(0, 0, 255));
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
int textField1=Integer.parseInt(textField.getText());
int textField2=Integer.parseInt(textField_2.getText());
int answer =(textField1 + textField2);
lblNewLabel_2.setText(Integer.toString(answer));
}
});
btnNewButton.setFont(new Font(“Tahoma”, Font.BOLD, 20));
btnNewButton.setBounds(35, 174, 302, 43);
contentPane.add(btnNewButton);
}
}
ΠΡΟΣΘΕΣΗ ΑΚΕΡΑΙΩΝ ΣΤΗΝ JAVA.