| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 452 人关注过本帖
标题:这里到底出了什么问题?
只看楼主 加入收藏
死了都要编
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2007-10-11
收藏
 问题点数:0 回复次数:5 
这里到底出了什么问题?

import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class frm123 extends Frame
{
public static void main(String args[])
{
frm123frm frm=new frm123frm();
}
}

public class frm123frm extends Frame implements ActionListener
{

FileDialog op,sv;
Button btn1,btn2,btn3;
TextArea tarea;
frm123frm()
{

super("我的专用记事本");
setLayout(null);
setBackground(Color.black);
setSize(600,300);
setVisible(true);
btn1=new Button("打开");
btn2=new Button("保存");
btn3=new Button("关闭");
tarea=new TextArea("");
add(btn1);add(btn2);add(btn3);add(tarea);
tarea.setBounds(30,50,460,220);
btn1.setBounds(520,60,50,30);
btn2.setBounds(520,120,50,30);
btn3.setBounds(520,180,50,30);
op=new FileDialog(this,"打开",FileDialog.LOAD);
sv=new FileDialog(this,"保存",FileDialog.SAVE);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);}});
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
}

}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
String str;
op.setVisible(true);
try
{
File f1=new File(op.getDirectory(),op.getFile());
FileReader fr=new FileReader(f1);
BufferedReader br = new BufferedReader(fr);
tarea.setText("");
while((str=br.readLine())!=nill)tarea.append(str+'\n');
fr.close();
}
catch(Exception e1)
{
}
}
if(e.getSource()==btn2)
{
sv.setVisible(true);
try
{
File f1=new File(sv.getDirectory(),sv.getFile());
FileWriter fw= new FileWriter(f1);
BufferedWriter bw = new BufferedWriter(fw);
String gt=tarea.getText();
bw.write(gt,0,gt.length());
bw.flush();
fw.close();
}
catch(Exception e2)
{
}
}
if(e.getSource()==3)
{
System.exit(0);
}
}

搜索更多相关主题的帖子: 记事本 public import super 
2007-10-17 15:28
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
收藏
得分:0 
public class只能有一个,但是你有2个,应该去掉一个public
while((str=br.readLine())!=nill)tarea.append(str+'\n');//改成null
if(e.getSource()==3)//一个是Object,一个是int,这样无法比较

I'm here, as always...
2007-10-17 15:39
死了都要编
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2007-10-11
收藏
得分:0 
那问题是粗心弄成的.
我改了,但还是不行

import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class frm123 extends Frame
{
public static void main(String args[])
{
frm123frm frm=new frm123frm();
}
}
class frm123frm extends Frame implements ActionListener
{

FileDialog op,sv;
Button btn1,btn2,btn3;
TextArea tarea;
frm123frm()
{

super("我的专用记事本");
setLayout(null);
setBackground(Color.black);
setSize(600,300);
setVisible(true);
btn1=new Button("打开");
btn2=new Button("保存");
btn3=new Button("关闭");
tarea=new TextArea("");
add(btn1);add(btn2);add(btn3);add(tarea);
tarea.setBounds(30,50,460,220);
btn1.setBounds(520,60,50,30);
btn2.setBounds(520,120,50,30);
btn3.setBounds(520,180,50,30);
op=new FileDialog(this,"打开",FileDialog.LOAD);
sv=new FileDialog(this,"保存",FileDialog.SAVE);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);}});
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
}

}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
String str;
op.setVisible(true);
try
{
File f1=new File(op.getDirectory(),op.getFile());
FileReader fr=new FileReader(f1);
BufferedReader br = new BufferedReader(fr);
tarea.setText("");
while((str=br.readLine())!=null)tarea.append(str+'\n');
fr.close();
}
catch(Exception e1)
{
}
}
if(e.getSource()==btn2)
{
sv.setVisible(true);
try
{
File f1=new File(sv.getDirectory(),sv.getFile());
FileWriter fw= new FileWriter(f1);
BufferedWriter bw = new BufferedWriter(fw);
String gt=tarea.getText();
bw.write(gt,0,gt.length());
bw.flush();
fw.close();
}
catch(Exception e2)
{
}
}
if(e.getSource()==btn3)
{
System.exit(0);
}
}
2007-10-17 15:54
hwoarangzk
Rank: 4
来 自:冰封王座
等 级:贵宾
威 望:12
帖 子:1894
专家分:0
注 册:2007-7-17
收藏
得分:0 
还有你的括号不配对,最后一行加一个},public void actionPerformed(ActionEvent e)前面删一个}

I'm here, as always...
2007-10-17 16:06
hjlwlyhjl
Rank: 1
等 级:新手上路
帖 子:71
专家分:0
注 册:2006-12-6
收藏
得分:0 

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

public class Frm123
{
public static void main(String args[])
{
Frm123frm frm=new Frm123frm();
}
}


class Frm123frm extends Frame implements ActionListener
{

private FileDialog op,sv;
private Button btn1,btn2,btn3;
private TextArea tarea;
public Frm123frm()
{

super("我的专用记事本");
setLayout(null);
setBackground(Color.black);
setSize(600,300);
setVisible(true);
btn1=new Button("打开");
btn2=new Button("保存");
btn3=new Button("关闭");
tarea=new TextArea("");
add(btn1);add(btn2);add(btn3);add(tarea);
tarea.setBounds(30,50,460,220);
btn1.setBounds(520,60,50,30);
btn2.setBounds(520,120,50,30);
btn3.setBounds(520,180,50,30);
op=new FileDialog(this,"打开",FileDialog.LOAD);
sv=new FileDialog(this,"保存",FileDialog.SAVE);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);}});
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn1)
{
String str;
op.setVisible(true);
try
{
File f1=new File(op.getDirectory(),op.getFile());
FileReader fr=new FileReader(f1);
BufferedReader br = new BufferedReader(fr);
tarea.setText("");
while((str=br.readLine())!=null)tarea.append(str+'\n');
fr.close();
}
catch(Exception e1)
{
}
}
if(e.getSource()==btn2)
{
sv.setVisible(true);
try
{
File f1=new File(sv.getDirectory(),sv.getFile());
FileWriter fw= new FileWriter(f1);
BufferedWriter bw = new BufferedWriter(fw);
String gt=tarea.getText();
bw.write(gt,0,gt.length());
bw.flush();
fw.close();
}
catch(Exception e2)
{
}
}
if(e.getSource()==btn3)
{
System.exit(0);
}
}
}
这样就行了,编程要养成良好的习惯,类名第一个字母大写,类的成员变量一般声明为private类型的


2007-10-17 16:56
hexiaoyuhit
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2007-7-16
收藏
得分:0 
菜鸟 还看不懂 但知道的习惯地重要性
2007-10-18 17:37
快速回复:这里到底出了什么问题?
数据加载中...
 
   



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

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