java内部类的问题

s74110s s74110s 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package untitled3;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame {
public Frame1() {
setTitle("ActionTest");
setSize(400,300);
MulticastPanel x=new MulticastPanel();
getContentPane().add(x);
}
public static void main(String[] args) {
Frame1 frame4 = new Frame1();
frame4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame4.setVisible(true);
}
}
class MulticastPanel extends JPanel{
public MulticastPanel(){
JButton newButton=new JButton("new");
this.add(newButton);
final JButton closeAllButton=new JButton("Close all");
this.add(closeAllButton);
ActionListener newListener=new f(closeAllButton);
//cannot find symbol:classf.location:class untitled3.MulticastPanel ?
class f implements ActionListener{
private final JButton b;
public f(final JButton s){
this.b=s;
}
public void actionPerformed(ActionEvent event){
BlankFrame frame=new BlankFrame(b);
//cannot findsymbol:constructor BlankFrame(javax.swing).JButton).location:class untitled3.BlandFrame?
//internal error:cannot instantiate untitled3.BlankFrame.<init>at untitled3.BlankFrame to()?
frame.setVisible(true);
}
}

newButton.addActionListener(newListener);
}
}
class BlankFrame extends JFrame {
private ActionListener closeListener;
public static final int SPACING=40;
private static int counter=0;
public BlankFrame(final Button closeButton){
counter++;
setTitle("Frame"+counter);
setSize(400,300);
setLocation(SPACING*counter,SPACING*counter);
closeListener=new ActionListener(){
public void actionPerformed(ActionEvent event){
closeButton.removeActionListener(closeListener);
dispose();
}
};
closeButton.addActionListener(closeListener);
}
}
在外部内中怎么构造内部类的对象?
为什么内部类中为什么不能构造同一个文件中的其他的类的对象
如果
a 继承 b
b 继承 c
那么 c z=new a() 这样行吗?
...全文
评论 7
收藏 已收藏
分享
返回顶部
s74110s
Java SE 62,620 成员 307,251 内容