Подключение полей и кнопки - Java
Формулировка задачи:
Помогите дописать код. В общем пишу программу которая считает зарплату исходя из введенных данных.
import javax.swing.*;
import java.awt.*;
public class Display {
private JTextField displayField;
public void setDisplayValue(String val) {
displayField.setText(val);
}
public String getDisplayValue() {
return displayField.getText();
}
public static void main(String[] args) {
JPanel p1;
JButton button0;
JPanel windowContent = new JPanel();
JTextField displayField;
button0 = new JButton("Enter my pay on display");
p1 = new JPanel();
JLabel label1 = new JLabel("Enter hours of mouth");
JTextField field1 = new JTextField(10);
JLabel label2 = new JLabel("Enter working day in month");
JTextField field2 = new JTextField(10);
JLabel label3 = new JLabel("Enter prepayment");
JTextField field3 = new JTextField(10);
JLabel label4 = new JLabel("Enter your working time");
JTextField field4 = new JTextField(10);
JLabel label5 = new JLabel("Enter your overtime");
JTextField field5 = new JTextField(10);
JLabel label6 = new JLabel("Your pay is: ");
JTextField field6 = new JTextField(10);
windowContent.add(label1);
windowContent.add(field1);
windowContent.add(label2);
windowContent.add(field2);
windowContent.add(label3);
windowContent.add(field3);
windowContent.add(label4);
windowContent.add(field4);
windowContent.add(label5);
windowContent.add(field5);
windowContent.add(label6);
windowContent.add(field6);
p1 = new JPanel();
GridLayout gl = new GridLayout(10, 30);
p1.setLayout(gl);
windowContent.add(button0);
CalculatorEngine calcEngine = new CalculatorEngine();
button0.addActionListener(calcEngine);
JFrame frame = new JFrame("PAY");
frame.setContentPane(windowContent);
frame.setSize(198, 360);
frame.setVisible(true);
}
}Решение задачи: «Подключение полей и кнопки»
textual
Листинг программы
String a=field1.getText();//считывание данных из текстового поля double b=Double.parseDouble(a);//перевод из строкового в вещественный тип