当前位置: 代码迷 >> Java相关 >> 编译通不过了.
  详细解决方案

编译通不过了.

热度:130   发布时间:2007-01-19 18:25:00.0
编译通不过了.

import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Example10_12
{ public static void main(String args[])
{ new CommFrame();
}
}
class InputArea extends Panel implements ActionListener
{ File f=null;
RandomAccessFile out;
Box baseBox,boxV1,boxV2;
TextField name,email,phone;
Button button;
InputArea(File f)
{ setBackground(Color.cyan);
this.f=f;
name=new TextField(12);
email=new TextField(12);
phone=new TextField(12);
button=new Button("录入");
button.addActionListener(this);
boxV1=Box.createVerticalBox();
boxV1.add(new Label("输入姓名"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("输入email"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("输入电话"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("单击录入"));
boxV2=Box.createVerticalBox();
boxV2.add(name);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(email);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(phone);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(button);
boxV2.add(Box.createVerticalStrut(8));
baseBox=Box.createHorizontalBox();
baseBox.add(boxV1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(boxV2);
add(baseBox);
}
public void actionPerformed(ActionEvent e)

{
try{
RandomAccessFile out= new RandomAccessFile(f,"rw");
if(f.exists())
{ long length=f.length();
out.seek(length);
}
out.writeUTF("姓名:"+name.getText());
out.writeUTF("email:"+email.getText());
out.writeUTF("电话:"+phone.getText());
out.close();
}
catch(IOException ee){ }
}
}


class CommFrame extends Frame implements ActionListener
{ File file=null;
MenuBar bar;
Menu fileMenu;
MenuItem 录入,显示;
TextArea show;
InputArea inputMessage;
CardLayout card=null;
Panel pCenter;
CommFrame()
{ file = new File("通讯录.txt");
录入=new MenuItem("录入");
显示=new MenuItem("显示");
bar=new MenuBar();
fileMenu=new Menu("菜单选项");
fileMenu.add(录入);
fileMenu.add(显示);
bar.add(fileMenu);
setMenuBar(bar);
录入.addActionListener(this);
显示.addActionListener(this);
inputMessage=new InputArea(file);
show=new TextArea(12,20);
card=new CardLayout();
pCenter.setLayout(card);
pCenter.add("录入",inputMessage);
pCenter.add("显示",show);
add(pCenter,BorderLayout.CENTER);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
});
setVisible(true);
setBounds(100,50,420,380);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==录入)
{ card.show(pCenter,"录入");

}
else if(e.getSource()==显示)
{ int number=1;
show.setText(null);
card.show(pCenter,"显示");
try{
RandomAccessFile in= new RandomAccessFile(file,"r");
String 姓名=null;
while((姓名=in.readUTF())!=null)
{ show.append("\n"+number+" "+姓名);
show.append(in.readUTF());
show.append(in.readUTF());
show.append("\n----------------------");
number++;

}
in.close();

}
catch(Exception ee){}


}
}
}

搜索更多相关的解决方案: 编译  

----------------解决方案--------------------------------------------------------
我这里编译正常,只是运行的时候会有空指针异常
----------------解决方案--------------------------------------------------------
把Panel pCenter=new Panel();加到程序第75行就可以了

你的pCenter没有初始化
----------------解决方案--------------------------------------------------------

现在在我这里面eclispe提示错误啊.呵呵,我再看看.原来jdk1.5行,现在1.6的却不行了.呵呵


----------------解决方案--------------------------------------------------------
什么错误/.

帖上来看看
----------------解决方案--------------------------------------------------------

错误就是这样的.残忍的.
----------------解决方案--------------------------------------------------------
错误1:

----------------解决方案--------------------------------------------------------
你可能是自己定久了一个叫File的类

要不就是你没有导入标准的JDK
----------------解决方案--------------------------------------------------------
我用JDK1.6也编译了,是可以通过的
----------------解决方案--------------------------------------------------------
是标准的jdk,我一直都是这个版本的.也正常的使用.
错误2:


----------------解决方案--------------------------------------------------------
  相关解决方案