我目前正在尝试从两个 JTextField 中读取值,通过递增 1 来查找值的范围,然后将值写入 Double 数组。但是我所做的方式似乎不起作用,我在谷歌/互联网上找不到解决方案。
到目前为止,这是我的代码:
package textfieldtodouble;
import java.awt.*;
import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import javax.swing.*;
public class TextFieldToDouble {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
static JTextField maxValue1 = new JTextField(20);
static JTextField maxValue2 = new JTextField(20);
JButton btn1 = new JButton("To Double Array");
double x[];
double value1;
double value2;
void buildTheGUI() {
panel.add(maxValue1, BorderLayout.NORTH);
panel.add(btn1, BorderLayout.SOUTH);
panel.add(maxValue2, BorderLayout.SOUTH);
btn1.addActionListener(new toDouble());
frame.add(panel);
frame.setSize(300, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
TextFieldToDouble() {
buildTheGUI();
}
public static void main(String[] args) {
new TextFieldToDouble();
}
class toDouble implements ActionListener {
public void actionPerformed(ActionEvent event) {
value1 = Double.parseDouble(maxValue1.getText());
value2 = Double.parseDouble(maxValue2.getText());
for (int i = 0; i < value1; i++) {
System.out.println(i);
x[i] = value2 + i;
value2 ++;
}
}
}
}
提前致谢。:)