0

我对 Java 非常陌生,并且一直在学习,因为这是我的工作需要的方式。我正在构建一个 GUI,让用户在 JFrame 上输入信息,然后我需要保存他们输入的内容,并在用户点击按钮时将其传递给另一个 JFrame 上的标签。

public class MainClass {
public static void main(String[] args) throws IOException{
JFrame frame = new JFrame("COLA");
                frame.setContentPane(new JLabel(new ImageIcon("JpPB.jpg")));
                frame.setLayout(new FlowLayout());// This layout allows things to overlap
                frame.setSize(950,765);
                frame.setIconImage(new ImageIcon("CLA.jpg").getImage()); 
                frame.setVisible(true);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //CLOSE
             //   frame.getContentPane().setBackground(LBlue); //COLOR
                frame.setLocationRelativeTo(null); //Center JFrame in the middle of screen

            JMenuBar menubar = new JMenuBar();
            frame.setJMenuBar(menubar);
            JMenu file = new JMenu ("File");
            menubar.add(file);

            JMenuItem newer = new JMenuItem("Mission Information");
            file.add(newer);

            class newmission implements ActionListener{ //Action to call menu bar to close
                public void actionPerformed (ActionEvent o){

                    JFrame nm = new JFrame("Mission");
                    nm.setContentPane(new JLabel(new ImageIcon("JpPB.jpg")));
                    nm.setLayout(new FlowLayout());// This layout allows things to overlap
                    nm.setSize(600,300);
                    nm.setIconImage(new ImageIcon("CLA.jpg").getImage()); 
                    //nm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //CLOSE

                    nm.setVisible(true);
                    nm.setLocationRelativeTo(null); //Center JFrame in the middle of screen

                    JPanel panel1 = new JPanel(new GridBagLayout());
                    panel1.setLayout(new GridBagLayout());
                    panel1.setPreferredSize(new Dimension(550, 250));
                    nm.getContentPane().add(panel1, BorderLayout.WEST);
                    GridBagConstraints a = new GridBagConstraints();
                    panel1.setBackground(new Color(0,0,0,0)); //Set Background of Panel
                    panel1.setVisible(true);
                    Border lineBorders1 = BorderFactory.createTitledBorder("Mission Information");
                    panel1.setBorder(lineBorders1);

                    JLabel label9 = new JLabel(" Mission Title: ");
                    a.gridx = 0; 
                    a.gridy = 0;
                    a.insets = new Insets(1,1,1,1); //Set Distance between lines
                    panel1.add(label9, a);

                    JTextField text=new JTextField(30);
                    a.gridx = 1; 
                    a.gridy = 0;
                    panel1.add(text, a);
}   

            }newer.addActionListener(new newmission());}}

用户将信息输入到 TextField 中,我需要以某种方式将其带回主类并将其添加到标签中。以上是我的代码片段,但我认为我的新手问题并不需要它。

我再次进入 Java 2 天,别无选择,只能用霰弹枪构建这个东西......谢谢你的帮助。

4

0 回答 0