swing和线程的问题

世界上最厉害的程序员 2018-01-05 02:47:58
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次到页面上显示出来
...全文
265 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sunyiban 2018-01-05
  • 打赏
  • 举报
回复
developer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent paramActionEvent) { int a = Integer.parseInt(fscsText.getText()); int b = Integer.parseInt(fxplText.getText()); try { String word = getFile("F:/test.txt"); for (int i = 0; i < a * b; i++) { text.append(word + "\n"); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); 加个能输出呀~
Sunyiban 2018-01-05
  • 打赏
  • 举报
回复
你的btn都没绑定点击事件吧
  • 打赏
  • 举报
回复
没有一个人会的吗

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