java小通信录的一个错误

wx3046 2009-05-30 05:39:18

下面是全部的代码
用的eclipse,错误提示:
java.lang.NoSuchMethodError: main
Exception in thread "main"

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

public class Tongxuelu extends JFrame
{
JPanel cp = new JPanel();
JTabbedPane jtp = new JTabbedPane(); //定义分页面板对象
JPanel jp1 = new JPanel(); //定义面板对象,做为分页使用
JPanel jp2 = new JPanel();
JPanel jp3 = new JPanel();

JButton jb2 = new JButton("请点击这里查看信息");
Label l2 = new Label(" 输入姓名: ");
Label l3 = new Label(" 输入电话:");
Label l4 = new Label(" 输入EMAIL:");
Label l5 = new Label(" 输入其他:");
TextField tf2 = new TextField(50);
TextField tf3 = new TextField(50);
TextField tf4 = new TextField(50);
TextField tf5 = new TextField(50);
JButton b3 = new JButton("录入",new ImageIcon("14.gif"));
JButton b4 = new JButton("清除",new ImageIcon("39.gif"));
TextArea ta1 = new TextArea("姓名 电话 EMAIL 其他 \n***** ******-****** *****@yahoo.com.cn 相信自己!去做事吧!一切都会有改变!!!\n ",18,40);

public Tongxuelu() //窗口Tongxuelu的构造函数
{
setTitle("****通讯系统欢迎欢迎您的光临!!!");
setSize(500,400);

this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});

Container cp = this.getContentPane(); //取得Tongxuelu类的容器框架
ImageIcon icon = new ImageIcon("middle.gif"); //定义图标

jp1.setLayout(new FlowLayout()); //设计jp1的布局
jp1.setBackground(Color.cyan);

jp1.add(l2);
jp1.add(tf2);
jp1.add(l3);
jp1.add(tf3);
jp1.add(l4);
jp1.add(tf4);
jp1.add(l5);
jp1.add(tf5);
jp1.add(b3);
jp1.add(b4);

b3.addActionListener(new qq());
b4.addActionListener(new kv()); //添加相应的监听者
jb2.addActionListener(new mm());

jp2.setLayout(new BorderLayout()); //设计jp2的布局
jp2.add("North",jb2);
jp2.add("Center",ta1);
jtp.add(jp1,0);
jtp.setTitleAt(0,"输入信息");

jtp.addTab("查看信息",icon,jp2,"落霞与孤鹜齐飞,秋水共长天一色");
jtp.setSelectedIndex(0);

jtp.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
jtpState(e);
}
});
cp.add(jtp);
}

class kv implements ActionListener{ //类kv用来实现“清除”功能
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == b4)
{
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
}
}
}

class qq implements ActionListener{ //类 qq用来实现将用户输入的数据写如到文件中
public void actionPerformed(ActionEvent e){
Object source = e.getSource();
if(source == b3)
try
{
File fw = new File("java123.doc");
RandomAccessFile out = new RandomAccessFile(fw,"rw");

if(fw.exists())
{
long length = fw.length();
out.seek(length);//定位文件读写指针到文件末尾,以免覆盖原来的数据;
}

if(tf2.getText().equals(""))
{
}

else
{
out.writeUTF(tf2.getText()+" "+tf3.getText()+" "+tf4.getText()+" "+tf5.getText());
out.close();
}
}
catch(IOException ee)
{
}
}
}

class mm implements ActionListener //类mm用来实现将数据从文件读如到文本区域中
{
public void actionPerformed(ActionEvent e)
{
String s = "";
Object source = e.getSource();
if(source == jb2)
{
try
{
int number = 1;
File fw = new File("java123.doc");
RandomAccessFile in = new RandomAccessFile(fw,"rw");
String xingming = null;
ta1.setText(null);

while((xingming = in.readUTF()) != null)
{
ta1.append("\n"+number+". " +xingming);
number++;
}

in.close();
}
catch(Exception ee)
{
}
}
}

public void main(String[] args)
{
Tongxuelu tabpane2 = new Tongxuelu();
tabpane2.setVisible(true);
}

void jtpState(ChangeEvent e) //处理ChangeEvent 事件的方法
{
String s = new String();
jp3 =(JPanel)jtp.getSelectedComponent(); //取得被选分页
}
}}
...全文
68 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wx3046 2009-06-02
  • 打赏
  • 举报
回复
那个大大帮我改一下代码,老改不对,谢谢
wx3046 2009-06-02
  • 打赏
  • 举报
回复
非常感谢
lwater1 2009-06-02
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wx3046 的回复:]
那个大大帮我改一下代码,老改不对,谢谢
[/Quote]




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

