java内部类的问题
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() 这样行吗?