I have a class named Parser which gets some input and do some calculations and output the results. I also have a jFrame, which has some text fields. I am misunderstanding how to run the parser and use the inputs from the jFrame. I don't know if I should implement the action Listener in my Parser class? or should I import all my Parser class methods in the jFrame? should I have run method in my main of the Parser or should I use the void run in the jframe class??
Here is my class Parser:
public class Parser{
public static List getXKeywords(String Url, int X, String html) throws Exception {
//somemethod with someoutput
}
public static void main(String[] args) throws Exception {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
SpyBiteDemo Sp = new SpyBiteDemo();
Sp.setVisible(true);
int X=Sp.getKeywordcount();
//this top line is not correct because it can only be done when the jframe jButton1 was clicked
}
});
}
}
and here is the jFrame;
public class SpyBiteDemo extends javax.swing.JFrame {
/**
* Creates new form SpyBiteDemo
*/
public SpyBiteDemo() {
initComponents();
}
public String getKeywordcount()
{
return jTextField4.getText();
}
//some methods
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//get the input from the jframe
//feed it to the parser?? how???
String SeedUrl=jTextField1.getText();
Parser P=new Parser();
//I don't have access to methods
because they are static
}
}
here I am trying to get keywordcount variable from the jFrame which is the int X in the getXKeywords method.
I solved my problem with the help of this link
I created a constructor in my parser class and also included a jframe in the parser class as follow:
public class Parser {
SpyBiteDemo Sp=new SpyBiteDemo();
public Parser(SpyBiteDemo Sp)
{
this.Sp=Sp;
int X = Sp.getXKeywords();
//do whatever
}
and in the action performed of the jframe class I call my parser constructor class:
public class SpyBiteDemo extends javax.swing.JFrame {
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Parser P=new Parser(this);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.