Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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
为什么HTML标记在我的java程序中不起作用?_Java_Html - Fatal编程技术网

为什么HTML标记在我的java程序中不起作用?

为什么HTML标记在我的java程序中不起作用?,java,html,Java,Html,这一行: array[x][y].setText("<html><font color = black>0</font></html>"); 有人知道我能做什么吗?我正在设置JButton的文本,我使用html标记,而不是setForeground(),因为setForeground()在disabled-setEnabled(false)按钮上不起作用 下面是它的完整部分,如果它有帮助的话: public void reveal(int x

这一行:

array[x][y].setText("<html><font color = black>0</font></html>");
有人知道我能做什么吗?我正在设置JButton的文本,我使用html标记,而不是setForeground(),因为setForeground()在disabled-setEnabled(false)按钮上不起作用

下面是它的完整部分,如果它有帮助的话:

  public void reveal(int x, int y)
  {
     array[x][y].setEnabled(false);
     array[x][y].setBackground(gray);

     int p = Integer.parseInt(array[x][y].getText());               
     switch(p){
        case 0: array[x][y].setText("<html><font color = black>0</font></html>");       
           zero(x, y);
           break;
        case 1: array[x][y].setText("<html><font color = red>1</font></html>"); 
           break;
        case 2: array[x][y].setText("<html><font color = blue>2</font></html>"); 
           break;
        case 3: array[x][y].setText("<html><font color = green>3</font></html>"); 
           break;
        case 4: array[x][y].setText("<html><font color = purple>4</font></html>"); 
           break;
        case 5: array[x][y].setText("<html><font color = pink>5</font></html>"); 
           break;
        case 6: array[x][y].setText("<html><font color = brown>6</font></html>"); 
           break;
        case 7: array[x][y].setText("<html><font color = yellow>7</font></html>"); 
           break;
        case 8: array[x][y].setText("<html><font color = orange>8</font></html>"); 
           break;
        case 9:
           remove(board);
           revalidate();
           repaint();
           end.setText("Ouch. You hit a bomb!");
           add(end, BorderLayout.CENTER);
           break;
     }
public void discover(整数x,整数y)
{
数组[x][y].setEnabled(false);
阵列[x][y]。背景(灰色);
int p=Integer.parseInt(数组[x][y].getText());
开关(p){
案例0:array[x][y].setText(“0”);
零(x,y);
打破
案例1:array[x][y].setText(“1”);
打破
案例2:数组[x][y].setText(“2”);
打破
案例3:数组[x][y].setText(“3”);
打破
案例4:数组[x][y].setText(“4”);
打破
案例5:数组[x][y].setText(“5”);
打破
案例6:数组[x][y].setText(“6”);
打破
案例7:数组[x][y].setText(“7”);
打破
案例8:数组[x][y].setText(“8”);
打破
案例9:
移除(板);
重新验证();
重新油漆();
end.setText(“哎哟,你撞到炸弹了!”);
添加(结束,边框布局。中心);
打破
}

有人知道我能做什么吗?

你提到你的JButtons被禁用了。你考虑过使用
setDisabledIcon(Icon disabledIcon)
?你所需要的只是一个图标(可以是纯色)。

你提到你的JButtons被禁用了。你考虑过使用
setDisabledIcon(Icon disabledIcon)吗
?您只需要一个图标(可以是纯色).

我不确定是否在Java中使用html,但您是否尝试过用引号写颜色标记?据我所知,您将它们用于html标记属性。@在这种情况下,OP显然应该使用单引号,或者转义双引号。我不确定是否在Java中使用html,但您是否尝试过用引号写颜色标记引号中的RK?据我所知,您将它们用于html标记属性。@在这种情况下,OP应该使用单引号,或者转义双引号。可能是
  public void reveal(int x, int y)
  {
     array[x][y].setEnabled(false);
     array[x][y].setBackground(gray);

     int p = Integer.parseInt(array[x][y].getText());               
     switch(p){
        case 0: array[x][y].setText("<html><font color = black>0</font></html>");       
           zero(x, y);
           break;
        case 1: array[x][y].setText("<html><font color = red>1</font></html>"); 
           break;
        case 2: array[x][y].setText("<html><font color = blue>2</font></html>"); 
           break;
        case 3: array[x][y].setText("<html><font color = green>3</font></html>"); 
           break;
        case 4: array[x][y].setText("<html><font color = purple>4</font></html>"); 
           break;
        case 5: array[x][y].setText("<html><font color = pink>5</font></html>"); 
           break;
        case 6: array[x][y].setText("<html><font color = brown>6</font></html>"); 
           break;
        case 7: array[x][y].setText("<html><font color = yellow>7</font></html>"); 
           break;
        case 8: array[x][y].setText("<html><font color = orange>8</font></html>"); 
           break;
        case 9:
           remove(board);
           revalidate();
           repaint();
           end.setText("Ouch. You hit a bomb!");
           add(end, BorderLayout.CENTER);
           break;
     }