| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 542 人关注过本帖
标题:[求助]语法问题:这样定义变量有什么问题?
取消只看楼主 加入收藏
zhybgy
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-3-19
收藏
 问题点数:0 回复次数:1 
[求助]语法问题:这样定义变量有什么问题?

代码是这样的:
import javax.swing.*;
import java.awt.*;

class NoHelloWorldPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawString("not a hello world program",MESSAGE_X,MESSAGE_Y);

public static final int MESSAGE_X = 75;
public static final int MESSAGE_Y = 100;


}
}

class NoHelloWorldFrame extends JFrame
{
public NoHelloWorldFrame()
{
setTitle("Not Hello World!!");
setSize(WIDTH,HEIGHT);
NoHelloWorldPanel panel = new NoHelloWorldPanel();
Container contentpane = getContentPane();
contentpane.add(panel);
}
public static final int WIDTH= 300;
public static final int HEIGHT = 200;

}

public class NoHelloWorld
{
public static void main(String [] args)
{
NoHelloWorldFrame frame = new NoHelloWorldFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}

以上代码在编译的时候提示如下错误:
illegal start of expression public static final int MESSAGE_X = 75;
illegal start of expression public static final int MESSAGE_Y= 100
但是如果把代码中划线的两行注释了。改为 g.drawString("not a hello world program",70,100);

是可以通过编译并运行的。
这是怎么回事啊??


搜索更多相关主题的帖子: 变量 语法 定义 
2006-03-19 14:24
zhybgy
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-3-19
收藏
得分:0 
static 怎么了?能说的详细点吗?
去掉STATIC还是不行啊
2006-03-19 14:47
快速回复:[求助]语法问题:这样定义变量有什么问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015203 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved