java无法实例化类型_java – 无法实例化类型actionlistener?

import org.jsoup.Jsoup;

@SuppressWarnings("unused")

public class SimpleWebCrawler extends JFrame implements ActionListener {

JTextField yourInputField = new JTextField(20);

static JTextArea _resultArea = new JTextArea(200, 200);

JScrollPane scrollingArea = new JScrollPane(_resultArea);

private final static String newline = "

";

JButton jButton = new JButton("Send Text");

public SimpleWebCrawler() throws MalformedURLException {

yourInputField.addActionListener(new ActionListener());

class MyActionListener implements ActionListener {

public void actionPerformed(ActionEvent evt) {

JTextField textfield = (JTextField)evt.getSource();

process(textfield.getText());

}

}

String word2 = yourInputField.getText();

_resultArea.setEditable(false);

try {

URL my_url = new URL("http://" + word2 + "/");

BufferedReader br = new BufferedReader(new InputStreamReader(

my_url.openStream()));

String strTemp = "";

while (null != (strTemp = br.readLine())) {

_resultArea.append(strTemp + newline);

}

} catch (Exception ex) {

ex.printStackTrace();

}

_resultArea.append("

");

_resultArea.append("

");

_resultArea.append("

");

String url = "http://" + word2 + "/";

print("Fetching %s...", url);

try{

Document doc = Jsoup.connect(url).get();

Elements links = doc.select("a[href]");

System.out.println("

");

BufferedWriter bw = new BufferedWriter(new

FileWriter("C:\Users\user\fypworkspace\FYP\Link\abc.txt"));

_resultArea.append("

");

for (Element link : links) {

print(" %s ", link.attr("abs:href"), trim(link.text(), 35));

bw.write(link.attr("abs:href"));

bw.write(System.getProperty("line.separator"));

}

bw.flush();

bw.close();

} catch (IOException e1) {

}

JPanel content = new JPanel();

content.setLayout(new BorderLayout());

content.add(scrollingArea, BorderLayout.CENTER);

content.add(yourInputField,BorderLayout.SOUTH);

content.add(jButton, BorderLayout.EAST);

this.setContentPane(content);

this.setTitle("Crawled Links");

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.pack();

}

private static void print(String msg, Object... args) {

_resultArea.append(String.format(msg, args) +newline);

}

private static String trim(String s, int width) {

if (s.length() > width)

return s.substring(0, width - 1) + ".";

else

return s;

}

//.. Get the content pane, set layout, add to center

public static void main(String[] args) throws IOException {

JFrame win = new SimpleWebCrawler();

win.setVisible(true);

}

}

我得到这个错误无法实例化类型actionlistener.代码行是:

yourInputField.addActionListener(new ActionListener());

class MyActionListener implements ActionListener {

public void actionPerformed(ActionEvent evt) {

JTextField textfield = (JTextField)evt.getSource();

process(textfield.getText());

}

}

我正在尝试创建一个JTextField来接收来自用户的输入.仍然不成功.什么导致错误?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值