| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6722 人关注过本帖
标题:'class' or 'interface' expected这是什么错误啊(具体在8楼)
只看楼主 加入收藏
Sieben7
Rank: 2
等 级:论坛游民
帖 子:116
专家分:20
注 册:2007-4-16
收藏
 问题点数:0 回复次数:9 
'class' or 'interface' expected这是什么错误啊(具体在8楼)

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.Container.*;

public class WeightConApplication extends JFrame
{
private JFrame mainFrame;
private JButton exitButton;
private JTextField inputField;
private JTextField messageField;
private JLabel inputLabel;

public WeightConApplication()
{
mainFrame=new JFrame("WeightConApplication");
ConButton=new JButton("Convert");
inputLabel=new JLabel("Input weight");
inputField=new JTextField(20);

Container c=mainFrame.getContentPane();
c.setLayout(new FlowLayout());

c.add(inputLabel);
c.add(inputField);
c.add(ConButton);
c.add(messageField);

mainFrame.setSize(250,125);
}

}

public static void main(String args[])
{
new WeightConApplication();
}


编译后显示:Z:\WeightConApplication.java:34: 'class' or 'interface' expected
public static void main(String args[])
^
1 error

请问这是什么意思啊?路过的大牛们请教,:-)

[此贴子已经被作者于2007-5-13 21:57:39编辑过]

搜索更多相关主题的帖子: interface class expected import awt 
2007-05-11 19:53
菜鸟上路
Rank: 4
等 级:贵宾
威 望:14
帖 子:1120
专家分:0
注 册:2006-3-21
收藏
得分:0 
public static void main(String args[])
{
new WeightConApplication();
}
要写在public class WeightConApplication extends JFrame内部
还有ConButton没定义

2007-05-11 19:59
Sieben7
Rank: 2
等 级:论坛游民
帖 子:116
专家分:20
注 册:2007-4-16
收藏
得分:0 

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.Container.*;

public class WeightConApplication extends JFrame implements TextListener
{
private JFrame mainFrame;
private JButton ConButton;
private JTextField inputField;
private JTextField messageField;
private JLabel inputLabel;

public WeightConApplication()
{
mainFrame=new JFrame("WeightConApplication");
ConButton=new JButton("Convert");
inputLabel=new JLabel("Input weight");
inputField=new JTextField(20);

Container c=mainFrame.getContentPane();
c.setLayout(new FlowLayout());

c.add(inputLabel);
c.add(inputField);
c.add(ConButton);
c.add(messageField);

mainFrame.setSize(250,125);
}

public static void main(String args[])
{
new WeightConApplication();
}

}



Z:\WeightConApplication.java:6: WeightConApplication is not abstract and does not override abstract method textValueChanged(java.awt.event.TextEvent) in java.awt.event.TextListener
public class WeightConApplication extends JFrame implements TextListener
^
1 error

我又不明白了,java真难学啊- -||
2007-05-11 20:11
flyboatzgc
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2006-9-25
收藏
得分:0 
实现TextListener应该还有一个

对应的方法吧

2007-05-11 20:35
Sieben7
Rank: 2
等 级:论坛游民
帖 子:116
专家分:20
注 册:2007-4-16
收藏
得分:0 
回复:(Sieben7)\'class\' or \'interface\' expected这...

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.Container.*;

public class WeightConApplication extends JFrame //implements TextListener
{
private JFrame mainFrame;
private JButton ConButton;
private JTextField inputField;
private JTextField messageField;
private JLabel inputLabel;

public WeightConApplication()
{
mainFrame=new JFrame("WeightConApplication");
ConButton=new JButton("Convert");
inputLabel=new JLabel("Input weight");
inputField=new JTextField(20);

Container c=mainFrame.getContentPane();
c.setLayout(new FlowLayout());

c.add(inputLabel);
c.add(inputField);
c.add(ConButton);
c.add(messageField);

mainFrame.setSize(250,125);
}

public static void main(String args[])
{
new WeightConApplication();
}

}



这样可以编译,不过在3楼的问题我还是不知道是什么意思。
2007-05-11 20:40
Sieben7
Rank: 2
等 级:论坛游民
帖 子:116
专家分:20
注 册:2007-4-16
收藏
得分:0 
回复:(Sieben7)\'class\' or \'interface\' expected这...

其实这道问题是这样的:
编写java独立应用程序,接收人在地球上体重,输出他在月球上的体重。

(1) 月球上人的体重是在地球上体重的1/6

(2) 定义可实例化类 ,以实现人在地球上的体重与在月球上体重的转换。

(3) 使用图形用户界面组件标签、文本框、按钮。

(4) 处理输入错误的情况。


我的代码如下:



import java.awt.event.*;
import java.awt.*;

