tdavidson_9
asked on
how to extract url information
https://www.experts-exchange.com/questions/23773234/Java-Swing-JTextArea-didn't-show-up.html?anchorAnswerId=22602342#a22602342
I need to set String content = args[0];
Thanks!
I need to set String content = args[0];
Thanks!
ASKER
It didn't work!
My eclipse complaint: Cannot refer to a non-final variable content inside an inner class defined in a different method.
My eclipse complaint: Cannot refer to a non-final variable content inside an inner class defined in a different method.
Sorry, wasn't paying attention to the invokeLater statement itself.
ASKER
Then how to make it work? Is it possible to do it?
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)
(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();
}
ASKER
// this way also works
public static void main(String[] args) {
if (args.length == 1){
String content = args[0];
createAndShowGUI(displayAr eaText);
}
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();
// }
// });
public static void main(String[] args) {
if (args.length == 1){
String content = args[0];
createAndShowGUI(displayAr
}
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
// public void run() {
// createAndShowGUI();
// }
// });
ASKER
I also try your method, it does not compile at all :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is how mine is defined:
public class Display implements ActionListener, Runnable
public class Display implements ActionListener, Runnable
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. :)
Open in new window