swing和线程的问题
package com.JTabberPane;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.filechooser.FileNameExtensionFilter;
public class MainFrame extends JFrame {
JTextArea text;
public void init() {
JFrame frame = new JFrame();
frame.setBounds(100, 100, 600, 200);
frame.setTitle("IMT模拟工具");
JPanel jpane = new JPanel();
jpane.setBounds(10, 10, 60, 80);
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 10, 10);
jpane.setLayout(f1);
Choice choice = new Choice();
choice.setBounds(100, 100, 500, 10);
choice.setPreferredSize(new Dimension(200, 20));
choice.add("DATA-TSS-0017");
choice.add("DATA-TSS-0024");
choice.add("DATA-TSS-0020");
choice.add("DATA-TSS-0025");
choice.add("DATA-TSS-0022");
choice.add("DATA-TSS-0018");
choice.add("DATA-TSS-0023");
choice.add("DATA-TSS-0019");
choice.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
String string = e.paramString();
String str = string.substring(string.indexOf("item") + 5, string.indexOf("stateChange") - 1);
String a = str + ".txt";
String path = "F:\\Users\\Dell\\nenoworkspace\\Swing\\MetaObjects\\";
// MainFrame main = new MainFrame();
// JTextArea text = new JTextArea();
try {
text.setText(getFile(path + a));
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
jpane.add(choice);
JLabel fxplLabel = new JLabel("发送频率:");
fxplLabel.setFont(new Font("微软雅黑", 1, 14));
fxplLabel.setBounds(220, 12, 100, 20);
JTextField fxplText = new JTextField();
fxplText.setBounds(290, 12, 100, 20);
JLabel fscsLabel = new JLabel("发送次数:");
fscsLabel.setFont(new Font("微软雅黑", 1, 14));
fscsLabel.setBounds(400, 12, 100, 20);
JTextField fscsText = new JTextField();
fscsText.setBounds(470, 12, 100, 20);
JLabel fssdLabel = new JLabel("发送速度");
fssdLabel.setFont(new Font("微软雅黑", 1, 14));
fssdLabel.setBounds(10, 35, 60, 50);
JButton developer = new JButton("发送");
developer.setBounds(450, 50, 100, 20);
text = new JTextArea();
text.setBounds(0, 75, 580, 80);
// String a = "DATA-TSS-0017" + ".txt";
//
// String path = "F:\\Users\\Dell\\nenoworkspace\\Swing\\MetaObjects\\"
// + a;
// MainFrame main = new MainFrame();
// try {
// text.setText(main.getFile(path));
// } catch (Exception e) {
// e.printStackTrace();
// }
frame.add(fxplLabel);
frame.add(fxplText);
frame.add(fscsLabel);
frame.add(fscsText);
frame.add(fssdLabel);
frame.add(developer);
frame.add(text);
frame.add(jpane);
frame.setVisible(true);
}
public String getFile(String filepath) throws IOException {
File file = new File(filepath);
FileInputStream fis = new FileInputStream(file);
BufferedReader buffereReader = new BufferedReader(new InputStreamReader(fis));
StringBuffer str = new StringBuffer("");
String tempstr = buffereReader.readLine();
while (tempstr != null) {
str.append(tempstr);
tempstr = buffereReader.readLine();
}
buffereReader.close();
return str.toString();
}
public static void main(String[] args) {
MainFrame mainframe = new MainFrame();
mainframe.init();
}
}
我的问题就是在发送频率和发送次数的文本框中输入数字 然后点击发送,然后将下拉框下面对应的txt文件发送之后的内容显示在页面上,发送的就是对应txt里面的内容,简单点说 发送10次点击发送然后页面上会将对应的txt文件内容复制10次到页面上显示出来