This discussion is archived
5 Replies Latest reply: Mar 5, 2013 12:35 PM by gimbal2 RSS

New to the language, issue using a previously created variable

994043 Newbie
Currently Being Moderated
I am new to Java, trying to get the basics under my belt, and am having problems with (what I thought was) a simple program. The long and short of the application is to create a small GUI with a text field for entry, a couple of radio buttons, and an action button. The end user inputs a computer name in the text field, selects one of the radios, and then clicks the action button. The problem I am running into is reading the text in from the text field. Below is the relevant portion of the code. The compiler is telling me it does not recognize the "asset_Name" variable, and I'm not sure why, I would think I would be able to see it in this context. Any suggestions would be greatly appreciated.


          txtAssetTag = new JTextField();
          String asset_Name;
          txtAssetTag.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                      asset_Name = txtAssetTag.getText();
               }
          });


          JButton btnNewButton = new JButton("Launch Client Action");
          btnNewButton.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent arg0) {
                    String x = "\\\\" + asset_Name;
                    if (rdbtnOpenCDrive.isSelected()) {
                         try {
                              Desktop.getDesktop().open(new java.io.File(x + "\\C$\\Users\\<UserName>\\Desktop"));
                         } catch (IOException e) {
                              e.printStackTrace();
                         }
                         
                    }
               }
          });
Edited by: 991040 on Feb 28, 2013 10:40 AM

Edited by: 991040 on Feb 28, 2013 10:41 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points