Java 如何更新Jtextarea一次?(mysql端-?)
好的,我一直在尝试做的是找出如何做到这一点,当我按下程序上的搜索按钮时,当前刚刚打印到控制台的代码将打印到我拥有的文本区域。我不知道该怎么做,我搜索了谷歌,但仍然没有找到答案 在我这么做的时候,如果有人能帮我弄清楚如何将这行信息发送到mysql数据库,这将非常有帮助Java 如何更新Jtextarea一次?(mysql端-?),java,mysql,database,jtextarea,Java,Mysql,Database,Jtextarea,好的,我一直在尝试做的是找出如何做到这一点,当我按下程序上的搜索按钮时,当前刚刚打印到控制台的代码将打印到我拥有的文本区域。我不知道该怎么做,我搜索了谷歌,但仍然没有找到答案 在我这么做的时候,如果有人能帮我弄清楚如何将这行信息发送到mysql数据库,这将非常有帮助 package GTE; import java.awt.*; import java.io.IOException; import java.io.InputStream; import java.util.List; impor
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);
}
}
包GTE;
导入java.awt.*;
导入java.io.IOException;
导入java.io.InputStream;
导入java.util.List;
导入javax.swing.*;
导入twitter4j.*;
公共级GTE{
私人JFRMGTE;
公共字符串hashq=“…”;
公共字符串twtresults;
公共int刷新=1;
公共静态void main(字符串[]args){
invokeLater(new Runnable()){
公开募捐{
试一试{
GTE窗口=新的GTE();
window.frmGte.setVisible(true);
}捕获(例外e){}
}
});
}
/**
*创建应用程序。
*@抛出异常
*@FontFormatException
*/
公共GTE(){
试一试{
初始化();
}捕获(FontFormat异常){}
捕获(IOE){}
}
/**
*初始化框架的内容。
*@抛出异常
*@FontFormatException
*/
私有void initialize()引发FontFormatException,IOException{
frmGte=新的JFrame();
frmGte.setresizeable(false);
frmGte.SETTILE(“GTE”);
法国立法院(100100450390);
frmGte.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridBagLayout GridBagLayout=新的GridBagLayout();
gridBagLayout.columnWidths=newint[]{434,0};
gridBagLayout.rowHeights=newint[]{21,0,0,0,0,0,0};
gridBagLayout.columnWeights=新的double[]{0.0,double.MIN_值};
gridBagLayout.rowWeights=新的double[]{0.0,0.0,0.0,0.0,0.0,0.0,double.MIN_值};
frmGte.getContentPane().setLayout(gridBagLayout);
JLabel GTETitle=新的JLabel(“个人推特提取器”);
InputStream is=this.getClass().getResourceAsStream(“ultraviolentbb_reg.ttf”);
Font GTEFont=Font.createFont(Font.TRUETYPE\u Font,is);
Font f=GTEFont.deriveFont(24f);
GTETitle.setFont(f);
GTETitle.SET水平对齐(旋转恒量中心);
GridBagConstraints gbc_GTETitle=新的GridBagConstraints();
GBCgtetitle.insets=新的insets(0,0,5,0);
GBCgtetitle.anchor=GridBagConstraints.NORTH;
GBCgtetitle.fill=GridBagConstraints.HORIZONTAL;
gbcgtetitle.gridx=0;
gbcgtetitle.gridy=0;
frmGte.getContentPane().add(GTETitle,gbcgtetitle);
Label Label\u 2=新标签(“~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~”;
GridBagConstraints gbc_label_2=新的GridBagConstraints();
gbc_标签_2.插图=新插图(0,0,5,0);
gbc_label_2.gridx=0;
gbc_label_2.gridy=1;
frmGte.getContentPane().add(label_2,gbc_label_2);
JLabel SearchTweets=新的JLabel(“使用“+hashq+”:”)搜索Tweets;
GridBagConstraints gbc_SearchTweets=新的GridBagConstraints();
gbc_SearchTweets.insets=新的insets(0,0,5,0);
gbc_SearchTweets.gridx=0;
gbc_SearchTweets.gridy=2;
frmGte.getContentPane().add(SearchTweets,gbc_SearchTweets);
JLabel标签=新的JLabel(“#”);
GridBagConstraints GBCU label=新的GridBagConstraints();
gbc_label.insets=新的插入(0,0,5,0);
gbc_label.gridx=0;
gbc_label.gridy=3;
frmGte.getContentPane().add(标签,gbc_标签);
JButton Search=新JButton(“开始搜索”);
Search.addActionListener(新ActionListener(){
已执行的公共无效操作(操作事件evt){
TS(hashq);
GTE.this.refresh=0;
试一试{
nulll dialog=新的nulll();
setDefaultCloseOperation(JDialog.DISPOSE\u ON\u CLOSE);
对话框.setVisible(true);
}捕获(例外e){}
}
公共void TS(字符串标签){
Twitter=new TwitterFactory().getInstance();
试一试{
System.out.println(hashtag);
QueryResult result=twitter.search(新查询(“#”+hashtag));
List tweets=result.getTweets();
用于(Tweet-Tweet:tweets){
System.out.println(“@”+tweet.getFromUser()+”:“+tweet.getText());
GTE.this.twtresults=(“@”+tweet.getFromUser()+”:“+tweet.getText());
}
}捕获(twitter异常){
te.printStackTrace();
System.out.println(“未能搜索tweets:+te.getMessage());
系统退出(-1);
}
}
});
TextField TextField=新的TextField();
addActionListener(新ActionListener(){
已执行的公共无效操作(操作事件evt){
GTE.this.hashq=evt.getActionCommand();
}
});
GridBagConstraints gbc_textField=新的GridBagConstraints();
gbc_textField.ipadx=99;
gbc_textField.insets=新的insets(0,0,5,0);
gbc_textField.gridx=0;
gbc_textField.gridy=4;
frmGte.getContentPane().add(textField,gbc_textField);
GridBagConstraints gbc_Search=新的GridBagConstraints();
gbc_Search.insets=新的insets(0,0,5,0);
gbc_Search.gridx=0;
gbc_Search.gridy=5;
frmGte.getContentPane().add(搜索,gbc_搜索);
Label Label_1=新标签(“使用搜索结果搜索推文”);
GridBagConstraints gbc_label_1=新的GridBagConstraints();
gbc_标签_1.插图=新插图(0,0,5,0);
gbc_label_1.gridx=0;
gbc_标签_1.gridy=6;
frmGte.getContentPane().add(label_1,gbc_label_1);
TextArea TextArea=新建TextArea();
textArea.setText(twtresults);
textArea.setEditable(false);
GridBagConstraints gbc_textArea=新的GridBagConstraints();
gbc_textArea.gridx=0;
G
private JFrame frmGte;
private JTextArea textArea;
GTE.this.textArea.setText(GTE.this.twtresults)