public class WeightConApplication extends Frame implements ActionListener,WindowListener{
public Frame mainFrame;
public Button ConButton;
public TextField inputField;
public TextField messageField;
public Label inputLabel;


WeightConApplication()
{
setLayout(new FlowLayout());
inputField=new TextField(20);
inputLabel=new Label("Input weight");
ConButton=new Button("Convert");

add(ConButton);
add(inputField);
add(messageField);
add(inputLabel);

ConButton.addActionListener(this);
setBounds(100,100,150,150);
setVisible(true);

//mainFrame.setSize(250,125);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
validate();

}


public static void main(String args[])
{
System.out.println("Starting WeightConApplication...");
WeightConApplication mainFrame = new WeightConApplication();
mainFrame.setSize(400, 400);
mainFrame.setTitle("WeightConApplication");
mainFrame.setVisible(true);
}


public void actionPerformed(ActionEvent exception)
{

try{
if(exception.getSource()==ConButton){
messageField.setText(Double.parseDouble(inputField.getText())/6);
}
}
catch(NumberFormatException e)
{
messageField.setText("非法字符");}
}
}



编译后有两个错误:
Z:\WeightConApplication.java:4: WeightConApplication is not abstract and does not override abstract method windowDeactivated(java.awt.event.WindowEvent) in java.awt.event.WindowListener
public class WeightConApplication extends Frame implements ActionListener,WindowListener{
^
Z:\WeightConApplication.java:55: cannot find symbol
symbol : method setText(double)
location: class java.awt.TextField
messageField.setText(Double.parseDouble(inputField.getText())/6);
^
2 errors


热心的斑斑或者路过的大牛们能够指点指点,我实在是没办法。java书上的例子很容易看懂,一到自己动手了就开始不行了。
2007-05-11 21:51
风月_无边
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:60
帖 子:2960
专家分:652
注 册:2007-1-19
收藏
得分:0 
1.WindowListener接口的抽象方法需要实现
2.messageField.setText(String );参数是string型!

我的网站 http://www.
2007-05-11 22:09
Sieben7
Rank: 2
等 级:论坛游民
帖 子:116
专家分:20
注 册:2007-4-16
收藏
得分:0 
回复:(Sieben7)\'class\' or \'interface\' expected这...

import java.awt.event.*;
import java.awt.*;

public class WeightConApplication extends Frame implements ActionListener{
public static void main(String args[])
{
System.out.println("Starting WeightConApplication...");
new WeightConApplication();
WeightConApplication mainFrame = new WeightConApplication();
mainFrame.setSize(400, 400);
mainFrame.setTitle("WeightConApplication");
mainFrame.setVisible(true);
}
public Button ConButton;
public TextArea inputField;
public TextArea messageField;
public Label inputLabel;


WeightConApplication()
{
setLayout(new FlowLayout());
inputField=new TextArea(6,15);
inputLabel=new Label("Input weight");
ConButton=new Button("Convert");

inputField=new TextArea(6,15);
messageField=new TextArea(6,15);

add(ConButton);
add(inputField);
add(messageField);
add(inputLabel);

setBounds(100,100,300,300);
setVisible(true);
ConButton.addActionListener(this);
setBounds(100,100,150,150);
validate();

}
public void actionPerformed(ActionEvent e)
{
messageField.append(Double.valueOf(inputField.getText())/6); //这里出了问题?
}

}


7楼的问题我考虑了,可是还是没有搞定这题- -||||

Z:\WeightConApplication.java:44: append(java.lang.String) in java.awt.TextArea cannot be applied to (double)
messageField.append(Double.valueOf(inputField.getText())/6);
^
1 error

说是不能转化成double型?

[此贴子已经被作者于2007-5-13 21:56:36编辑过]

2007-05-13 21:54
zhufeifei
Rank: 1
等 级:新手上路
威 望:2
帖 子:402
专家分:0
注 册:2006-8-11
收藏
得分:0 
public void actionPerformed(ActionEvent e)
{
Double m=Double.valueOf(inputField.getText())/6;
String n=m.toString();
messageField.append(n); //这里出了问题?
}
JField.append(String a),将其计算出的Double数据转换成字符串?
建议:异常要处理,加入关闭JFrame的代码setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

在不断的拼搏与进取中,定能创造一片天地!
2007-05-13 22:58
Sieben7
Rank: 2
等 级:论坛游民
帖 子:116
专家分:20
注 册:2007-4-16
收藏
得分:0 
和JField有什么关系,呵呵我没用swing组件啊。嗯,知道问题出现哪里了,谢谢大家!谢谢斑斑!

[此贴子已经被作者于2007-5-14 19:00:31编辑过]


2007-05-14 18:58
快速回复:'class' or 'interface' expected这是什么错误啊(具体在8楼)
数据加载中...
 
   



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

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