Reputation:
This is the full code if anyone can help, I'm basically attempting to make a email availability checker. All I want is too put the variable line into my Jlist so it will output all the emails and be removed from JList if that email has been checked.
class main{
public static void main(String[] args) throws InterruptedException {
gui.gui();
}
}
|
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
class tuna {
public static void tuna() throws InterruptedException, FileNotFoundException {
WebDriver driver = new ChromeDriver();
try (BufferedReader br = new BufferedReader(new FileReader("emails.txt"))) {
String line;
while ((line = br.readLine()) != null) {
driver.get("https://signup.live.com/signup?wa=wsignin1.0&rpsnv=12&ct=1465840004&rver=6.7.6643.0&wp=&wreply=https%3a%2f%2fwww.msn.com%2fen-us%2fhomepage%2fSecure%2fPassport%3fru%3dhttp%253a%252f%252fwww.msn.com%252f%253focid%253dmailsignout%2526pfr%253d1&id=1184&pcexp=True&bk=1465840005&uiflavor=web&uaid=dc151162984741948b8371ce3e0c865e&mkt=EN-US&lc=1033&lic=1");
WebElement Email = driver.findElement(By.id("MemberName"));
WebElement Refresher = driver.findElement(By.id("FirstName"));
WebElement TakenErrorMsg = driver.findElement(By.id("MemberNameError"));
Email.sendKeys(line);
Refresher.click();
Thread.sleep(650);
if (TakenErrorMsg.isDisplayed()) {
System.out.println(line + " is taken!");
} else {
System.out.println(line + " is not taken!");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
public class gui extends JFrame {
public static void gui() {
JLabel label1 = new JLabel("Hotmail availability checker");
label1.setVisible(true);
label1.setSize(250, 250);
label1.setLocation(165, -100);
JLabel label2 = new JLabel("Emails unchecked");
label2.setVisible(true);
label2.setSize(250, 240);
label2.setLocation(40, -82);
JButton b1 = new JButton("Start");
b1.setSize(200,50);
b1.setLocation(140, 300);
b1.setVisible(true);
JScrollPane scrollPane = new JScrollPane();
final DefaultListModel emailsChecked = new DefaultListModel();
emailsChecked.addElement("AAA");
final JList list = new JList(emailsChecked);
list.setVisible(true);
list.setVisible(true);
list.setLocation(20,50);
list.setSize(150,200);
scrollPane.setViewportView(list);
JFrame frames = new JFrame();
frames.setTitle("Hotmail availability checker");
frames.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frames.setLayout(null);
frames.setVisible(true);
frames.setSize(500, 400);
frames.setLocationRelativeTo(null);
frames.add(b1);
frames.add(label1);
frames.add(list);
frames.add(label2);
frames.add(scrollPane);
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
tuna.tuna();
} catch (InterruptedException e1) {
e1.printStackTrace();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
});
}
}
Upvotes: 2
Views: 165
Reputation: 718758
If line
is a local variable declared in another method, then you cannot access it from your main
method.
Local variables in methods are only accessible (in limited circumstances) from classes that are declared within the scope of the local variable; e.g. using an anonymous inner class. That is clearly not applicable from a main
method.
I don't know what to suggest as a solution, but there is clearly something rather wrong with the design of your application if one method needs to see the local variables of another method.
Upvotes: 3