zoukankan      html  css  js  c++  java
  • JAVA在Eclipse里能运行,但是在cmd中却提示找不到主函数的错误【环境变量配置】

         在拷贝完java的jdk以后,配置环境变量,我以前一直以为,只要把%JAVA_HOME%\bin这个包含java.exe跟javac.exe的路径放到path环境变量中就好了。

         确实,这样配置完了以后已经可以在Eclipse中运行java程序了,但是在控制台中却运行不了,在网上查资料后发现,需要在环境变量Classpath中加入%JAVA_HOME%\lib\rt.jar;%JAVA_HOME%\lib\tools.jar;这样完了以后重启控制台,就能通过控制台编译运行正确的java程序了。

      还有个一问题:java引用同路径下的其他类,需要在classpath中加入"."的路径,这样java编译时才会查找当前路径的其他类。

         另外看到各种标准的文档还需要配置jre什么的,目前还没有发现作用是什么,以后发现了再补充、

         附能运行的java程序一个,如下:

         from:lianliankan.java

    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Random;
    import javax.swing.*;
    
    
    public class lianliankan implements ActionListener {
        JFrame mainFrame;
        Container thisContainer;
        JPanel centerPanel,southPanel,northPanel;
        JButton diamondsButton[][] = new JButton[6][5];
        JButton exitButton,resetButton,newlyButton;
        JLabel fractionLabel = new JLabel("0");
        JButton firstButton,secondButton;
        int i=0,j=0,k;
        int grid[][] = new int[6][5];
        static boolean pressInformation = false;
        int x0=0,y0=0,x=0,y=0,firstMsg=0,secondMsg=0,calidateLV;
        public void init(){
            mainFrame = new JFrame("JKJ连连看");
            thisContainer = mainFrame.getContentPane();
            thisContainer.setLayout(new BorderLayout());
            centerPanel = new JPanel();
            southPanel = new JPanel();
            northPanel = new JPanel();
            thisContainer.add(centerPanel,"Center");
            thisContainer.add(southPanel,"South");
            thisContainer.add(northPanel,"North");
            centerPanel.setLayout(new GridLayout(6,5));
            for(int cols=0; cols<6; cols++){
                for(int rows=0; rows<5; rows++){
                    diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols][rows]));
                    diamondsButton[cols][rows].addActionListener(this);
                    centerPanel.add(diamondsButton[cols][rows]);////
                }
            }
            exitButton = new JButton("退出");
            exitButton.addActionListener(this);
            resetButton = new JButton("重列");
            resetButton.addActionListener(this);
            newlyButton = new JButton("再来一局");
            newlyButton.addActionListener(this);
            southPanel.add(exitButton);
            southPanel.add(resetButton);
            southPanel.add(newlyButton);
            fractionLabel.setText(String.valueOf(Integer.parseInt(fractionLabel.getText())));
            northPanel.add(fractionLabel);
            mainFrame.setBounds(280,100,500,450);
            mainFrame.setVisible(true);
        }
        public void randomBuild(){
            int randoms = 0,rows = 0,cols = 0;
            for(int twins=1; twins<=15;twins++){
                Random rnd = new Random();
                randoms=rnd.nextInt(25)+1;
                for(int alike=1; alike<=2; alike++){
                    cols=rnd.nextInt(6);
                    rows=rnd.nextInt(5);
                    while(grid[cols][rows]!=0){
                        cols=rnd.nextInt(6);
                        rows=rnd.nextInt(5);
                    }
                    this.grid[cols][rows] = randoms;
                }
            }
        }
        public void fraction(){
            fractionLabel.setText(String.valueOf(Integer.parseInt(fractionLabel.getText())+100));
        }
        public void reload(){
            int save[] = new int[30];
            int n=0,cols,rows;
            int grid[][] = new int[6][5];
            for(int i=0; i<6; i++){
                for(int j=0; j<5; j++){
                    if(this.grid[i][j]!=0){
                        save[n] = this.grid[i][j];
                        n++;
                    }
                }
            }
            n=n-1;
            this.grid = grid;
            while(n>=0){
                Random rnd = new Random();
                cols=rnd.nextInt(6);
                rows=rnd.nextInt(5);
                while(grid[cols][rows]!=0){
                    cols=rnd.nextInt(6);
                    rows=rnd.nextInt(5);
                }
                this.grid[cols][rows]=save[n];
                n--;
            }
            mainFrame.setVisible(false);
            pressInformation=false;        //很重要,按钮信息归为初始。
            init();
            for(int i=0;i<6; i++){
                for(int j=0; j<5; j++){
                    if(grid[i][j]==0){
                        diamondsButton[i][j].setVisible(false);
                    }
                }
            }
        }
        public void estimateEven(int placeX,int placeY,JButton bz){
            if(pressInformation==false){
                x=placeX;
                y=placeY;
                secondMsg=grid[x][y];
                secondButton=bz;
                pressInformation=true;
            }
            else{
                x0=x;
                y0=y;
                firstMsg=secondMsg;
                firstButton=secondButton;
                x=placeX;
                y=placeY;
                secondMsg=grid[x][y];
                secondButton=bz;
                if(firstMsg==secondMsg&&secondButton!=firstButton){
                    xiao();
                }
            }
        }
        public void xiao(){                                    //内容相同的情况下能不能消去
            int n;
            if(x0==x&&(y0==y+1||y0==y-1)||((x0==x+1||x0==x-1)&&(y0==y)))
                remove();
            else{
                for(j=0; j<5; j++){
                    if(grid[x0][j]==0){//判断第一个按钮同行哪个按钮为空
                        if(y>j){//吐过第二个按钮的Y坐标大于空按钮的Y坐标说明第一个按钮在第二个的左边
                            for(i=y-1; i>=j; i--){//判断第二按钮左侧知道第一按钮中间有没有按钮
                                if(grid[x][i]!=0){
                                    k=0;
                                    break;
                                }
                                else
                                    k=1;//k=1说明通过了第一次验证
                            }
                            if(k==1){
                                linePassOne();
                            }
                        }
                        if(y<j){//如果第二个按钮的Y坐标小于空按钮的坐标,说明第一个在第二个的右边
                            for(i=y+1;i<=j;i++){//判断第二按钮错侧直到第一个按钮的中间有木有按钮
                                if(grid[x][i]!=0){
                                    k=0;
                                    break;
                                }
                                else
                                    k=1;
                            }
                            if(k==1)
                                linePassOne();
                        }
                        if(y==j)
                            linePassOne();
                    }
                if(k==2){//这里原本是k==2
                    if(x0==x){
                        remove();
                    }
                    if(x0<x){
                        for(n=x0; n<=x-1; n++){
                            if(grid[n][j]!=0){
                                k=0;
                                break;
                            }
                            if(grid[n][j]==0&&n==x-1){
                                remove();
                            }
                        }
                    }
                    if(x>x0){
                        for(n=x0; n>=x+1; n--){
                            if(grid[n][j]!=0){
                                k=0;
                                break;
                            }
                            if(grid[n][j]==0&&n==x+1){
                                remove();
                            }
                        }
                    }
                }
                }
            }
            for(i=0;i<6;i++){//
                if(grid[i][y0]==0){
                    if(x>i){
                        for(j=x-1; j>=i; j--){
                            if(grid[j][y]!=0){
                                k=0;
                                break;
                            }
                            else
                                k=1;
                        }
                        if(k==1){
                            rowPassOne();
                        }
                    }
                    if(x<i){
                        for(j=x+1; j<=i; j++){
                            if(grid[j][y]!=0){
                                k=0;
                                break;
                            }
                            else
                                k=1;
                        }
                        if(k==1)
                            rowPassOne();
                    }
                    if(x==i){
                        rowPassOne();
                    }
                }
                if(k==2){//原本是k==2
                    if(y0==y){
                        remove();
                    }
                    if(y0<y){
                        for(n=y0; n<=y-1; n++){
                            if(grid[i][n]!=0){
                                k=0;
                                break;
                            }
                            if(grid[i][n]==0&&n==y-1){
                                remove();
                            }
                        }
                    }
                    if(y0>y){
                        for(n=y0; n>=y+1; n--){
                            if(grid[i][n]!=0){
                                k=0;
                                break;
                            }
                            if(grid[i][n]==0&&n==y+1){
                                remove();
                            }
                        }
                    }
                }
            }
        }
        private void linePassOne(){
            if(y0>j){//第一行同行按钮在左边
                for(i=y0-1; i>=j; i--){//判断第一按钮左侧空按钮之间有木有按钮
                    if(grid[x0][i]!=0){
                        k=0;
                        break;
                    }
                    else
                        k=2;//k=2说明通过了第二次验证
                }
            }
            if(y0<j){//第一按钮同行空按钮在与第二按钮之间
                for(i=y0+1; i<=j; i++){
                    if(grid[x0][i]!=0){
                        k=0;
                        break;
                    }
                    else
                        k=2;
                }
            }
        }
        private void rowPassOne() {
            // TODO Auto-generated method stub
            if(x0>i){
                for(j=x0-1; j>=i; j--){
                    if(grid[j][y0]!=0){
                        k=0;
                        break;
                    }
                    else
                        k=2;
                }
            }
            if(x0<i){
                for(j=x0+1; j<=i; j++){
                    if(grid[j][y0]!=0){
                        k=0;
                        break;
                    }
                    else
                        k=2;
                }
            }
        }
        public void remove(){
            firstButton.setVisible(false);
            secondButton.setVisible(false);
            fraction();
            pressInformation=false;
            k=0;
            grid[x0][y0]=0;
            grid[x][y]=0;
        }
    
        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            if(e.getSource()==newlyButton){
                int grid[][] = new int[8][7];
                this.grid = grid;
                randomBuild();
                mainFrame.setVisible(false);
                pressInformation=false;
                init();
            }
            if(e.getSource()==exitButton){
                System.exit(0);
            }
            if(e.getSource()==resetButton){
                reload();
            }
            for(int cols=0; cols<6; cols++){
                for(int rows=0; rows<5; rows++){
                    if(e.getSource()==diamondsButton[cols][rows]){
                        estimateEven(cols,rows,diamondsButton[cols][rows]);
                    }
                }
            }
        }
    
        public static void main(String args[]){
            lianliankan llk = new lianliankan();
            llk.randomBuild();
            llk.init();
        }
    }

    如有错误,希望指正。

  • 相关阅读:
    tp5 url 线上访问 在nginx 上 出现404错误,解决办法(1.80nginx 配置 pathInfo)
    Windows下配置nginx+php(wnmp)
    windows向github提交代码
    改变图片尺寸
    mysql字符编码的设置以及mysql中文乱码的解决方法
    wamp升级php7
    C++Primer第五版——习题答案和解析
    Ubuntu16.04下安装显卡驱动记录
    Ubuntu环境下No module named '_tkinter'错误的解决
    TensorFlow:NameError: name ‘input_data’ is not defined
  • 原文地址:https://www.cnblogs.com/zhidian314/p/2872928.html
Copyright © 2011-2022 走看看