• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

how to extract url information

0
tdavidson_9
Asked:
tdavidson_9
  • 5
  • 4
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
For setting the content to an argument, you should check that it has a value first and then pass to your JTextArea through parameters of the methods you use to create the GUI or through an instance variable.

Hopefully the code snippet helps explain it.

P.S. In the future you can just created a related question and the expert who helped you will get an e-mail but additionally other experts will be able to assist; therefore, you don't need to address question directly to a specific expert. :)
public static void main(String[] args) {
    String displayAreaText = "";
    
    if (args.length >= 1) { // you may want this to be exactly 1 (==)
        displayAreaText = args[0];
    }
 
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI(displayAreaText);
        }
    });
}
 
// Then you will need to change the signature of your methods like this
private static void createAndShowGUI(String displayAreaText) 
public JPanel createContentPane (String displayAreaText)
 
// And pass the displayAreaText down to the JTextArea
// OR just change the createAndShowGUI as shown above and add this line
Display display = new Display();
display.content = displayAreaText; // <--- this is new line
frame.setContentPane(display.createContentPane());

Open in new window

0
 
tdavidson_9Author Commented:
It didn't work!
My eclipse complaint: Cannot refer to a non-final variable content inside an inner class defined in a different method.
0
 
Kevin CrossChief Technology OfficerCommented:
Sorry, wasn't paying attention to the invokeLater statement itself.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
tdavidson_9Author Commented:
Then how to make it work? Is it possible to do it?
0
 
Kevin CrossChief Technology OfficerCommented:
You could do it making the following alterations.  May be another way to accomplish, but this is what I know off top of my head.

(Display class implements Runnable)
private void createAndShowGUI() {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame("Request message cookies");
        frame.setContentPane(createContentPane());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 600);
        frame.setVisible(true);
    }
 
    public static void main(String[] args) {
        String displayAreaText = "";
 
        if (args.length >= 1) { 
            displayAreaText = args[0];
        }
 
        SwingUtilities.invokeLater(new Display(displayAreaText));
    }
 
    public Display(String content) {
        this.content = content;
    }
 
    @Override
    public void run() {
        createAndShowGUI();
    }

Open in new window

0
 
tdavidson_9Author Commented:
// this way also works

   public static void main(String[] args) {

        if (args.length == 1){
            String content = args[0];
            createAndShowGUI(displayAreaText);
        }
        else
              System.exit(0);
   }
   private static void createAndShowGUI(String text) {
    ...
   public JPanel createContentPane (String text){
    ...
// I was wondering what is the risk for the program to invoke the object
// directly without using the code below!
//        SwingUtilities.invokeLater(new Runnable() {
//            public void run() {
//                createAndShowGUI();
//            }
//        });  
0
 
tdavidson_9Author Commented:
I also try your method, it does not compile at all :(
0
 
Kevin CrossChief Technology OfficerCommented:
Your method does work if you don't need to use the invokeLater of Swing as you had previously.  I stuck with that since you had it in original.

As far as my method, I tested it before posting and it will work if you change code as shown and add Runnable to the implements listing of Display as indicated in my comment.  Sorry if that wasn't clear.

Regards,
Kevin
0
 
Kevin CrossChief Technology OfficerCommented:
This is how mine is defined:
public class Display implements ActionListener, Runnable
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now