.java 9 找不到符号_java找不到符号

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

因为太长百度知道不好使只能来贴吧了TAT

这个错误比较诡异,第一次javac会提示出错,可是再运行一次就没问题,当然,java运行后的结果也不是书上说的那样,把class文件删掉之前的错误才会再次出现。话不多说,上代码——

Example10_21.java

public class Example10_21

{

public static void main(String[] args)

{

new CommFrame();

}

}

InputArea.java

import java.io.*;

import javax.swing.*;

import java.awt.Color;

import java.awt.event.*;

public class InputArea extends JPanel implements ActionListener

{

File f=null;

RandomAccessFile out;

Box baseBox,boxV1,boxV2;

JTextField name,email,phone;

JButton button;

InputArea(File f)

{

setBackground(Color.cyan);

this.f=f;

name=new JTextField(12);

email=new JTextField(12);

phone=new JTextField(12);

button=new JButton("录入");

button.addActionListener(this);

boxV1=Box.createVerticalBox();

boxV1.add(new JLabel("输入姓名"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("输入email"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("输入电话"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("单击录入"));

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);

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.getTxet());

out.writeUTF("eamil:"+email.getText());

out.writeUTF("电话:"+phone.getText());

out.close();

}

catch(IOException ee){}

}

}

CommFrame.java

import java.io.*;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class CommFrame extends JFrame implements ActionListener

{

File file=null;

JMenuBar bar;

JMenu fileMenu;

JMenuItem inputMenuItem,showMenuItem;

JTextArea show; //显示信息

InputArea inputMessage; //录入信息

CardLayout card=null; //卡片式布局

JPanel pCenter;

CommFrame()

{

file=new File("通讯录.TXT");

inputMenuItem=new JMenuItem("录入");

showMenuItem=new JMenuItem("显示");

bar=new JMenuBar();

fileMenu=new JMenu("菜单选项");

fileMenu.add(inputMenuItem);

fileMenu.add(showMenuItem);

bar.add(fileMenu);

setJMenuBar(bar);

inputMenuItem.addActionListener(this);

showMenuItem.addActionListener(this);

inputMessage=new InputArea(file);

show=new JTextArea(12,20);

card=new CardLayout();

pCenter=new JPanel();

pCenter.setLayout(card);

pCenter.add("inputMenuItem",inputMessage);

pCenter.add("showMenuItem",show);

add(pCenter,BorderLayout.CENTER);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

setBounds(100,50,420,380);

validate();

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==inputMenuItem)

card.show(pCenter,"inputMenuItem");

else if(e.getSource()==showMenuItem);

{

int number=1;

show.setText(null);

card.show(pCenter,"showMenuItem");

try

{

RandomAccessFile in=new RandomAccessFile(file,"r");

String name=null;

while((name=in.readUTF())!=null)

{

show.append("\n"+number+" "+name);

show.append("\t "+in.readUTF()); //读取email

show.append("\t"+in.readUTF()); //读取phone

show.append("\n---------------------------------");

number++;

}

in.close();

}

catch (Exception ee){}

}

}

}

三个文件做出来的(不知道我这个说法准确不准确),挺难的,我检查了好几遍眼睛都花了也没发现哪里不对,老师也没抽不出时间。还是我太无知了,只能在这里请求各位大佬来帮帮我了(跪谢)!

(ps:第一章图片是我做出来的效果,第二张图片是书上说的应该有的样子)

6f02ceb7142f623dfa96a2a242dfc0b4.png

02c5888aa2fc9122012102f436915bb2.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值