Хорошо, я пытался выяснить, как это сделать, так что, когда я нажимаю кнопку поиска в моей программе, код, который в данный момент только выводится на консоль, будет печататься в имеющейся у меня текстовой области. Я не могу понять, как это сделать, я искал в Google и до сих пор не нашел ответа.
И пока я на этом, если кто-нибудь может помочь мне выяснить, как отправить эту же строку информации в базу данных mysql, которая очень поможет.
package GTE;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import javax.swing.*;
import twitter4j.*;
public class GTE {
private JFrame frmGte;
public String hashq = "...";
public String twtresults;
public int refresh = 1;
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
GTE window = new GTE();
window.frmGte.setVisible(true);
} catch (Exception e) {}
}
});
}
/**
* Create the application.
* @throws IOException
* @throws FontFormatException
*/
public GTE(){
try {
initialize();
} catch (FontFormatException e) {}
catch (IOException e) {}
}
/**
* Initialize the contents of the frame.
* @throws IOException
* @throws FontFormatException
*/
private void initialize() throws FontFormatException, IOException {
frmGte = new JFrame();
frmGte.setResizable(false);
frmGte.setTitle("GTE");
frmGte.setBounds(100, 100, 450, 390);
frmGte.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{434, 0};
gridBagLayout.rowHeights = new int[]{21, 0, 0, 0, 0, 0, 0, 0, 0};
gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE};
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
frmGte.getContentPane().setLayout(gridBagLayout);
JLabel GTETitle = new JLabel("Personal Tweet Extractor");
InputStream is = this.getClass().getResourceAsStream("ultraviolentbb_reg.ttf");
Font GTEFont = Font.createFont(Font.TRUETYPE_FONT,is);
Font f = GTEFont.deriveFont(24f);
GTETitle.setFont(f);
GTETitle.setHorizontalAlignment(SwingConstants.CENTER);
GridBagConstraints gbc_GTETitle = new GridBagConstraints();
gbc_GTETitle.insets = new Insets(0, 0, 5, 0);
gbc_GTETitle.anchor = GridBagConstraints.NORTH;
gbc_GTETitle.fill = GridBagConstraints.HORIZONTAL;
gbc_GTETitle.gridx = 0;
gbc_GTETitle.gridy = 0;
frmGte.getContentPane().add(GTETitle, gbc_GTETitle);
Label label_2 = new Label("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
GridBagConstraints gbc_label_2 = new GridBagConstraints();
gbc_label_2.insets = new Insets(0, 0, 5, 0);
gbc_label_2.gridx = 0;
gbc_label_2.gridy = 1;
frmGte.getContentPane().add(label_2, gbc_label_2);
JLabel SearchTweets = new JLabel("Search For Tweets With" + hashq + ":");
GridBagConstraints gbc_SearchTweets = new GridBagConstraints();
gbc_SearchTweets.insets = new Insets(0, 0, 5, 0);
gbc_SearchTweets.gridx = 0;
gbc_SearchTweets.gridy = 2;
frmGte.getContentPane().add(SearchTweets, gbc_SearchTweets);
JLabel label = new JLabel("#");
GridBagConstraints gbc_label = new GridBagConstraints();
gbc_label.insets = new Insets(0, 0, 5, 0);
gbc_label.gridx = 0;
gbc_label.gridy = 3;
frmGte.getContentPane().add(label, gbc_label);
JButton Search = new JButton("Start Search");
Search.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
TS(hashq);
GTE.this.refresh = 0;
try {
nulll dialog = new nulll();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {}
}
public void TS(String hashtag){
Twitter twitter = new TwitterFactory().getInstance();
try {
System.out.println(hashtag);
QueryResult result = twitter.search(new Query("#" + hashtag));
List<Tweet> tweets = result.getTweets();
for (Tweet tweet : tweets) {
System.out.println("@" + tweet.getFromUser() + " : " + tweet.getText());
GTE.this.twtresults = ("@" + tweet.getFromUser() + " : " + tweet.getText());
}
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to search tweets: " + te.getMessage());
System.exit(-1);
}
}
});
TextField textField = new TextField();
textField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
GTE.this.hashq = evt.getActionCommand();
}
});
GridBagConstraints gbc_textField = new GridBagConstraints();
gbc_textField.ipadx = 99;
gbc_textField.insets = new Insets(0, 0, 5, 0);
gbc_textField.gridx = 0;
gbc_textField.gridy = 4;
frmGte.getContentPane().add(textField, gbc_textField);
GridBagConstraints gbc_Search = new GridBagConstraints();
gbc_Search.insets = new Insets(0, 0, 5, 0);
gbc_Search.gridx = 0;
gbc_Search.gridy = 5;
frmGte.getContentPane().add(Search, gbc_Search);
Label label_1 = new Label("Search Results For Tweets With");
GridBagConstraints gbc_label_1 = new GridBagConstraints();
gbc_label_1.insets = new Insets(0, 0, 5, 0);
gbc_label_1.gridx = 0;
gbc_label_1.gridy = 6;
frmGte.getContentPane().add(label_1, gbc_label_1);
TextArea textArea = new TextArea();
textArea.setText(twtresults);
textArea.setEditable(false);
GridBagConstraints gbc_textArea = new GridBagConstraints();
gbc_textArea.gridx = 0;
gbc_textArea.gridy = 7;
frmGte.getContentPane().add(textArea, gbc_textArea);
JMenuBar menuBar = new JMenuBar();
frmGte.setJMenuBar(menuBar);
JMenu Filemenu = new JMenu("File");
menuBar.add(Filemenu);
JMenuItem Exititem = new JMenuItem("Exit");
Exititem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
System.exit(0);
}
});
Filemenu.add(Exititem);
JMenu Helpmenu = new JMenu("Help");
menuBar.add(Helpmenu);
JMenuItem Aboutitem = new JMenuItem("About");
Helpmenu.add(Aboutitem);
}
}