Solved

how to extract url information

Posted on 2008-09-29
9
209 Views
Last Modified: 2013-11-23
0
Comment
Question by:tdavidson_9
  • 5
  • 4
9 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
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
 

Author Comment

by:tdavidson_9
Comment Utility
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
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
Sorry, wasn't paying attention to the invokeLater statement itself.
0
 

Author Comment

by:tdavidson_9
Comment Utility
Then how to make it work? Is it possible to do it?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
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
 

Author Comment

by:tdavidson_9
Comment Utility
// 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
 

Author Comment

by:tdavidson_9
Comment Utility
I also try your method, it does not compile at all :(
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 250 total points
Comment Utility
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
 
LVL 59

Expert Comment

by:Kevin Cross
Comment Utility
This is how mine is defined:
public class Display implements ActionListener, Runnable
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now