public class Tongxuelu extends JFrame
{
JPanel cp = new JPanel();
JTabbedPane jtp = new JTabbedPane(); //定义分页面板对象
JPanel jp1 = new JPanel(); //定义面板对象,做为分页使用
JPanel jp2 = new JPanel();
JPanel jp3 = new JPanel();

JButton jb2 = new JButton("请点击这里查看信息");
Label l2 = new Label(" 输入姓名: ");
Label l3 = new Label(" 输入电话:");
Label l4 = new Label(" 输入EMAIL:");
Label l5 = new Label(" 输入其他:");
TextField tf2 = new TextField(50);
TextField tf3 = new TextField(50);
TextField tf4 = new TextField(50);
TextField tf5 = new TextField(50);
JButton b3 = new JButton("录入",new ImageIcon("14.gif"));
JButton b4 = new JButton("清除",new ImageIcon("39.gif"));
TextArea ta1 = new TextArea("姓名 电话 EMAIL 其他 \n***** ******-****** *****@yahoo.com.cn 相信自己!去做事吧!一切都会有改变!!!\n ",18,40);

public Tongxuelu() //窗口Tongxuelu的构造函数
{
setTitle("****通讯系统欢迎欢迎您的光临!!!");
setSize(500,400);

this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});

Container cp = this.getContentPane(); //取得Tongxuelu类的容器框架
ImageIcon icon = new ImageIcon("middle.gif"); //定义图标

jp1.setLayout(new FlowLayout()); //设计jp1的布局
jp1.setBackground(Color.cyan);

jp1.add(l2);
jp1.add(tf2);
jp1.add(l3);
jp1.add(tf3);
jp1.add(l4);
jp1.add(tf4);
jp1.add(l5);
jp1.add(tf5);
jp1.add(b3);
jp1.add(b4);

b3.addActionListener(new qq());
b4.addActionListener(new kv()); //添加相应的监听者
jb2.addActionListener(new mm());

jp2.setLayout(new BorderLayout()); //设计jp2的布局
jp2.add("North",jb2);
jp2.add("Center",ta1);
jtp.add(jp1,0);
jtp.setTitleAt(0,"输入信息");

jtp.addTab("查看信息",icon,jp2,"落霞与孤鹜齐飞,秋水共长天一色");
jtp.setSelectedIndex(0);

jtp.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
jtpState(e);
}
});
cp.add(jtp);
}

class kv implements ActionListener{ //类kv用来实现“清除”功能
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == b4)
{
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
}
}
}

class qq implements ActionListener{ //类 qq用来实现将用户输入的数据写如到文件中
public void actionPerformed(ActionEvent e){
Object source = e.getSource();
if(source == b3)
try
{
File fw = new File("java123.doc");
RandomAccessFile out = new RandomAccessFile(fw,"rw");

if(fw.exists())
{
long length = fw.length();
out.seek(length);//定位文件读写指针到文件末尾,以免覆盖原来的数据;
}

if(tf2.getText().equals(""))
{
}

else
{
out.writeUTF(tf2.getText()+" "+tf3.getText()+" "+tf4.getText()+" "+tf5.getText());
out.close();
}
}
catch(IOException ee)
{
}
}
}

class mm implements ActionListener //类mm用来实现将数据从文件读如到文本区域中
{
public void actionPerformed(ActionEvent e)
{
String s = "";
Object source = e.getSource();
if(source == jb2)
{
try
{
int number = 1;
File fw = new File("java123.doc");
RandomAccessFile in = new RandomAccessFile(fw,"rw");
String xingming = null;
ta1.setText(null);

while((xingming = in.readUTF()) != null)
{
ta1.append("\n"+number+". " +xingming);
number++;
}

in.close();
}
catch(Exception ee)
{
}
}
}
} //少了个}
public static void main(String args[]) //加了static
{
Tongxuelu tabpane2 = new Tongxuelu();
tabpane2.setVisible(true);
}

void jtpState(ChangeEvent e) //处理ChangeEvent 事件的方法
{
String s = new String();
jp3 =(JPanel)jtp.getSelectedComponent(); //取得被选分页
}
}

wx3046 2009-06-01
  • 打赏
  • 举报
回复
能否具体点不..我看了还是不会改.main方法已经改成static了,那个括号是我故意加的,因为我不加括号他就提示结尾不正确了。.
一步一个脚印 2009-05-30
  • 打赏
  • 举报
回复

public static void main(String[] args) {
//....
}
你没有main函数,内部类mm倒是有个,你应该把mm.main(..)放到类似Tongxuelu.main(..)下
wanglingzhong 2009-05-30
  • 打赏
  • 举报
回复
还有你的内部类mm中括号加错位置了!
wanglingzhong 2009-05-30
  • 打赏
  • 举报
回复
main方法必须声明为static的

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