从第一种形式到第二种形式的信息摆动java

时间:2016-07-18 22:40:37

标签: java swing

我有2个表格。在第一种形式中,我创建了一个对象public class FormNum1 extends JFrame { JButton clearConfermation, conferm; JLabel dateofDeparture, dateofArrival, cityFrom, cityTo; JTextField dateofDepartureTextField, dateofArrivalTextField, cityFromTextField, cityToTextField; static Suggestion suggestion; Boolean n = false; JFrame form1 = new JFrame("form1"); ActionListener actionPerformed; public FormNum1(){ form1.setVisible(true); form1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); form1.setSize(1200,250); //setResizable(false); form1.setLocationRelativeTo(null); form1.setLayout(new FlowLayout()); clearConfermation = new JButton("Make clear"); conferm = new JButton("Confirm information "); dateofDeparture = new JLabel("Date of Departure"); dateofArrival = new JLabel("Date of Arrival"); cityFrom = new JLabel("City From"); cityTo = new JLabel("City to"); dateofDepartureTextField = new JTextField(10); dateofArrivalTextField = new JTextField(10); cityFromTextField = new JTextField(10); cityToTextField = new JTextField(10); form1.add(clearConfermation); form1.add(conferm); form1.add(dateofDeparture); form1. add(dateofDepartureTextField); form1.add(dateofArrival); form1.add(dateofArrivalTextField); form1.add(cityFrom); form1.add(cityFromTextField); form1.add(cityTo); form1.add(cityToTextField); actionPerformed = new InformationFromFormOne(); conferm.addActionListener(actionPerformed); clearConfermation.addActionListener(actionPerformed); } class InformationFromFormOne implements ActionListener{ public void actionPerformed(ActionEvent e) { if (e.getSource() == conferm){ String dateOfDeparture = (dateofDepartureTextField.getText()); String dateOfArrival = (dateofArrivalTextField.getText()); String cityFrom = (cityFromTextField.getText()); String cityTo = (cityToTextField.getText()); suggestion = new Suggestion(dateOfDeparture, dateOfArrival, true, cityFrom, cityTo); setVisible(false); form1.dispose(); } if (e.getSource() == clearConfermation){ dateofArrivalTextField.setText(null); dateofDepartureTextField.setText(null); cityFromTextField.setText(null); cityToTextField.setText(null); } } } } 。然后我必须用它做一些事情并将其提交给第二个表格。填写第一张表格后如何打开第二个窗口?

这是我的第一个表格:

public class FormNum2 extends JFrame{
    static JFrame form2 = new JFrame("form2");

    public FormNum2()  {
        form2.setSize(1200,600);
        //frame.setResizable(false);
        form2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        form2.setLocationRelativeTo(null);
        form2.setVisible(true);
    }
}

我的第二种形式是

public class Main extends Thread{
    public static void main(String[] args) {
        FormNum1 form1 = new FormNum1();
        FormNum2 form2 = new FormNum2();
    }
}

主要课程

{{1}}

2 个答案:

答案 0 :(得分:0)

在第一帧处理后,将第二帧设置为visible,将FormNum2 .setVisible(true);设置为显示第二帧。

答案 1 :(得分:-1)

如果要在填充第一个窗口后打开第二个窗口,则应在填充对象后调用FormNum2 form2 = new FormNum2()。看起来你想在form1.dispose()之后添加这一行。