Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java可运行文件,带文件读取器_Java_Eclipse_Runnable - Fatal编程技术网

Java可运行文件,带文件读取器

Java可运行文件,带文件读取器,java,eclipse,runnable,Java,Eclipse,Runnable,当我尝试在eclipse中创建java可运行文件时,我的类没有出现在启动配置列表中?如何修复该问题以创建可运行文件。我希望能够在任何地方执行我的程序 import java.applet.Applet; import java.awt.Color; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader

当我尝试在eclipse中创建java可运行文件时,我的类没有出现在启动配置列表中?如何修复该问题以创建可运行文件。我希望能够在任何地方执行我的程序

import java.applet.Applet;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.event.AncestorListener;




public class StartActivity extends Applet implements ActionListener{
/**
 * 
 */
private static final long serialVersionUID = -1470898831456146593L;
private JTextField textField;
public JTextField[] textStock = new JTextField[190];
public tags[] tags = new tags[90];
public String[] tg = new String[90];
public JList set = new JList();

   public StartActivity(){

    }
public void init() {

    setSize(1800, 950); // create an instance 
    setBackground(Color.gray);
    setFocusable(true);
    setLayout(null);

    FileReader file = null; // get the tags and their name
    FileReader file2 = null;
    try {
        file = new FileReader("resource/tagsName.txt");
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    BufferedReader br = new BufferedReader(file);
    try {
        file2 = new FileReader("resource/ref.txt");
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    BufferedReader br2 = new BufferedReader(file2);



    //      textField = new JTextField();
    //      textField.setBounds(35, 136, 86, 20);
    //      add(textField);
    //      textField.setColumns(10);
    int x = 35;
    int  y= 136;

    for (int i=0 ; i < 190 ; i++){ // add the text field to enter the quote
        textStock[i] = new JTextField("");
        textStock[i].setBounds(x,y,86,20);
        add(textStock[i]);
        textStock[i].setColumns(10);
        y = y + 25;
        if (y > 900){
            y = 136;
            x = x + 91;
        }
    }

    JLabel label1 = new JLabel("Enter Stock Symbols");
    label1.setBounds((x-35)/2, 100, 200, 20);
    add(label1);

    //addKeyListener(this);


    String tg = "";
    String rf = "";
    x = x + 200;
    y= 136;
    int i = 0;
    int  z = x;
    try { // 
        while((tg = br.readLine()) != null){ // add textfields to enter their tags
            rf =br2.readLine();
            tags[i] = new tags(tg, rf); // tags are a separte method that has their own info
            tags[i].setBounds(x, y, 200, 23); // tags are declared as buttons
            add(tags[i]);
            y = y + 28;
            if (y > 900){
                y = 136;
                x = x + 205;
            }
            tg = "";
            i = i +1;
        }
    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    try {
        br.close();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    JLabel label2 = new JLabel("Choose stock tags Retrival");
    label2.setBounds((x+z)/2, 100, 200, 20);
    add(label2);

    //set = new JList();

    JButton list1= new JButton("List 1");
    list1.setBounds(35, 100, 89, 23);
    list1.addActionListener(this);
    add(list1);

    JButton run = new JButton("Run");
    run.setBounds(getWidth()/2, 32, 89, 23);
    run.addActionListener(this);
    add(run);

    JButton analyse = new JButton("Analyse");
    analyse.setBounds(getWidth()/2 - 200, 32, 89, 23);
    analyse.addActionListener(this);
    add(analyse);

    Frame frame = (Frame) this.getParent().getParent();
    frame.setTitle(" Financial Analysis");
    try {

    } catch (Exception e) {
        // TODO: handle exception
    }


}




public void actionPerformed(ActionEvent arg0) {
    // TODO Auto-generated method stub 
    /**
     * call method depending on their button
     */

    System.out.println(arg0.getActionCommand());
    if (arg0.getActionCommand()== "Run"){
        stockdata();
    }
    //System.out.println("true");
    if (arg0.getActionCommand()== "List 1"){
        listSet(1);
    }
    if (arg0.getActionCommand()== "Analyse"){
        choose();
        System.out.println(arg0.getActionCommand());
    }
}

private void choose() {
    /*
     * analyse quotes with parameters that I choose
     */
    int m =0;
    String[]   quotes = new String[200];
    int s =0;
    String[]  tq = new String[20];
        String qurl = "http://finance.yahoo.com/d/quotes.csv?s=";
        for (int i=0 ; i < 60 ; i++){
            String stock =textStock[i].getText();
            if (m == 0 && stock != ""){
                qurl = qurl + stock ;
                m =1 ;
                quotes[s] = stock;
                s=s+1;
            }
            else if(stock != ""){
                qurl = qurl +"+"+ stock ;
                quotes[s] = stock;
                s=s+1;
            }
        }
        qurl = qurl + "&f=l1vhgd1rp6";

        System.out.println(qurl);
        Analysis tab = new Analysis(qurl, quotes); // param are declared in another method
        tab.setVisible(true);
}

private void stockdata() {

    /*
     * retrieves stock data 
     */
int m =0;
String[]  tq = new String[20];
String[]   quotes = new String[200];
int s =0;
    String qurl = "http://finance.yahoo.com/d/quotes.csv?s=";
    for (int i=0 ; i < 60 ; i++){
        String stock =textStock[i].getText();
        if (m == 0 && stock != ""){
            qurl = qurl + stock ;
            quotes[s] = stock;
            s=s+1;
            m =1 ;
        }
        else if(stock != ""){
            qurl = qurl +"+"+ stock ;
            quotes[s] = stock;
            //System.out.println(quotes[s]);
            s=s+1;
        }
    }
    qurl = qurl + "&f=";
    int z =0;
    for (int i=0 ; i < 60 ; i++){
        if(tags[i].getStatus()){
            qurl = qurl + tags[i].getReference();
            tq[z]= tags[i].getName();
            z =z+1;
        }

    }   

    System.out.println(qurl);
    // this method retrives data and creates a table to show them
    StockData tab = new StockData(qurl, tq, quotes);
    tab.setVisible(true);
}
private void listSet(int fileNumber){
    // this method populates a set of stocks
    FileReader file = null;

    try {
        file = new FileReader("resource/set"+fileNumber + ".txt");
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    BufferedReader br = new BufferedReader(file);
    String tg;
    int i = 0;
    try {
        while((tg = br.readLine()) != null){
            if (i<190){
                textStock[i].setText(tg);
                i = i +1;

            }}
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public static void main( String args[] )
{
    // Create an instance of the test application

}

}
import java.applet.applet;
导入java.awt.Color;
导入java.awt.Frame;
导入java.awt.event.ActionEvent;
导入java.awt.event.ActionListener;
导入java.io.BufferedReader;
导入java.io.FileNotFoundException;
导入java.io.FileReader;
导入java.io.IOException;
导入javax.swing.JApplet;
导入javax.swing.JButton;
导入javax.swing.JLabel;
导入javax.swing.JList;
导入javax.swing.JTextField;
导入javax.swing.event.AncestorListener;
公共类StartActivity扩展小程序实现ActionListener{
/**
* 
*/
私有静态最终长serialVersionUID=-1470898831456146593L;
私有JTextField textField;
公共JTextField[]textStock=新JTextField[190];
公共标签[]标签=新标签[90];
公共字符串[]tg=新字符串[90];
public JList set=new JList();
公众意识(){
}
公共void init(){
setSize(1800950);//创建一个实例
挫折背景(颜色:灰色);
设置聚焦(真);
setLayout(空);
FileReader file=null;//获取标记及其名称
FileReader file2=null;
试一试{
file=newfilereader(“resource/tagsName.txt”);
}捕获(FileNotFoundException e1){
//TODO自动生成的捕捉块
e1.printStackTrace();
}
BufferedReader br=新的BufferedReader(文件);
试一试{
file2=新的文件阅读器(“resource/ref.txt”);
}捕获(FileNotFoundException e1){
//TODO自动生成的捕捉块
e1.printStackTrace();
}
BufferedReader br2=新的BufferedReader(文件2);
//textField=新的JTextField();
//textField.setBounds(35,136,86,20);
//添加(文本字段);
//textField.setColumns(10);
int x=35;
int y=136;
对于(inti=0;i<190;i++){//添加文本字段以输入引号
textStock[i]=新的JTextField(“”);
textStock[i].setBounds(x,y,86,20);
添加(textStock[i]);
textStock[i].setColumns(10);
y=y+25;
如果(y>900){
y=136;
x=x+91;
}
}
JLabel label1=新的JLabel(“输入股票符号”);
标签1.立根((x-35)/2100、200、20);
添加(标签1);
//addKeyListener(此);
字符串tg=“”;
字符串rf=“”;
x=x+200;
y=136;
int i=0;
int z=x;
试试{//
而((tg=br.readLine())!=null){//添加文本字段以输入它们的标记
rf=br2.readLine();
tags[i]=新标签(tg,rf);//标签是一种有自己信息的分离方法
标记[i].setBounds(x,y,200,23);//标记声明为按钮
添加(标签[i]);
y=y+28;
如果(y>900){
y=136;
x=x+205;
}
tg=“”;
i=i+1;
}
}捕获(IOE2异常){
//TODO自动生成的捕捉块
e2.printStackTrace();
}
试一试{
br.close();
}捕获(IOE1异常){
//TODO自动生成的捕捉块
e1.printStackTrace();
}
JLabel label2=新的JLabel(“选择股票标签检索”);
标签2.立根((x+z)/2100、200、20);
添加(标签2);
//set=new JList();
JButton list1=新JButton(“列表1”);
清单1.挫折(35100,89,23);
列表1.addActionListener(此);
添加(列表1);
JButton run=新JButton(“run”);
run.setBounds(getWidth()/2,32,89,23);
run.addActionListener(this);
添加(运行);
JButton analysis=新JButton(“analysis”);
分析.setBounds(getWidth()/2-200,32,89,23);
analysis.addActionListener(this);
添加(分析);
Frame Frame=(Frame)this.getParent().getParent();
框架.setTitle(“财务分析”);
试一试{
}捕获(例外e){
//TODO:处理异常
}
}
已执行的公共无效操作(操作事件arg0){
//TODO自动生成的方法存根
/**
*根据按钮调用方法
*/
System.out.println(arg0.getActionCommand());
如果(arg0.getActionCommand()=“运行”){
stockdata();
}
//System.out.println(“真”);
如果(arg0.getActionCommand()=“列表1”){
列表集(1);
}
如果(arg0.getActionCommand()=“分析”){
选择();
System.out.println(arg0.getActionCommand());
}
}
私有void choose(){
/*
*使用我选择的参数分析引号
*/
int m=0;
字符串[]引号=新字符串[200];
int s=0;
字符串[]tq=新字符串[20];
字符串qurl=”http://finance.yahoo.com/d/quotes.csv?s=";
对于(int i=0;i<60;i++){
字符串stock=textStock[i].getText();
如果(m==0&&stock!=“”){
qurl=qurl+库存;
m=1;
报价=股票;
s=s+1;
}
else if(股票!=“”){
qurl=qurl+“+”+股票;
报价=股票;
s=s+1;
}
}
qurl=qurl+“&f=l1vhgd1rp6”;
系统输出打印项次(qurl);
分析选项卡=新分析(qurl,quotes);//参数在另一个方法中声明
tab.setVisible(true);
}
私有void stockdata(){
/*
*检索股票数据
*/
int m=0;
字符串[]tq=新字符串[20];
字符串[]引号=新字符串[200];
int s=0;
字符串qurl=”http://finance.yahoo.com/d/quotes.csv?s=";
对于(int i=0;i<60;i++){
字符串stock=textStock[i].getText();
如果(m==0&&stock!=“”){
qurl=qurl+库存;
报价=股票;
s=s+1;
m=1;
}
else if(股票!=“”){
qurl=qurl+“+”+股票;
报价=股票;
//系统输出打印Ln(quo
   public class StartActivity extends JFrame implements ActionListener{
/**
 * 
 */
private static final long serialVersionUID = -1470898831456146593L;
private JTextField textField;
public JTextField[] textStock = new JTextField[190];
public tags[] tags = new tags[90];
public String[] tg = new String[90];
public JList set = new JList();

    public StartActivity(){

    setSize(1800, 950); // create an instance 
    setBackground(Color.gray);


    FileReader file = null; // get the tags and their name
    FileReader file2 = null;
    try {

        file = new FileReader("src/resource/tagsName.txt");
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    BufferedReader br = new BufferedReader(file);
    try {
        file2 = new FileReader("src/resource/ref.txt");
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    BufferedReader br2 = new BufferedReader(file2);



    //      textField = new JTextField();
    //      textField.setBounds(35, 136, 86, 20);
    //      add(textField);
    //      textField.setColumns(10);
    int x = 35;
    int  y= 136;

    for (int i=0 ; i < 190 ; i++){ // add the text field to enter the quote
        textStock[i] = new JTextField("");
        textStock[i].setBounds(x,y,86,20);
        add(textStock[i]);
        textStock[i].setColumns(10);
        y = y + 25;
        if (y > 900){
            y = 136;
            x = x + 91;
        }
    }

    JLabel label1 = new JLabel("Enter Stock Symbols");
    label1.setBounds((x-35)/2, 100, 200, 20);
    add(label1);

    //addKeyListener(this);


    String tg = "";
    String rf = "";
    x = x + 200;
    y= 136;
    int i = 0;
    int  z = x;
    try { // 
        while((tg = br.readLine()) != null){ // add textfields to enter their tags
            rf =br2.readLine();
            tags[i] = new tags(tg, rf); // tags are a separte method that has 
            tags[i].setBounds(x, y, 200, 23); // tags are declared as buttons
            add(tags[i]);
            y = y + 28;
            if (y > 900){
                y = 136;
                x = x + 205;
            }
            tg = "";
            i = i +1;
        }
    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    try {
        br.close();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    JLabel label2 = new JLabel("Choose stock tags Retrival");
    label2.setBounds((x+z)/2, 100, 200, 20);
    add(label2);

    //set = new JList();

    JButton list1= new JButton("List 1");
    list1.setBounds(35, 100, 89, 23);
    list1.addActionListener(this);
    add(list1);

    JButton run = new JButton("Run");
    run.setBounds(getWidth()/2, 32, 89, 23);
    run.addActionListener(this);
    add(run);

    JButton analyse = new JButton("Analyse");
    analyse.setBounds(getWidth()/2 - 200, 32, 89, 23);
    analyse.addActionListener(this);
    add(analyse);

    //Frame frame = (Frame) this.getParent().getParent();
    //frame.setTitle(" Financial Analysis");
    try {

    } catch (Exception e) {
        // TODO: handle exception
    }


}




public void actionPerformed(ActionEvent arg0) {
    // TODO Auto-generated method stub 
    /**
     * call method depending on their button
     */

    System.out.println(arg0.getActionCommand());
    if (arg0.getActionCommand()== "Run"){
        stockdata();
    }
    //System.out.println("true");
    if (arg0.getActionCommand()== "List 1"){
        listSet(1);
    }
    if (arg0.getActionCommand()== "Analyse"){
        choose();
        System.out.println(arg0.getActionCommand());
    }
}

private void choose() {
    /*
     * analyse quotes with parameters that I choose
     */
    int m =0;
    String[]   quotes = new String[200];
    int s =0;
    String[]  tq = new String[20];
        String qurl = "http://finance.yahoo.com/d/quotes.csv?s=";
        for (int i=0 ; i < 60 ; i++){
            String stock =textStock[i].getText();
            if (m == 0 && stock != ""){
                qurl = qurl + stock ;
                m =1 ;
                quotes[s] = stock;
                s=s+1;
            }
            else if(stock != ""){
                qurl = qurl +"+"+ stock ;
                quotes[s] = stock;
                s=s+1;
            }
        }
        qurl = qurl + "&f=l1vhgd1rp6";

        System.out.println(qurl);
        Analysis tab = new Analysis(qurl, quotes); // param are declared in another                
        tab.setVisible(true);
}

private void stockdata() {

    /*
     * retrieves stock data 
     */
int m =0;
String[]  tq = new String[20];
String[]   quotes = new String[200];
int s =0;
    String qurl = "http://finance.yahoo.com/d/quotes.csv?s=";
    for (int i=0 ; i < 60 ; i++){
        String stock =textStock[i].getText();
        if (m == 0 && stock != ""){
            qurl = qurl + stock ;
            quotes[s] = stock;
            s=s+1;
            m =1 ;
        }
        else if(stock != ""){
            qurl = qurl +"+"+ stock ;
            quotes[s] = stock;
            //System.out.println(quotes[s]);
            s=s+1;
        }
    }
    qurl = qurl + "&f=";
    int z =0;
    for (int i=0 ; i < 60 ; i++){
        if(tags[i].getStatus()){
            qurl = qurl + tags[i].getReference();
            tq[z]= tags[i].getName();
            z =z+1;
        }

    }   

    System.out.println(qurl);
    // this method retrives data and creates a table to show them
    StockData tab = new StockData(qurl, tq, quotes);
    tab.setVisible(true);
}
private void listSet(int fileNumber){
    // this method populates a set of stocks
    FileReader file = null;

    try {
        file = new FileReader("src/resource/set"+fileNumber + ".txt");
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    BufferedReader br = new BufferedReader(file);
    String tg;
    int i = 0;
    try {
        while((tg = br.readLine()) != null){
            if (i<190){
                textStock[i].setText(tg);
                i = i +1;

            }}
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public static void main( String args[] )
{
    StartActivity mainFrame = new StartActivity();
    mainFrame.setVisible( true );

}

}