
JAVA编写文本编辑器遇到的问题求解 20
fileMenu.add(newItem);newItem.addActionListener(newActionListener(){publicvoidactionP...
fileMenu.add(newItem);
newItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
textArea.setText("");
setTitle("文本编辑 新");
}
});
以上这样写是可以实现新建功能的,但是改了种写法就会出现错误
newItem.addActionListener(this)
public void actionPerformed(ActionEvent e) //打开文件
{
if(e.getSource()==newItem) //实现“新建”功能
{
textArea.setText("");
this.setTitle("文本编辑 新");
}
} 展开
newItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
textArea.setText("");
setTitle("文本编辑 新");
}
});
以上这样写是可以实现新建功能的,但是改了种写法就会出现错误
newItem.addActionListener(this)
public void actionPerformed(ActionEvent e) //打开文件
{
if(e.getSource()==newItem) //实现“新建”功能
{
textArea.setText("");
this.setTitle("文本编辑 新");
}
} 展开
1个回答
2014-06-15 · 知道合伙人软件行家
关注

展开全部
下面的两个this分别指的是神马?
newItem.addActionListener(this)中的this,需要的是一个实现了ActionListener的当前对象
this.setTitle中的this,需要的是一个JFrame(Frame)或者JDialog(Dialog)...窗体当前对象
楼主可否再放些代码出来?
newItem.addActionListener(this)中的this,需要的是一个实现了ActionListener的当前对象
this.setTitle中的this,需要的是一个JFrame(Frame)或者JDialog(Dialog)...窗体当前对象
楼主可否再放些代码出来?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询