java答题小程序代码 java答题软件( 四 )


}
}
}
ps:这是刚刚敲出来的 , 本来想优化下代码的,但是现在我要忙别的了(万分火急的),sorry , 希望采纳,给我个鼓励 。
JAVA小程序代码问题,求高手很简单啊,你这是个while循环,catch到这个exception以后提示重新输入,然后因为上一次的输入结果还在 , 所以当然还是会显示是高还是低了啊
应该改成先输入数字,再判断是高还是低
while(correctCount==0){
try{
userString=JOptionPane.showInputDialog("Start guessing, it's a number between 1 and 1000...");
userNumber=Integer.parseInt(userString);}
catch(NumberFormatExceptionex){
JOptionPane.showMessageDialog(null, "Please input a number",JOptionPane.WARNING_MESSAGE);
continue;
}
if((userNumberrightNumber)(userNumber1000)){
JOptionPane.showMessageDialog(null,"too high!");
count++;
}
else if((userNumberrightNumber)(userNumber0)){
JOptionPane.showMessageDialog(null,"too low!");
count++;
}
else if(userNumber0||userNumber1000)
JOptionPane.showMessageDialog(null,"Stupid Guy",JOptionPane.WARNING_MESSAGE);
else
JOptionPane.showMessageDialog(null, "Please input a number",JOptionPane.WARNING_MESSAGE);
if (userNumber==rightNumber){
count++;
correctCount++;
}
}
求java小程序代码,500行左右 。。大作业用 。追加50import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class mypanel extends Panel implements MouseListener
{
int chess[][] = new int[11][11];
boolean Is_Black_True;
mypanel()
{
Is_Black_True = true;
for(int i = 0;i11;i++)
{
for(int j = 0;j11;j++)
{
chess[i][j] = 0;
}
}
addMouseListener(this);
setBackground(Color.BLUE);
setBounds(0, 0, 360, 360);
setVisible(true);
}
public void mousePressed(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
if(x25 || x330 + 25 ||y25 || y330+25)
{
return;
}
if(chess[x/30-1][y/30-1] != 0)
{
return;
}
if(Is_Black_True == true)
{
chess[x/30-1][y/30-1] = 1;
Is_Black_True = false;
repaint();
Justisewiner();
return;
}
if(Is_Black_True == false)
{
chess[x/30-1][y/30-1] = 2;
Is_Black_True = true;
repaint();
Justisewiner();
return;
}
}
void Drawline(Graphics g)
{
for(int i = 30;i = 330;i += 30)
{
for(int j = 30;j = 330; j+= 30)
{
g.setColor(Color.WHITE);
g.drawLine(i, j, i, 330);
}
}
for(int j = 30;j = 330;j += 30)
{
g.setColor(Color.WHITE);
g.drawLine(30, j, 330, j);
}
}
void Drawchess(Graphics g)
{
for(int i = 0;i11;i++)
{
for(int j = 0;j11;j++)
{
if(chess[i][j] == 1)
{
g.setColor(Color.BLACK);
g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);
}
if(chess[i][j] == 2)
{
g.setColor(Color.WHITE);
g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);
}
}
}
}
void Justisewiner()
{
int black_count = 0;
int white_count = 0;
int i = 0;
for(i = 0;i11;i++)//横向判断
{
for(int j = 0;j11;j++)
{
if(chess[i][j] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i][j] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");

推荐阅读