Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am very new to Java and have been learning as I go since this is how my job requires it. I am building a GUI to have the user imput infomration into on JFrame then I need to save what they entered and pass it to a label on another JFrame when the User hits a button.

public class swing {
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);
}   
            }

The user will enter the information into the TextField and I need to somehow take that back into the main class and add it to a label. Above is a snippet of my code but I do not think it is really required for my newbie question.

Again I am 2 days into java and have no choice but to shotgun build this thing... Thank you for your help.

share

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.