Мне нужно создать GUI и ввести там высоту и ширину, нажать на кнопку, и с этими высотами и ширинами откроется новое окно. На данный момент у меня есть значения переменных width и height, которые установлены в publi c void actionPerformed (ActionEvent e) {}, и я хочу использовать их для переноса значений для нового окна. Я пришел к выводу, что необходимо либо извлекать значения из самого JTextField, либо так, как я хочу реализовать
public class Form extends JFrame implements Runnable {
//private int w= 1280;
//private int h=768;
public int wt;
public int ht;
public void Okno() {
JFrame win1 = new JFrame("Evolution.IO");
win1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win1.setLayout(new BorderLayout());
win1.setSize(470, 400);
JPanel pane = new JPanel();
pane.setLayout(new FlowLayout());
JTextField txtField = new JTextField(5);
JTextField txtField2 = new JTextField(5);
JLabel weightL = new JLabel("Weight: ");
JLabel highL = new JLabel("High: ");
pane.add(weightL);
pane.add(txtField);
pane.add(highL);
pane.add(txtField2);
JButton btn = new JButton("Начать симуляцию");
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
wt = Integer.parseInt(txtField.getText());
ht = Integer.parseInt(txtField2.getText());
if (!(txtField==null)) {
Form f = new Form();
new Thread(f).start();
win1.getDefaultCloseOperation();
}
}
});
pane.add(btn);
win1.add(pane);
win1.setLocationRelativeTo(null);
win1.setVisible(true);
}
//THIS DOESNT WORK#
// public int w1() {
// return this.wt;
// }
// public int h1() {
// return this.ht;
// }
private final int FRAMES_TOTAL = 100000;
private final int SKIP_FRAMES = 10;
private final Color BG = new Color(200, 200, 200, 255);
private final Color BLUE = new Color(150, 160, 255, 255);
private final Color RED = new Color(255, 100, 120, 255);
private BufferedImage buf = new BufferedImage(w1(), h1(), BufferedImage.TYPE_INT_RGB);
private BufferedImage img = new BufferedImage(w1(), h1(), BufferedImage.TYPE_INT_RGB);
private BufferedImage graph = new BufferedImage(w1(), h1(), BufferedImage.TYPE_INT_ARGB);
//no longer needed