原因:这是因为安装java时把jdk的路径和jre的路径选择成一样,就造成覆盖了,这时候你在lib下也找不都toolsjar和dtjar
解决:
如果只需要使用javac命令其实不需要这么复杂的,可以直接把新建的JAVA_HOME、CLASSPATH这两个变量和PATH变量中的JAVA_HOME%\bin;%JAVA_HOME%\jre\bin删了,然后在Path变量的头部添加如下路径:
C:\Program Files\Java\jdk150\bin;就可以了。
扩展资料:
关于上述中配置的path
配置系统变量path,在里边加入路径值
;%JAVA_HOME%/bin;%JAVA_HOME%/jre/bin;(加在中间的配置方式为,即C:\Program Files (x86)\Common Files\Oracle\Java\javapath)
%JAVA_HOME%/bin;%JAVA_HOME%/jre/bin;(加在首部)
;%JAVA_HOME%/bin;%JAVA_HOME%/jre/bin(加在尾部)
贪吃蛇程序:
GreedSnakejava (也是程序入口):
import javaawtBorderLayout;
import javaawtCanvas;
import javaawtColor;
import javaawtContainer;
import javaawtGraphics;
import javaawteventKeyEvent;
import javaawteventKeyListener;
import javautilIterator;
import javautilLinkedList;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJPanel;
public class GreedSnake implements KeyListener {
JFrame mainFrame;
Canvas paintCanvas;
JLabel labelScore;// 计分牌
SnakeModel snakeModel = null;// 蛇
public static final int canvasWidth = 200;
public static final int canvasHeight = 300;
public static final int nodeWidth = 10;
public static final int nodeHeight = 10;
// ----------------------------------------------------------------------
// GreedSnake():初始化游戏界面
// ----------------------------------------------------------------------
public GreedSnake() {
// 设置界面元素
mainFrame = new JFrame("GreedSnake");
Container cp = mainFramegetContentPane();
labelScore = new JLabel("Score:");
cpadd(labelScore, BorderLayoutNORTH);
paintCanvas = new Canvas();
paintCanvassetSize(canvasWidth + 1, canvasHeight + 1);
paintCanvasaddKeyListener(this);
cpadd(paintCanvas, BorderLayoutCENTER);
JPanel panelButtom = new JPanel();
panelButtomsetLayout(new BorderLayout());
JLabel labelHelp;// 帮助信息
labelHelp = new JLabel("PageUp, PageDown for speed;", JLabelCENTER);
panelButtomadd(labelHelp, BorderLayoutNORTH);
labelHelp = new JLabel("ENTER or R or S for start;", JLabelCENTER);
panelButtomadd(labelHelp, BorderLayoutCENTER);
labelHelp = new JLabel("SPACE or P for pause", JLabelCENTER);
panelButtomadd(labelHelp, BorderLayoutSOUTH);
cpadd(panelButtom, BorderLayoutSOUTH);
mainFrameaddKeyListener(this);
mainFramepack();
mainFramesetResizable(false);
mainFramesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
mainFramesetVisible(true);
begin();
}
// ----------------------------------------------------------------------
// keyPressed():按键检测
// ----------------------------------------------------------------------
public void keyPressed(KeyEvent e) {
int keyCode = egetKeyCode();
if (snakeModelrunning)
switch (keyCode) {
case KeyEventVK_UP:
snakeModelchangeDirection(SnakeModelUP);
break;
case KeyEventVK_DOWN:
snakeModelchangeDirection(SnakeModelDOWN);
break;
case KeyEventVK_LEFT:
snakeModelchangeDirection(SnakeModelLEFT);
break;
case KeyEventVK_RIGHT:
snakeModelchangeDirection(SnakeModelRIGHT);
break;
case KeyEventVK_ADD:
case KeyEventVK_PAGE_UP:
snakeModelspeedUp();// 加速
break;
case KeyEventVK_SUBTRACT:
case KeyEventVK_PAGE_DOWN:
snakeModelspeedDown();// 减速
break;
case KeyEventVK_SPACE:
case KeyEventVK_P:
snakeModelchangePauseState();// 暂停或继续
break;
default:
}
// 重新开始
if (keyCode == KeyEventVK_R || keyCode == KeyEventVK_S
|| keyCode == KeyEventVK_ENTER) {
snakeModelrunning = false;
begin();
}
}
// ----------------------------------------------------------------------
// keyReleased():空函数
// ----------------------------------------------------------------------
public void keyReleased(KeyEvent e) {
}
// ----------------------------------------------------------------------
// keyTyped():空函数
// ----------------------------------------------------------------------
public void keyTyped(KeyEvent e) {
}
// ----------------------------------------------------------------------
// repaint():绘制游戏界面(包括蛇和食物)
// ----------------------------------------------------------------------
void repaint() {
Graphics g = paintCanvasgetGraphics();
// draw background
gsetColor(ColorWHITE);
gfillRect(0, 0, canvasWidth, canvasHeight);
// draw the snake
gsetColor(ColorBLACK);
LinkedList na = snakeModelnodeArray;
Iterator it = naiterator();
while (ithasNext()) {
Node n = (Node) itnext();
drawNode(g, n);
}
// draw the food
gsetColor(ColorRED);
Node n = snakeModelfood;
drawNode(g, n);
updateScore();
}
// ----------------------------------------------------------------------
// drawNode():绘画某一结点(蛇身或食物)
// ----------------------------------------------------------------------
private void drawNode(Graphics g, Node n) {
gfillRect(nx nodeWidth, ny nodeHeight, nodeWidth - 1,
nodeHeight - 1);
}
// ----------------------------------------------------------------------
// updateScore():改变计分牌
// ----------------------------------------------------------------------
public void updateScore() {
String s = "Score: " + snakeModelscore;
labelScoresetText(s);
}
// ----------------------------------------------------------------------
// begin():游戏开始,放置贪吃蛇
// ----------------------------------------------------------------------
void begin() {
if (snakeModel == null || !snakeModelrunning) {
snakeModel = new SnakeModel(this, canvasWidth / nodeWidth,
thiscanvasHeight / nodeHeight);
(new Thread(snakeModel))start();
}
}
// ----------------------------------------------------------------------
// main():主函数
// ----------------------------------------------------------------------
public static void main(String[] args) {
GreedSnake gs = new GreedSnake();
}
}
Nodejava:
public class Node {
int x;
int y;
Node(int x, int y) {
thisx = x;
thisy = y;
}
}
SnakeModeljava:
import javautilArrays;
import javautilLinkedList;
import javautilRandom;
import javaxswingJOptionPane;
public class SnakeModel implements Runnable {
GreedSnake gs;
boolean[][] matrix;// 界面数据保存在数组里
LinkedList nodeArray = new LinkedList();
Node food;
int maxX;// 最大宽度
int maxY;// 最大长度
int direction = 2;// 方向
boolean running = false;
int timeInterval = 200;// 间隔时间(速度)
double speedChangeRate = 075;// 速度改变程度
boolean paused = false;// 游戏状态
int score = 0;
int countMove = 0;
// UP和DOWN是偶数,RIGHT和LEFT是奇数
public static final int UP = 2;
public static final int DOWN = 4;
public static final int LEFT = 1;
public static final int RIGHT = 3;
// ----------------------------------------------------------------------
// GreedModel():初始化界面
// ----------------------------------------------------------------------
public SnakeModel(GreedSnake gs, int maxX, int maxY) {
thisgs = gs;
thismaxX = maxX;
thismaxY = maxY;
matrix = new boolean[maxX][];
for (int i = 0; i < maxX; ++i) {
matrix[i] = new boolean[maxY];
Arraysfill(matrix[i], false);// 没有蛇和食物的地区置false
}
// 初始化贪吃蛇
int initArrayLength = maxX > 20 10 : maxX / 2;
for (int i = 0; i < initArrayLength; ++i) {
int x = maxX / 2 + i;
int y = maxY / 2;
nodeArrayaddLast(new Node(x, y));
matrix[x][y] = true;// 蛇身处置true
}
food = createFood();
matrix[foodx][foody] = true;// 食物处置true
}
// ----------------------------------------------------------------------
// changeDirection():改变运动方向
// ----------------------------------------------------------------------
public void changeDirection(int newDirection) {
if (direction % 2 != newDirection % 2)// 避免冲突
{
direction = newDirection;
}
}
// ----------------------------------------------------------------------
// moveOn():贪吃蛇运动函数
// ----------------------------------------------------------------------
public boolean moveOn() {
Node n = (Node) nodeArraygetFirst();
int x = nx;
int y = ny;
switch (direction) {
case UP:
y--;
break;
case DOWN:
y++;
break;
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
}
if ((0 <= x && x < maxX) && (0 <= y && y < maxY)) {
if (matrix[x][y])// 吃到食物或者撞到身体
{
if (x == foodx && y == foody)// 吃到食物
{
nodeArrayaddFirst(food);// 在头部加上一结点
// 计分规则与移动长度和速度有关
int scoreGet = (10000 - 200 countMove) / timeInterval;
score += scoreGet > 0 scoreGet : 10;
countMove = 0;
food = createFood();
matrix[foodx][foody] = true;
return true;
} else
return false;// 撞到身体
} else// 什么都没有碰到
{
nodeArrayaddFirst(new Node(x, y));// 加上头部
matrix[x][y] = true;
n = (Node) nodeArrayremoveLast();// 去掉尾部
matrix[nx][ny] = false;
countMove++;
return true;
}
}
return false;// 越界(撞到墙壁)
}
// ----------------------------------------------------------------------
// run():贪吃蛇运动线程
// ----------------------------------------------------------------------
public void run() {
running = true;
while (running) {
try {
Threadsleep(timeInterval);
} catch (Exception e) {
break;
}
if (!paused) {
if (moveOn())// 未结束
{
gsrepaint();
} else// 游戏结束
{
JOptionPaneshowMessageDialog(null, "GAME OVER",
"Game Over", JOptionPaneINFORMATION_MESSAGE);
break;
}
}
}
running = false;
}
// ----------------------------------------------------------------------
// createFood():生成食物及放置地点
// ----------------------------------------------------------------------
private Node createFood() {
int x = 0;
int y = 0;
do {
Random r = new Random();
x = rnextInt(maxX);
y = rnextInt(maxY);
} while (matrix[x][y]);
return new Node(x, y);
}
// ----------------------------------------------------------------------
// speedUp():加快蛇运动速度
// ----------------------------------------------------------------------
public void speedUp() {
timeInterval = speedChangeRate;
}
// ----------------------------------------------------------------------
// speedDown():放慢蛇运动速度
// ----------------------------------------------------------------------
public void speedDown() {
timeInterval /= speedChangeRate;
}
// ----------------------------------------------------------------------
// changePauseState(): 改变游戏状态(暂停或继续)
// ----------------------------------------------------------------------
public void changePauseState() {
paused = !paused;
}
}
/
输出
@param year 年份
/
private void output(int year){
boolean bo = false; //是否是闰年
if (year % 4 == 0 && year % 400 == 0){
bo = true;
}
for (int i = 1; i <= 12; i++){
for (int n = 0; n < 3; n++){
Systemoutprintln("2017年" + i + "月" + n + "3日");
Systemoutprintln("2017年" + i + "月" + n + "6日");
if (bo && i == 2){
Systemoutprintln("2017年" + i + "月" + n + "9日");
}
}
}
}
以上就是关于java 显示不是内部或外部命令,也不是可运行程序全部的内容,包括:java 显示不是内部或外部命令,也不是可运行程序、用JAVA编一个小游戏或者其他程序、java 写一程序在控制台输出,今年所有日期尾号是3,6,9的日期.如:3号,6号,9号等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)